]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: demote dwarf {range,loc} sub-symbols to aux
authorThan McIntosh <thanm@google.com>
Mon, 9 Mar 2020 15:42:03 +0000 (11:42 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 12 Mar 2020 18:56:09 +0000 (18:56 +0000)
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 <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/dwarf/dwarf.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/objfile2.go
src/cmd/internal/obj/plist.go
src/cmd/link/internal/ld/dwarf.go
src/cmd/link/internal/loader/loader.go

index 0fdbe1ae62582c4eedd77bbd29694ca7a0d4c88d..3ba0623c8cd2e29995cfd3d8ab470732f1385e8e 100644 (file)
@@ -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."
 
index bca42c212d8f1a20e01399a45752844f02a036fa..4669e415cc757a318f48d09055a5fca0e327237e 100644 (file)
@@ -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)
                }
index 839167bc1a31fafcdca34317c8252ecbac9f5f32..dc492733ac5cd9b88621c5f319b1d15d455daa16 100644 (file)
@@ -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...)
 }
index 4d02042956a84e026e2cf4a145c7bd3053ef5694..fdb549025515a1d9cb709abfe561f60948a9e3a6 100644 (file)
@@ -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)
index 8376ea82db21acbbc3a77f9e6793ecc1cc1947ca..dcc957655ae418e34f7c9396f0cce57dfaffdf3f 100644 (file)
@@ -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)
index 6f8b0dc27bc2b0d9786531b11b08ab0a45523bdb..5d29aa59a655b809730bc46ca5ebb5db36e9694a 100644 (file)
@@ -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 {