mirror of
https://github.com/golang/go
synced 2024-11-12 08:50:22 -07:00
cmd/link: abstract DWARF metadata symbol lookup
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>
This commit is contained in:
parent
571236543f
commit
ec4ae29f52
@ -342,6 +342,16 @@ func lookupOrDiag(ctxt *Link, n string) *sym.Symbol {
|
|||||||
return s
|
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 {
|
func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) *dwarf.DWDie {
|
||||||
// Only emit typedefs for real names.
|
// Only emit typedefs for real names.
|
||||||
if strings.HasPrefix(name, "map[") {
|
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.
|
// indexes (created by numberfile) to CU-local indexes.
|
||||||
fileNums := make(map[int]int)
|
fileNums := make(map[int]int)
|
||||||
for _, s := range unit.lib.Textp { // textp has been dead-code-eliminated already.
|
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 {
|
for _, f := range s.FuncInfo.File {
|
||||||
if _, ok := fileNums[int(f.Value)]; ok {
|
if _, ok := fileNums[int(f.Value)]; ok {
|
||||||
continue
|
continue
|
||||||
@ -1756,12 +1766,12 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
|
|||||||
// referenced abstract functions.
|
// referenced abstract functions.
|
||||||
// Collect all debug_range symbols in unit.rangeSyms
|
// Collect all debug_range symbols in unit.rangeSyms
|
||||||
for _, s := range lib.Textp { // textp has been dead-code-eliminated already.
|
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.Attr |= sym.AttrNotInSymbolTable | sym.AttrReachable
|
||||||
dsym.Type = sym.SDWARFINFO
|
dsym.Type = sym.SDWARFINFO
|
||||||
unit.funcDIEs = append(unit.funcDIEs, dsym)
|
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 {
|
if rangeSym != nil && rangeSym.Size > 0 {
|
||||||
rangeSym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable
|
rangeSym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable
|
||||||
rangeSym.Type = sym.SDWARFRANGE
|
rangeSym.Type = sym.SDWARFRANGE
|
||||||
|
Loading…
Reference in New Issue
Block a user