From: Than McIntosh Date: Mon, 9 Mar 2020 15:42:03 +0000 (-0400) Subject: [dev.link] cmd/link: demote dwarf {range,loc} sub-symbols to aux X-Git-Tag: go1.15beta1~679^2~76 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8634642f9aea9c432aa4cf392eba31de96f75726;p=gostls13.git [dev.link] cmd/link: demote dwarf {range,loc} sub-symbols to aux When the compiler emits DWARF for a function F, in addition to the text symbol for F, it emits a set of sibling or child symbols that carry the various DWARF bits for F (for example, go.info.F, go.ranges.F, go.loc.F, and so on). Prior to the linker modernization work, name lookup was the way you made your way from a function symbol to one of its child DWARF symbols. We now have a new mechanism (aux symbols), so there is really no need for the DWARF sub-symbols to be named or to be dupok. This patch converts DWARF "range" and "loc" sub-symbols to be pure aux syms: unnamed, and connected to their parent text symbol only via aux data. This should presumably have performance benefits in that we add fewer symbols to the linker lookup tables. Other related DWARF sub-symbols (ex: go.line.*) will be handled in a subsequent patch. Change-Id: Iae3ec2d42452962d4afc1df4a1bd89ccdeadc6e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/222673 Reviewed-by: Cherry Zhang Reviewed-by: Jeremy Faller Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go index 0fdbe1ae62..3ba0623c8c 100644 --- a/src/cmd/internal/dwarf/dwarf.go +++ b/src/cmd/internal/dwarf/dwarf.go @@ -21,12 +21,6 @@ import ( // InfoPrefix is the prefix for all the symbols containing DWARF info entries. const InfoPrefix = "go.info." -// RangePrefix is the prefix for all the symbols containing DWARF location lists. -const LocPrefix = "go.loc." - -// RangePrefix is the prefix for all the symbols containing DWARF range lists. -const RangePrefix = "go.range." - // DebugLinesPrefix is the prefix for all the symbols containing DWARF debug_line information from the compiler. const DebugLinesPrefix = "go.debuglines." diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index bca42c212d..4669e415cc 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -205,9 +205,13 @@ func (ctxt *Link) dwarfSym(s *LSym) (dwarfInfoSym, dwarfLocSym, dwarfRangesSym, if s.Func.dwarfInfoSym == nil { s.Func.dwarfInfoSym = ctxt.LookupDerived(s, dwarf.InfoPrefix+s.Name) if ctxt.Flag_locationlists { - s.Func.dwarfLocSym = ctxt.LookupDerived(s, dwarf.LocPrefix+s.Name) + s.Func.dwarfLocSym = &LSym{ + Type: objabi.SDWARFLOC, + } + } + s.Func.dwarfRangesSym = &LSym{ + Type: objabi.SDWARFRANGE, } - s.Func.dwarfRangesSym = ctxt.LookupDerived(s, dwarf.RangePrefix+s.Name) if s.WasInlined() { s.Func.dwarfAbsFnSym = ctxt.DwFixups.AbsFuncDwarfSym(s) } diff --git a/src/cmd/internal/obj/objfile2.go b/src/cmd/internal/obj/objfile2.go index 839167bc1a..dc492733ac 100644 --- a/src/cmd/internal/obj/objfile2.go +++ b/src/cmd/internal/obj/objfile2.go @@ -307,14 +307,14 @@ func (w *writer) Aux(s *LSym) { } o.Write(w.Writer) } - if s.Func.dwarfLocSym != nil { + if s.Func.dwarfLocSym != nil && s.Func.dwarfLocSym.Size != 0 { o := goobj2.Aux{ Type: goobj2.AuxDwarfLoc, Sym: makeSymRef(s.Func.dwarfLocSym), } o.Write(w.Writer) } - if s.Func.dwarfRangesSym != nil { + if s.Func.dwarfRangesSym != nil && s.Func.dwarfRangesSym.Size != 0 { o := goobj2.Aux{ Type: goobj2.AuxDwarfRanges, Sym: makeSymRef(s.Func.dwarfRangesSym), @@ -343,10 +343,10 @@ func nAuxSym(s *LSym) int { if s.Func.dwarfInfoSym != nil { n++ } - if s.Func.dwarfLocSym != nil { + if s.Func.dwarfLocSym != nil && s.Func.dwarfLocSym.Size != 0 { n++ } - if s.Func.dwarfRangesSym != nil { + if s.Func.dwarfRangesSym != nil && s.Func.dwarfRangesSym.Size != 0 { n++ } if s.Func.dwarfDebugLinesSym != nil { @@ -419,6 +419,18 @@ func genFuncInfoSyms(ctxt *Link) { infosyms = append(infosyms, isym) s.Func.FuncInfoSym = isym b.Reset() + + dwsyms := []*LSym{s.Func.dwarfRangesSym, s.Func.dwarfLocSym} + for _, s := range dwsyms { + if s == nil || s.Size == 0 { + continue + } + s.PkgIdx = goobj2.PkgIdxSelf + s.SymIdx = symidx + s.Set(AttrIndexed, true) + symidx++ + infosyms = append(infosyms, s) + } } ctxt.defs = append(ctxt.defs, infosyms...) } diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go index 4d02042956..fdb5490255 100644 --- a/src/cmd/internal/obj/plist.go +++ b/src/cmd/internal/obj/plist.go @@ -139,17 +139,10 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) { ctxt.Text = append(ctxt.Text, s) // Set up DWARF entries for s. - info, loc, ranges, _, lines := ctxt.dwarfSym(s) + info, _, _, _, lines := ctxt.dwarfSym(s) info.Type = objabi.SDWARFINFO info.Set(AttrDuplicateOK, s.DuplicateOK()) - if loc != nil { - loc.Type = objabi.SDWARFLOC - loc.Set(AttrDuplicateOK, s.DuplicateOK()) - ctxt.Data = append(ctxt.Data, loc) - } - ranges.Type = objabi.SDWARFRANGE - ranges.Set(AttrDuplicateOK, s.DuplicateOK()) - ctxt.Data = append(ctxt.Data, info, ranges) + ctxt.Data = append(ctxt.Data, info) lines.Type = objabi.SDWARFLINES lines.Set(AttrDuplicateOK, s.DuplicateOK()) ctxt.Data = append(ctxt.Data, lines) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 8376ea82db..dcc957655a 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1934,8 +1934,11 @@ func dwarfGenerateDebugInfo(ctxt *Link) { r := &relocs[ri] if r.Type == objabi.R_DWARFSECREF { rsym := r.Sym - // NB: there should be a better way to do this that doesn't involve materializing the symbol name and doing string prefix+suffix checks. rsn := d.ldr.SymName(rsym) + if len(rsn) == 0 { + continue + } + // NB: there should be a better way to do this that doesn't involve materializing the symbol name and doing string prefix+suffix checks. if strings.HasPrefix(rsn, dwarf.InfoPrefix) && strings.HasSuffix(rsn, dwarf.AbstractFuncSuffix) && !d.ldr.AttrOnList(rsym) { // abstract function d.ldr.SetAttrOnList(rsym, true) @@ -2129,8 +2132,7 @@ func (d *dwctxt2) collectlocs(syms []loader.Sym, units []*sym.CompilationUnit) [ if reloc.Type != objabi.R_DWARFSECREF { continue } - sn := d.ldr.SymName(reloc.Sym) - if strings.HasPrefix(sn, dwarf.LocPrefix) { + if d.ldr.SymType(reloc.Sym) == sym.SDWARFLOC { d.ldr.SetAttrReachable(reloc.Sym, true) d.ldr.SetAttrNotInSymbolTable(reloc.Sym, true) syms = append(syms, reloc.Sym) diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 6f8b0dc27b..5d29aa59a6 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -1856,6 +1856,7 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb sn := l.SymName(cand) sv := l.SymVersion(cand) + st := l.SymType(cand) if sv < 0 { sv = anonVerReplacement } @@ -1866,7 +1867,7 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb if sn == "" { // Don't install anonymous symbols in the lookup tab. if s == nil { - s := l.allocSym(sn, sv) + s = l.allocSym(sn, sv) l.installSym(cand, s) } isnew = true @@ -1885,7 +1886,7 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb // Always copy these from new to old. s.Value = l.SymValue(cand) - s.Type = l.SymType(cand) + s.Type = st // If the data for a symbol has increased in size, make sure // we bring the new content across. @@ -1914,7 +1915,10 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb // If this symbol has any DWARF file relocations, we need to // make sure that the relocations are copied back over, since - // DWARF-gen alters the offset values for these relocs. + // DWARF-gen alters the offset values for these relocs. Also: + // if this is an info symbol and it refers to a previously + // unseen range/loc symbol, we'll need to fix up relocations + // for it as well. relocs := l.Relocs(cand) rslice = relocs.ReadSyms(rslice) for ri := range rslice { @@ -1922,6 +1926,14 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, syms *sym.Symb relfix = true break } + if st != sym.SDWARFINFO { + continue + } + rst := l.SymType(rslice[ri].Sym) + if rst == sym.SDWARFRANGE || rst == sym.SDWARFLOC { + relfix = true + break + } } if relfix {