]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: abstract DWARF metadata symbol lookup
authorAustin Clements <austin@google.com>
Mon, 22 Oct 2018 20:36:24 +0000 (16:36 -0400)
committerAustin Clements <austin@google.com>
Mon, 12 Nov 2018 20:27:21 +0000 (20:27 +0000)
The compiler passes a lot of DWARF metadata about functions to the
linker via symbols whose names are derived from the function's own
symbol name. We look up these symbols in several places. This is about
to get slightly more complex as we introduce ABIs as symbol versions,
so abstract this lookup pattern into a helper function.

For #27539.

Change-Id: Ic71f6b5dc6608a5a5f5f515808981e6d6f5d728e
Reviewed-on: https://go-review.googlesource.com/c/146858
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
src/cmd/link/internal/ld/dwarf.go

index 7a20650d9cc0cd143305bbca36077878141f94c3..b733bc690e6abace35182c84adf0ca5cc3f852e6 100644 (file)
@@ -342,6 +342,16 @@ func lookupOrDiag(ctxt *Link, n string) *sym.Symbol {
        return s
 }
 
+// dwarfFuncSym looks up a DWARF metadata symbol for function symbol s.
+// If the symbol does not exist, it creates it if create is true,
+// or returns nil otherwise.
+func dwarfFuncSym(ctxt *Link, s *sym.Symbol, meta string, create bool) *sym.Symbol {
+       if create {
+               return ctxt.Syms.Lookup(meta+s.Name, int(s.Version))
+       }
+       return ctxt.Syms.ROLookup(meta+s.Name, int(s.Version))
+}
+
 func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) *dwarf.DWDie {
        // Only emit typedefs for real names.
        if strings.HasPrefix(name, "map[") {
@@ -1146,7 +1156,7 @@ func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) {
        // indexes (created by numberfile) to CU-local indexes.
        fileNums := make(map[int]int)
        for _, s := range unit.lib.Textp { // textp has been dead-code-eliminated already.
-               dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version))
+               dsym := dwarfFuncSym(ctxt, s, dwarf.InfoPrefix, true)
                for _, f := range s.FuncInfo.File {
                        if _, ok := fileNums[int(f.Value)]; ok {
                                continue
@@ -1756,12 +1766,12 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
                // referenced abstract functions.
                // Collect all debug_range symbols in unit.rangeSyms
                for _, s := range lib.Textp { // textp has been dead-code-eliminated already.
-                       dsym := ctxt.Syms.ROLookup(dwarf.InfoPrefix+s.Name, int(s.Version))
+                       dsym := dwarfFuncSym(ctxt, s, dwarf.InfoPrefix, false)
                        dsym.Attr |= sym.AttrNotInSymbolTable | sym.AttrReachable
                        dsym.Type = sym.SDWARFINFO
                        unit.funcDIEs = append(unit.funcDIEs, dsym)
 
-                       rangeSym := ctxt.Syms.ROLookup(dwarf.RangePrefix+s.Name, int(s.Version))
+                       rangeSym := dwarfFuncSym(ctxt, s, dwarf.RangePrefix, false)
                        if rangeSym != nil && rangeSym.Size > 0 {
                                rangeSym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable
                                rangeSym.Type = sym.SDWARFRANGE