[dev.link] cmd/link: hoist dwarfGenerateDebugSyms out of dodata()

Hoist dwarfGenerateDebugSyms call up out of dodata to before
loadlibfull. This required a couple of small tweaks to the
loader and to loadlibfull.

Change-Id: I48ffb450d2e48b9e55775b73a6debcd27dbb7b9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/228221
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-04-13 15:38:03 -04:00
parent 3216d14f78
commit eed3ef581b
5 changed files with 21 additions and 22 deletions

View file

@ -1923,8 +1923,6 @@ func (ctxt *Link) dodata() {
ctxt.datap = append(ctxt.datap, data[symn]...) ctxt.datap = append(ctxt.datap, data[symn]...)
} }
dwarfGenerateDebugSyms(ctxt)
var i int var i int
for ; i < len(dwarfp); i++ { for ; i < len(dwarfp); i++ {
s := dwarfp[i] s := dwarfp[i]

View file

@ -1970,17 +1970,6 @@ func dwarfGenerateDebugSyms(ctxt *Link) {
} }
func (d *dwctxt2) dwarfGenerateDebugSyms() { func (d *dwctxt2) dwarfGenerateDebugSyms() {
// Hack: because the "wavefront" hasn't been pushed all the way
// up to dodata(), there will have been changes made to the sym.Symbol's
// that are not yet reflected in the loader. Call a temporary
// loader routine that copies any changes back.
// WARNING: changing a symbol's content will usually require
// calling the loader cloneToExternal method, meaning that there
// can be an increase in memory, so this is likely to mess up any
// benchmarking runs.
d.ldr.PropagateSymbolChangesBackToLoader()
abbrev := d.writeabbrev() abbrev := d.writeabbrev()
syms := []loader.Sym{abbrev} syms := []loader.Sym{abbrev}
@ -2036,8 +2025,6 @@ func (d *dwctxt2) dwarfGenerateDebugSyms() {
} }
} }
dwarfp2 = syms dwarfp2 = syms
anonVerReplacement := d.linkctxt.Syms.IncVersion()
dwarfp = d.ldr.PropagateLoaderChangesToSymbols(dwarfp2, anonVerReplacement)
} }
func (d *dwctxt2) collectlocs(syms []loader.Sym, units []*sym.CompilationUnit) []loader.Sym { func (d *dwctxt2) collectlocs(syms []loader.Sym, units []*sym.CompilationUnit) []loader.Sym {

View file

@ -2801,6 +2801,16 @@ func (ctxt *Link) loadlibfull() {
// Convert special symbols created by pcln. // Convert special symbols created by pcln.
pclntabFirstFunc = ctxt.loader.Syms[pclntabFirstFunc2] pclntabFirstFunc = ctxt.loader.Syms[pclntabFirstFunc2]
pclntabLastFunc = ctxt.loader.Syms[pclntabLastFunc2] pclntabLastFunc = ctxt.loader.Syms[pclntabLastFunc2]
// Populate dwarfp from dwarfp2. If we see a symbol index on dwarfp2
// whose loader.Syms entry is nil, something went wrong.
for _, symIdx := range dwarfp2 {
s := ctxt.loader.Syms[symIdx]
if s == nil {
panic(fmt.Sprintf("nil sym for dwarfp2 element %d", symIdx))
}
dwarfp = append(dwarfp, s)
}
} }
func (ctxt *Link) dumpsyms() { func (ctxt *Link) dumpsyms() {

View file

@ -298,6 +298,8 @@ func Main(arch *sys.Arch, theArch Arch) {
container := ctxt.pclntab() container := ctxt.pclntab()
bench.Start("findfunctab") bench.Start("findfunctab")
ctxt.findfunctab(container) ctxt.findfunctab(container)
bench.Start("dwarfGenerateDebugSyms")
dwarfGenerateDebugSyms(ctxt)
bench.Start("loadlibfull") bench.Start("loadlibfull")
ctxt.loadlibfull() // XXX do it here for now ctxt.loadlibfull() // XXX do it here for now
bench.Start("symtab") bench.Start("symtab")

View file

@ -2204,13 +2204,15 @@ func loadObjSyms(l *Loader, syms *sym.Symbols, r *oReader) int {
name := strings.Replace(osym.Name(r.Reader), "\"\".", r.pkgprefix, -1) name := strings.Replace(osym.Name(r.Reader), "\"\".", r.pkgprefix, -1)
t := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())] t := sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type())]
// NB: for the test below, we can skip most anonymous symbols // NB: for the test below, we can skip most anonymous symbols
// since they will never be turned into sym.Symbols (ex: // since they will never be turned into sym.Symbols (eg:
// funcdata), however DWARF subprogram DIE symbols (which are // funcdata). DWARF symbols are an exception however -- we
// nameless) will eventually need to be turned into // want to include all reachable but nameless DWARF symbols.
// sym.Symbols (with relocations), so the simplest thing to do if name == "" {
// is include them as part of this loop. switch t {
if name == "" && t != sym.SDWARFINFO { case sym.SDWARFINFO, sym.SDWARFRANGE, sym.SDWARFLOC, sym.SDWARFLINES:
continue default:
continue
}
} }
ver := abiToVer(osym.ABI(), r.version) ver := abiToVer(osym.ABI(), r.version)
if t == sym.SXREF { if t == sym.SXREF {