diff options
author | Than McIntosh <thanm@google.com> | 2020-04-21 18:37:43 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2020-04-24 14:09:38 +0000 |
commit | 941de9760bcf35ad1ef4eee23d2851d3f2fa087b (patch) | |
tree | 128dbec7db74ed82eb8732bff494e44b502096de /src/cmd/link/internal/loader/loader.go | |
parent | 3d1007d28e92316b08974dc65cde44a6aa31bf21 (diff) | |
download | go-941de9760bcf35ad1ef4eee23d2851d3f2fa087b.tar.gz go-941de9760bcf35ad1ef4eee23d2851d3f2fa087b.zip |
[dev.link] cmd/link: begin converting dodata() to loader APIs
This patch begins the work of converting the linker's dodata phase to
work with loader APIs. Passes all.bash on linux/amd64, but hasn't been
tested on anything else (more arch-specific code needs to be written).
Use of the new dodata() phase is currently gated by a temporary
command line flag ("-newdodata"), and there is code in the linker's
main routine to insure that we only use the new version for the right
GOOS/GOARCH (currently restricted to ELF + AMD64).
Change-Id: Ied3966677d2a450bc3e0990e0f519b3fceaab806
Reviewed-on: https://go-review.googlesource.com/c/go/+/229706
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
-rw-r--r-- | src/cmd/link/internal/loader/loader.go | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 458c87a6b6..114bd43477 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -1268,6 +1268,17 @@ func (l *Loader) SetSymDynid(i Sym, val int32) { } } +// DynIdSyms returns the set of symbols for which dynID is set to an +// interesting (non-default) value. This is expected to be a fairly +// small set. +func (l *Loader) DynidSyms() []Sym { + sl := make([]Sym, 0, len(l.dynid)) + for s := range l.dynid { + sl = append(sl, s) + } + return sl +} + // SymGoType returns the 'Gotype' property for a given symbol (set by // the Go compiler for variable symbols). This version relies on // reading aux symbols for the target sym -- it could be that a faster @@ -2255,6 +2266,30 @@ func (l *Loader) addNewSym(i Sym, name string, ver int, unit *sym.CompilationUni return s } +// TopLevelSym tests a symbol (by name and kind) to determine whether +// the symbol first class sym (participating in the link) or is an +// anonymous aux or sub-symbol containing some sub-part or payload of +// another symbol. +func (l *Loader) TopLevelSym(s Sym) bool { + return topLevelSym(l.RawSymName(s), l.SymType(s)) +} + +// topLevelSym tests a symbol name and kind to determine whether +// the symbol first class sym (participating in the link) or is an +// anonymous aux or sub-symbol containing some sub-part or payload of +// another symbol. +func topLevelSym(sname string, skind sym.SymKind) bool { + if sname != "" { + return true + } + switch skind { + case sym.SDWARFINFO, sym.SDWARFRANGE, sym.SDWARFLOC, sym.SDWARFLINES, sym.SGOFUNC: + return true + default: + return false + } +} + // loadObjSyms creates sym.Symbol objects for the live Syms in the // object corresponding to object reader "r". Return value is the // number of sym.Reloc entries required for all the new symbols. @@ -2268,16 +2303,11 @@ func loadObjSyms(l *Loader, syms *sym.Symbols, r *oReader) int { osym := r.Sym(i) name := strings.Replace(osym.Name(r.Reader), "\"\".", r.pkgprefix, -1) t := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())] - // NB: for the test below, we can skip most anonymous symbols - // since they will never be turned into sym.Symbols (eg: - // funcdata). DWARF symbols are an exception however -- we - // want to include all reachable but nameless DWARF symbols. - if name == "" { - switch t { - case sym.SDWARFINFO, sym.SDWARFRANGE, sym.SDWARFLOC, sym.SDWARFLINES: - default: - continue - } + + // Skip non-dwarf anonymous symbols (e.g. funcdata), + // since they will never be turned into sym.Symbols. + if !topLevelSym(name, t) { + continue } ver := abiToVer(osym.ABI(), r.version) if t == sym.SXREF { |