]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: simplify named symbol resolution
authorCherry Zhang <cherryyz@google.com>
Thu, 30 Jan 2020 22:27:27 +0000 (17:27 -0500)
committerCherry Zhang <cherryyz@google.com>
Wed, 5 Feb 2020 20:50:45 +0000 (20:50 +0000)
Now that we have local-global index mappings, just use that for
symbol reference resolution.

Change-Id: I6bc5405853fe040ff21b624ccd8da7965d66ec8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/217065
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/loader/loader.go

index 912d283221cb63068de5522fa2abf62b0bcd01cd..8b26d4a6b20d085be076b7fdcb052fe650c78712 100644 (file)
@@ -455,6 +455,9 @@ func (ctxt *Link) loadlib() {
                }
        }
 
+       // Add references of externally defined symbols.
+       ctxt.loader.LoadRefs(ctxt.Arch, ctxt.Syms)
+
        // Process cgo directives (has to be done before host object loading).
        ctxt.loadcgodirectives(ctxt.loaderSupport())
 
@@ -462,9 +465,6 @@ func (ctxt *Link) loadlib() {
        hostobjs(ctxt)
        hostlinksetup(ctxt)
 
-       // Add references of externally defined symbols.
-       ctxt.loader.LoadRefs(ctxt.Arch, ctxt.Syms)
-
        if ctxt.LinkMode == LinkInternal && len(hostobj) != 0 {
                // If we have any undefined symbols in external
                // objects, try to read them from the libgcc file.
index 02a15dc1557c388a79c6faf7a25696250c1fcffe..280978dbe4d4f14045d7610114710a4bdcf60c3b 100644 (file)
@@ -61,7 +61,6 @@ type oReader struct {
        version   int    // version of static symbol
        flags     uint32 // read from object file
        pkgprefix string
-       rcache    []Sym // cache mapping local PkgNone symbol to resolved Sym
        syms      []Sym // Sym's global index, indexed by local index
 }
 
@@ -519,26 +518,6 @@ func (l *Loader) toLocal(i Sym) (*oReader, int) {
        return l.objSyms[i].r, int(l.objSyms[i].s)
 }
 
-// rcacheGet checks for a valid entry for 's' in the readers cache,
-// where 's' is a local PkgIdxNone ref or def, or zero if
-// the cache is empty or doesn't contain a value for 's'.
-func (or *oReader) rcacheGet(symIdx uint32) Sym {
-       if len(or.rcache) > 0 {
-               return or.rcache[symIdx]
-       }
-       return 0
-}
-
-// rcacheSet installs a new entry in the oReader's PkgNone
-// resolver cache for the specified PkgIdxNone ref or def,
-// allocating a new cache if needed.
-func (or *oReader) rcacheSet(symIdx uint32, gsym Sym) {
-       if len(or.rcache) == 0 {
-               or.rcache = make([]Sym, or.NNonpkgdef()+or.NNonpkgref())
-       }
-       or.rcache[symIdx] = gsym
-}
-
 // Resolve a local symbol reference. Return global index.
 func (l *Loader) resolve(r *oReader, s goobj2.SymRef) Sym {
        var rr *oReader
@@ -550,19 +529,7 @@ func (l *Loader) resolve(r *oReader, s goobj2.SymRef) Sym {
                return 0
        case goobj2.PkgIdxNone:
                i := int(s.SymIdx) + r.NSym()
-               // Check for cached version first
-               if cached := r.rcacheGet(s.SymIdx); cached != 0 {
-                       return cached
-               }
-               // Resolve by name
-               osym := goobj2.Sym{}
-               osym.Read(r.Reader, r.SymOff(i))
-               name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1)
-               v := abiToVer(osym.ABI, r.version)
-               gsym := l.Lookup(name, v)
-               // Add to cache, then return.
-               r.rcacheSet(s.SymIdx, gsym)
-               return gsym
+               return r.syms[i]
        case goobj2.PkgIdxBuiltin:
                return l.builtinSyms[s.SymIdx]
        case goobj2.PkgIdxSelf:
@@ -1596,7 +1563,7 @@ func (l *Loader) Preload(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *
        pkgprefix := objabi.PathToPrefix(lib.Pkg) + "."
        ndef := r.NSym()
        nnonpkgdef := r.NNonpkgdef()
-       or := &oReader{r, unit, localSymVersion, r.Flags(), pkgprefix, nil, make([]Sym, ndef + nnonpkgdef + r.NNonpkgref())}
+       or := &oReader{r, unit, localSymVersion, r.Flags(), pkgprefix, make([]Sym, ndef + nnonpkgdef + r.NNonpkgref())}
 
        // Autolib
        lib.ImportStrings = append(lib.ImportStrings, r.Autolib()...)