]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: convert typelink pass to new style
authorCherry Zhang <cherryyz@google.com>
Wed, 8 Apr 2020 23:46:00 +0000 (19:46 -0400)
committerCherry Zhang <cherryyz@google.com>
Thu, 9 Apr 2020 19:02:47 +0000 (19:02 +0000)
Change-Id: If861409a5cc4e398496199a89498a141f106f44f
Reviewed-on: https://go-review.googlesource.com/c/go/+/227762
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/decodesym2.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/ld/typelink.go
src/cmd/link/internal/loader/loader.go

index 318ce36594163951f9fead742fb480a7b8be7a45..8b19afffa340d887b57d255fff76a2fa9d67c087 100644 (file)
@@ -118,3 +118,14 @@ func decodetypeStructFieldOffsAnon2(ldr *loader.Loader, arch *sys.Arch, symIdx l
        data := ldr.Data(symIdx)
        return int64(decodeInuxi(arch, data[off+2*arch.PtrSize:], arch.PtrSize))
 }
+
+// decodetypeStr2 returns the contents of an rtype's str field (a nameOff).
+func decodetypeStr2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) string {
+       relocs := ldr.Relocs(symIdx)
+       str := decodetypeName2(ldr, symIdx, &relocs, 4*arch.PtrSize+8)
+       data := ldr.Data(symIdx)
+       if data[2*arch.PtrSize+4]&tflagExtraStar != 0 {
+               return str[1:]
+       }
+       return str
+}
index b91a195694a659e97ed9cfd774a47e3547ec3590..7f11731ef4dd21f636bdd18d749105d7525bed47 100644 (file)
@@ -290,14 +290,14 @@ func Main(arch *sys.Arch, theArch Arch) {
 
        bench.Start("textaddress")
        ctxt.textaddress()
+       bench.Start("typelink")
+       ctxt.typelink()
        bench.Start("loadlibfull")
        ctxt.loadlibfull() // XXX do it here for now
        bench.Start("pclntab")
        ctxt.pclntab()
        bench.Start("findfunctab")
        ctxt.findfunctab()
-       bench.Start("typelink")
-       ctxt.typelink()
        bench.Start("symtab")
        ctxt.symtab()
        bench.Start("buildinfo")
index 6b5ab080f3e8e17930024ccdcb95958dc707d9b4..22b679bf543c1a87ff5ea4f5b04826d7ed3d7c2b 100644 (file)
@@ -6,6 +6,7 @@ package ld
 
 import (
        "cmd/internal/objabi"
+       "cmd/link/internal/loader"
        "cmd/link/internal/sym"
        "sort"
 )
@@ -14,7 +15,7 @@ type byTypeStr []typelinkSortKey
 
 type typelinkSortKey struct {
        TypeStr string
-       Type    *sym.Symbol
+       Type    loader.Sym
 }
 
 func (s byTypeStr) Less(i, j int) bool { return s[i].TypeStr < s[j].TypeStr }
@@ -25,25 +26,27 @@ func (s byTypeStr) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
 // Types that should be added to the typelinks table are marked with the
 // MakeTypelink attribute by the compiler.
 func (ctxt *Link) typelink() {
+       ldr := ctxt.loader
        typelinks := byTypeStr{}
-       for _, s := range ctxt.Syms.Allsym {
-               if s.Attr.Reachable() && s.Attr.MakeTypelink() {
-                       typelinks = append(typelinks, typelinkSortKey{decodetypeStr(ctxt.Arch, s), s})
+       for s := loader.Sym(1); s < loader.Sym(ldr.NSym()); s++ {
+               if ldr.AttrReachable(s) && ldr.IsTypelink(s) {
+                       typelinks = append(typelinks, typelinkSortKey{decodetypeStr2(ldr, ctxt.Arch, s), s})
                }
        }
        sort.Sort(typelinks)
 
-       tl := ctxt.Syms.Lookup("runtime.typelink", 0)
-       tl.Type = sym.STYPELINK
-       tl.Attr |= sym.AttrReachable | sym.AttrLocal
-       tl.Size = int64(4 * len(typelinks))
-       tl.P = make([]byte, tl.Size)
-       tl.R = make([]sym.Reloc, len(typelinks))
+       tl := ldr.CreateSymForUpdate("runtime.typelink", 0)
+       tl.SetType(sym.STYPELINK)
+       ldr.SetAttrReachable(tl.Sym(), true)
+       ldr.SetAttrLocal(tl.Sym(), true)
+       tl.SetSize(int64(4 * len(typelinks)))
+       tl.Grow(tl.Size())
+       relocs := tl.AddRelocs(len(typelinks))
        for i, s := range typelinks {
-               r := &tl.R[i]
-               r.Sym = s.Type
-               r.Off = int32(i * 4)
-               r.Siz = 4
-               r.Type = objabi.R_ADDROFF
+               r := relocs.At2(i)
+               r.SetSym(s.Type)
+               r.SetOff(int32(i * 4))
+               r.SetSiz(4)
+               r.SetType(objabi.R_ADDROFF)
        }
 }
index 3437b42b6521f0d0bb9fc13a9b92a3c2cf0ae5d8..cd5971c2e1a774b06bd3d6022c43de2e3cba74a9 100644 (file)
@@ -659,7 +659,9 @@ func (l *Loader) SymType(i Sym) sym.SymKind {
 // Returns the attributes of the i-th symbol.
 func (l *Loader) SymAttr(i Sym) uint8 {
        if l.IsExternal(i) {
-               // TODO: do something? External symbols have different representation of attributes. For now, ReflectMethod is the only thing matters and it cannot be set by external symbol.
+               // TODO: do something? External symbols have different representation of attributes.
+               // For now, ReflectMethod, NoSplit, GoType, and Typelink are used and they cannot be
+               // set by external symbol.
                return 0
        }
        r, li := l.toLocal(i)
@@ -982,6 +984,11 @@ func (l *Loader) IsGoType(i Sym) bool {
        return l.SymAttr(i)&goobj2.SymFlagGoType != 0
 }
 
+// Returns whether this symbol should be included in typelink.
+func (l *Loader) IsTypelink(i Sym) bool {
+       return l.SymAttr(i)&goobj2.SymFlagTypelink != 0
+}
+
 // Returns whether this is a "go.itablink.*" symbol.
 func (l *Loader) IsItabLink(i Sym) bool {
        if _, ok := l.itablink[i]; ok {