cmd/link, cmd/internal/obj: use aux symbol for global variable DWARF info

Currently, for a global variable, its debug info symbol is a named
symbol with the variable's name with a special prefix. And the
linker looks it up by name. This CL makes the debug info symbol an
aux symbol of the variable symbol.

Change-Id: I55614d0ef2af9c53eb40144ad80e09339bf3cbee
Reviewed-on: https://go-review.googlesource.com/c/go/+/490816
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Mui 2023-04-28 21:35:31 -04:00
parent 04f059f9ef
commit 4e8c6af239
6 changed files with 62 additions and 24 deletions

View file

@ -465,7 +465,7 @@ type LSym struct {
P []byte
R []Reloc
Extra *interface{} // *FuncInfo or *FileInfo, if present
Extra *interface{} // *FuncInfo, *VarInfo, or *FileInfo, if present
Pkg string
PkgIdx int32
@ -537,6 +537,30 @@ func (s *LSym) Func() *FuncInfo {
return f
}
type VarInfo struct {
dwarfInfoSym *LSym
}
// NewVarInfo allocates and returns a VarInfo for LSym.
func (s *LSym) NewVarInfo() *VarInfo {
if s.Extra != nil {
panic(fmt.Sprintf("invalid use of LSym - NewVarInfo with Extra of type %T", *s.Extra))
}
f := new(VarInfo)
s.Extra = new(interface{})
*s.Extra = f
return f
}
// VarInfo returns the *VarInfo associated with s, or else nil.
func (s *LSym) VarInfo() *VarInfo {
if s.Extra == nil {
return nil
}
f, _ := (*s.Extra).(*VarInfo)
return f
}
// A FileInfo contains extra fields for SDATA symbols backed by files.
// (If LSym.Extra is a *FileInfo, LSym.P == nil.)
type FileInfo struct {