mirror of
https://github.com/golang/go
synced 2024-11-19 00:54:42 -07:00
cmd/internal/{dwarf,obj}: stop substituting "" with pkgprefix
cmd/asm and cmd/compile now always create symbols with the appropriate package prefixes, so cmd/internal/dwarf and cmd/internal/obj can stop worrying about qualifying names itself. Change-Id: I9aee5d759bf0d41a61722c777e7f66fce957e79e Reviewed-on: https://go-review.googlesource.com/c/go/+/523338 Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
cf338eb890
commit
b3faace3f7
@ -16,8 +16,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cmd/internal/objabi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// InfoPrefix is the prefix for all the symbols containing DWARF info entries.
|
// InfoPrefix is the prefix for all the symbols containing DWARF info entries.
|
||||||
@ -86,7 +84,6 @@ type Range struct {
|
|||||||
// creating the DWARF subprogram DIE(s) for a function.
|
// creating the DWARF subprogram DIE(s) for a function.
|
||||||
type FnState struct {
|
type FnState struct {
|
||||||
Name string
|
Name string
|
||||||
Importpath string
|
|
||||||
Info Sym
|
Info Sym
|
||||||
Filesym Sym
|
Filesym Sym
|
||||||
Loc Sym
|
Loc Sym
|
||||||
@ -1241,15 +1238,8 @@ func PutAbstractFunc(ctxt Context, s *FnState) error {
|
|||||||
Uleb128put(ctxt, s.Absfn, int64(abbrev))
|
Uleb128put(ctxt, s.Absfn, int64(abbrev))
|
||||||
|
|
||||||
fullname := s.Name
|
fullname := s.Name
|
||||||
if strings.HasPrefix(s.Name, "\"\".") {
|
if strings.HasPrefix(s.Name, `"".`) {
|
||||||
// Generate a fully qualified name for the function in the
|
return fmt.Errorf("unqualified symbol name: %v", s.Name)
|
||||||
// abstract case. This is so as to avoid the need for the
|
|
||||||
// linker to process the DIE with patchDWARFName(); we can't
|
|
||||||
// allow the name attribute of an abstract subprogram DIE to
|
|
||||||
// be rewritten, since it would change the offsets of the
|
|
||||||
// child DIEs (which we're relying on in order for abstract
|
|
||||||
// origin references to work).
|
|
||||||
fullname = objabi.PathToPrefix(s.Importpath) + "." + s.Name[3:]
|
|
||||||
}
|
}
|
||||||
putattr(ctxt, s.Absfn, abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(fullname)), fullname)
|
putattr(ctxt, s.Absfn, abbrev, DW_FORM_string, DW_CLS_STRING, int64(len(fullname)), fullname)
|
||||||
|
|
||||||
@ -1436,10 +1426,9 @@ func PutDefaultFunc(ctxt Context, s *FnState, isWrapper bool) error {
|
|||||||
}
|
}
|
||||||
Uleb128put(ctxt, s.Info, int64(abbrev))
|
Uleb128put(ctxt, s.Info, int64(abbrev))
|
||||||
|
|
||||||
// Expand '"".' to import path.
|
|
||||||
name := s.Name
|
name := s.Name
|
||||||
if s.Importpath != "" {
|
if strings.HasPrefix(name, `"".`) {
|
||||||
name = strings.Replace(name, "\"\".", objabi.PathToPrefix(s.Importpath)+".", -1)
|
return fmt.Errorf("unqualified symbol name: %v", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
putattr(ctxt, s.Info, DW_ABRV_FUNCTION, DW_FORM_string, DW_CLS_STRING, int64(len(name)), name)
|
putattr(ctxt, s.Info, DW_ABRV_FUNCTION, DW_FORM_string, DW_CLS_STRING, int64(len(name)), name)
|
||||||
|
@ -367,7 +367,6 @@ func (ctxt *Link) populateDWARF(curfn interface{}, s *LSym) {
|
|||||||
filesym := ctxt.fileSymbol(s)
|
filesym := ctxt.fileSymbol(s)
|
||||||
fnstate := &dwarf.FnState{
|
fnstate := &dwarf.FnState{
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Importpath: myimportpath,
|
|
||||||
Info: info,
|
Info: info,
|
||||||
Filesym: filesym,
|
Filesym: filesym,
|
||||||
Loc: loc,
|
Loc: loc,
|
||||||
@ -441,7 +440,6 @@ func (ctxt *Link) DwarfAbstractFunc(curfn interface{}, s *LSym) {
|
|||||||
dwctxt := dwCtxt{ctxt}
|
dwctxt := dwCtxt{ctxt}
|
||||||
fnstate := dwarf.FnState{
|
fnstate := dwarf.FnState{
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Importpath: ctxt.Pkgpath,
|
|
||||||
Info: absfn,
|
Info: absfn,
|
||||||
Absfn: absfn,
|
Absfn: absfn,
|
||||||
StartLine: startLine,
|
StartLine: startLine,
|
||||||
|
@ -292,8 +292,8 @@ func (w *writer) StringTable() {
|
|||||||
// Don't include them if Flag_noRefName
|
// Don't include them if Flag_noRefName
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.pkgpath != "" {
|
if strings.HasPrefix(s.Name, `"".`) {
|
||||||
s.Name = strings.Replace(s.Name, "\"\".", w.pkgpath+".", -1)
|
w.ctxt.Diag("unqualified symbol name: %v", s.Name)
|
||||||
}
|
}
|
||||||
w.AddString(s.Name)
|
w.AddString(s.Name)
|
||||||
})
|
})
|
||||||
|
@ -22,6 +22,10 @@ type Plist struct {
|
|||||||
type ProgAlloc func() *Prog
|
type ProgAlloc func() *Prog
|
||||||
|
|
||||||
func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
|
func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
|
||||||
|
if ctxt.Pkgpath == "" {
|
||||||
|
panic("Flushplist called without Pkgpath")
|
||||||
|
}
|
||||||
|
|
||||||
// Build list of symbols, and assign instructions to lists.
|
// Build list of symbols, and assign instructions to lists.
|
||||||
var curtext *LSym
|
var curtext *LSym
|
||||||
var etext *Prog
|
var etext *Prog
|
||||||
@ -98,7 +102,7 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
|
|||||||
if ctxt.IsAsm {
|
if ctxt.IsAsm {
|
||||||
pkgPrefix := objabi.PathToPrefix(ctxt.Pkgpath) + "."
|
pkgPrefix := objabi.PathToPrefix(ctxt.Pkgpath) + "."
|
||||||
for _, s := range text {
|
for _, s := range text {
|
||||||
if !strings.HasPrefix(s.Name, `"".`) && !strings.HasPrefix(s.Name, pkgPrefix) {
|
if !strings.HasPrefix(s.Name, pkgPrefix) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// The current args_stackmap generation in the compiler assumes
|
// The current args_stackmap generation in the compiler assumes
|
||||||
@ -187,15 +191,16 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos) {
|
|||||||
ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(start), s.Name)
|
ctxt.Diag("%s: symbol %s redeclared", ctxt.PosTable.Pos(start), s.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(s.Name, `"".`) {
|
||||||
|
ctxt.Diag("%s: unqualified symbol name: %s", ctxt.PosTable.Pos(start), s.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// startLine should be the same line number that would be displayed via
|
// startLine should be the same line number that would be displayed via
|
||||||
// pcln, etc for the declaration (i.e., relative line number, as
|
// pcln, etc for the declaration (i.e., relative line number, as
|
||||||
// adjusted by //line).
|
// adjusted by //line).
|
||||||
_, startLine := ctxt.getFileSymbolAndLine(start)
|
_, startLine := ctxt.getFileSymbolAndLine(start)
|
||||||
|
|
||||||
// TODO(mdempsky): Remove once cmd/asm stops writing "" symbols.
|
s.Func().FuncID = objabi.GetFuncID(s.Name, flag&WRAPPER != 0 || flag&ABIWRAPPER != 0)
|
||||||
name := strings.Replace(s.Name, "\"\"", ctxt.Pkgpath, -1)
|
|
||||||
s.Func().FuncID = objabi.GetFuncID(name, flag&WRAPPER != 0 || flag&ABIWRAPPER != 0)
|
|
||||||
s.Func().FuncFlag = ctxt.toFuncFlag(flag)
|
s.Func().FuncFlag = ctxt.toFuncFlag(flag)
|
||||||
s.Func().StartLine = startLine
|
s.Func().StartLine = startLine
|
||||||
s.Set(AttrOnList, true)
|
s.Set(AttrOnList, true)
|
||||||
|
@ -219,6 +219,10 @@ func (ctxt *Link) GCLocalsSym(data []byte) *LSym {
|
|||||||
// asm is set to true if this is called by the assembler (i.e. not the compiler),
|
// asm is set to true if this is called by the assembler (i.e. not the compiler),
|
||||||
// in which case all the symbols are non-package (for now).
|
// in which case all the symbols are non-package (for now).
|
||||||
func (ctxt *Link) NumberSyms() {
|
func (ctxt *Link) NumberSyms() {
|
||||||
|
if ctxt.Pkgpath == "" {
|
||||||
|
panic("NumberSyms called without package path")
|
||||||
|
}
|
||||||
|
|
||||||
if ctxt.Headtype == objabi.Haix {
|
if ctxt.Headtype == objabi.Haix {
|
||||||
// Data must be in a reliable order for reproducible builds.
|
// Data must be in a reliable order for reproducible builds.
|
||||||
// The original entries are in a reliable order, but the TOC symbols
|
// The original entries are in a reliable order, but the TOC symbols
|
||||||
@ -249,9 +253,7 @@ func (ctxt *Link) NumberSyms() {
|
|||||||
|
|
||||||
var idx, hashedidx, hashed64idx, nonpkgidx int32
|
var idx, hashedidx, hashed64idx, nonpkgidx int32
|
||||||
ctxt.traverseSyms(traverseDefs|traversePcdata, func(s *LSym) {
|
ctxt.traverseSyms(traverseDefs|traversePcdata, func(s *LSym) {
|
||||||
// if Pkgpath is unknown, cannot hash symbols with relocations, as it
|
if s.ContentAddressable() {
|
||||||
// may reference named symbols whose names are not fully expanded.
|
|
||||||
if s.ContentAddressable() && (ctxt.Pkgpath != "" || len(s.R) == 0) {
|
|
||||||
if s.Size <= 8 && len(s.R) == 0 && contentHashSection(s) == 0 {
|
if s.Size <= 8 && len(s.R) == 0 && contentHashSection(s) == 0 {
|
||||||
// We can use short hash only for symbols without relocations.
|
// We can use short hash only for symbols without relocations.
|
||||||
// Don't use short hash for symbols that belong in a particular section
|
// Don't use short hash for symbols that belong in a particular section
|
||||||
|
Loading…
Reference in New Issue
Block a user