diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 912d283221..8b26d4a6b2 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -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. diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 02a15dc155..280978dbe4 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -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()...)