1
0
mirror of https://github.com/golang/go synced 2024-11-06 08:36:14 -07:00

[dev.link] cmd/link: simplify named symbol resolution

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>
This commit is contained in:
Cherry Zhang 2020-01-30 17:27:27 -05:00
parent 83ba044be6
commit 29d95be875
2 changed files with 5 additions and 38 deletions

View 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.

View 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()...)