mirror of
https://github.com/golang/go
synced 2024-11-26 23:11:24 -07:00
[dev.link] cmd/link: skip symtab entries for selected file local symbols
Don't emit symbol table entries for compiler-generated file-local symbols (this category includes .stmp_* temporaries and *.stkobj symbols). Note that user-written static symbols within assembler sources will still be added to the symbol table. Apply the same test when emitting DWARF for global variables. Change-Id: I4db77a2750a0b575e051dfea895c4742cf6709a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/240539 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
0434d40934
commit
8aa036e913
@ -241,6 +241,7 @@ const SymABIstatic = ^uint16(0)
|
||||
const (
|
||||
ObjFlagShared = 1 << iota // this object is built with -shared
|
||||
ObjFlagNeedNameExpansion // the linker needs to expand `"".` to package path in symbol names
|
||||
ObjFlagFromAssembly // object is from asm src, not go
|
||||
)
|
||||
|
||||
// Sym.Flag
|
||||
@ -742,3 +743,4 @@ func (r *Reader) Flags() uint32 {
|
||||
|
||||
func (r *Reader) Shared() bool { return r.Flags()&ObjFlagShared != 0 }
|
||||
func (r *Reader) NeedNameExpansion() bool { return r.Flags()&ObjFlagNeedNameExpansion != 0 }
|
||||
func (r *Reader) FromAssembly() bool { return r.Flags()&ObjFlagFromAssembly != 0 }
|
||||
|
@ -41,6 +41,9 @@ func WriteObjFile(ctxt *Link, b *bio.Writer, pkgpath string) {
|
||||
if pkgpath == "" {
|
||||
flags |= goobj2.ObjFlagNeedNameExpansion
|
||||
}
|
||||
if ctxt.IsAsm {
|
||||
flags |= goobj2.ObjFlagFromAssembly
|
||||
}
|
||||
h := goobj2.Header{
|
||||
Magic: goobj2.Magic,
|
||||
Fingerprint: ctxt.Fingerprint,
|
||||
|
@ -1887,11 +1887,12 @@ func dwarfGenerateDebugInfo(ctxt *Link) {
|
||||
if d.ldr.SymGoType(idx) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
sn := d.ldr.SymName(idx)
|
||||
if ctxt.LinkMode != LinkExternal && isStaticTemp(sn) {
|
||||
// Skip file local symbols (this includes static tmps, stack
|
||||
// object symbols, and local symbols in assembler src files).
|
||||
if d.ldr.IsFileLocal(idx) {
|
||||
continue
|
||||
}
|
||||
sn := d.ldr.SymName(idx)
|
||||
if sn == "" {
|
||||
// skip aux symbols
|
||||
continue
|
||||
|
@ -196,7 +196,14 @@ func genelfsym(ctxt *Link, elfbind int) {
|
||||
return false
|
||||
}
|
||||
// FIXME: avoid having to do name inspections here.
|
||||
// NB: the restrictions below on file local symbols are a bit
|
||||
// arbitrary -- if it turns out we need nameless static
|
||||
// symbols they could be relaxed/removed.
|
||||
sn := ldr.SymName(s)
|
||||
if (sn == "" || sn[0] == '.') && ldr.IsFileLocal(s) {
|
||||
panic(fmt.Sprintf("unexpected file local symbol %d %s<%d>\n",
|
||||
s, sn, ldr.SymVersion(s)))
|
||||
}
|
||||
if (sn == "" || sn[0] == '.') && !ldr.IsFileLocal(s) {
|
||||
return false
|
||||
}
|
||||
@ -499,15 +506,14 @@ func (ctxt *Link) symtab() []sym.SymKind {
|
||||
nsym := loader.Sym(ldr.NSym())
|
||||
symGroupType := make([]sym.SymKind, nsym)
|
||||
for s := loader.Sym(1); s < nsym; s++ {
|
||||
name := ldr.SymName(s)
|
||||
if !ctxt.IsExternal() && isStaticTemp(name) {
|
||||
if !ctxt.IsExternal() && ldr.IsFileLocal(s) && !ldr.IsFromAssembly(s) {
|
||||
ldr.SetAttrNotInSymbolTable(s, true)
|
||||
}
|
||||
|
||||
if !ldr.AttrReachable(s) || ldr.AttrSpecial(s) || (ldr.SymType(s) != sym.SRODATA && ldr.SymType(s) != sym.SGOFUNC) {
|
||||
continue
|
||||
}
|
||||
|
||||
name := ldr.SymName(s)
|
||||
switch {
|
||||
case strings.HasPrefix(name, "type."):
|
||||
if !ctxt.DynlinkingGo() {
|
||||
@ -768,10 +774,3 @@ func (ctxt *Link) symtab() []sym.SymKind {
|
||||
}
|
||||
return symGroupType
|
||||
}
|
||||
|
||||
func isStaticTemp(name string) bool {
|
||||
if i := strings.LastIndex(name, "/"); i >= 0 {
|
||||
name = name[i:]
|
||||
}
|
||||
return strings.Contains(name, "..stmp_")
|
||||
}
|
||||
|
@ -683,7 +683,19 @@ func (l *Loader) SymVersion(i Sym) int {
|
||||
return int(abiToVer(r.Sym(li).ABI(), r.version))
|
||||
}
|
||||
|
||||
func (l *Loader) IsFileLocal(i Sym) bool { return l.SymVersion(i) >= sym.SymVerStatic }
|
||||
func (l *Loader) IsFileLocal(i Sym) bool {
|
||||
return l.SymVersion(i) >= sym.SymVerStatic
|
||||
}
|
||||
|
||||
// IsFromAssembly returns true if this symbol is derived from an
|
||||
// object file generated by the Go assembler.
|
||||
func (l *Loader) IsFromAssembly(i Sym) bool {
|
||||
if l.IsExternal(i) {
|
||||
return false
|
||||
}
|
||||
r, _ := l.toLocal(i)
|
||||
return r.FromAssembly()
|
||||
}
|
||||
|
||||
// Returns the type of the i-th symbol.
|
||||
func (l *Loader) SymType(i Sym) sym.SymKind {
|
||||
|
Loading…
Reference in New Issue
Block a user