mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: give names and a type to the symbol types used by genasmsym
Doing this revealed some dead code. Change-Id: I5202fcc3f73e3dfddfea3ec7b772e16da51195da Reviewed-on: https://go-review.googlesource.com/29331 Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
c1bee49cac
commit
2266047556
5 changed files with 68 additions and 72 deletions
|
|
@ -814,7 +814,7 @@ func synthesizechantypes(ctxt *Link, die *dwarf.DWDie) {
|
|||
}
|
||||
|
||||
// For use with pass.c::genasmsym
|
||||
func defdwsymb(ctxt *Link, sym *Symbol, s string, t int, v int64, size int64, ver int, gotype *Symbol) {
|
||||
func defdwsymb(ctxt *Link, sym *Symbol, s string, t SymbolType, v int64, size int64, ver int, gotype *Symbol) {
|
||||
if strings.HasPrefix(s, "go.string.") {
|
||||
return
|
||||
}
|
||||
|
|
@ -834,7 +834,7 @@ func defdwsymb(ctxt *Link, sym *Symbol, s string, t int, v int64, size int64, ve
|
|||
default:
|
||||
return
|
||||
|
||||
case 'd', 'b', 'D', 'B':
|
||||
case DataSym, BSSSym:
|
||||
dv = newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, s, ver)
|
||||
newabslocexprattr(dv, v, sym)
|
||||
if ver == 0 {
|
||||
|
|
@ -842,7 +842,7 @@ func defdwsymb(ctxt *Link, sym *Symbol, s string, t int, v int64, size int64, ve
|
|||
}
|
||||
fallthrough
|
||||
|
||||
case 'a', 'p':
|
||||
case AutoSym, ParamSym:
|
||||
dt = defgotype(ctxt, gotype)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1804,16 +1804,30 @@ func doversion() {
|
|||
Exitf("version %s", obj.Version)
|
||||
}
|
||||
|
||||
func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, int, *Symbol)) {
|
||||
type SymbolType int8
|
||||
|
||||
const (
|
||||
TextSym SymbolType = 'T'
|
||||
DataSym = 'D'
|
||||
BSSSym = 'B'
|
||||
UndefinedSym = 'U'
|
||||
TLSSym = 't'
|
||||
FileSym = 'f'
|
||||
FrameSym = 'm'
|
||||
ParamSym = 'p'
|
||||
AutoSym = 'a'
|
||||
)
|
||||
|
||||
func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, int64, int, *Symbol)) {
|
||||
// These symbols won't show up in the first loop below because we
|
||||
// skip STEXT symbols. Normal STEXT symbols are emitted by walking textp.
|
||||
s := Linklookup(ctxt, "runtime.text", 0)
|
||||
if s.Type == obj.STEXT {
|
||||
put(ctxt, s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
|
||||
put(ctxt, s, s.Name, TextSym, s.Value, s.Size, int(s.Version), nil)
|
||||
}
|
||||
s = Linklookup(ctxt, "runtime.etext", 0)
|
||||
if s.Type == obj.STEXT {
|
||||
put(ctxt, s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
|
||||
put(ctxt, s, s.Name, TextSym, s.Value, s.Size, int(s.Version), nil)
|
||||
}
|
||||
|
||||
for _, s := range ctxt.Allsym {
|
||||
|
|
@ -1852,7 +1866,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, i
|
|||
if !s.Attr.Reachable() {
|
||||
continue
|
||||
}
|
||||
put(ctxt, s, s.Name, 'D', Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
put(ctxt, s, s.Name, DataSym, Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
|
||||
case obj.SBSS, obj.SNOPTRBSS:
|
||||
if !s.Attr.Reachable() {
|
||||
|
|
@ -1861,39 +1875,39 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, i
|
|||
if len(s.P) > 0 {
|
||||
ctxt.Diag("%s should not be bss (size=%d type=%d special=%v)", s.Name, len(s.P), s.Type, s.Attr.Special())
|
||||
}
|
||||
put(ctxt, s, s.Name, 'B', Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
put(ctxt, s, s.Name, BSSSym, Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
|
||||
case obj.SFILE:
|
||||
put(ctxt, nil, s.Name, 'f', s.Value, 0, int(s.Version), nil)
|
||||
put(ctxt, nil, s.Name, FileSym, s.Value, 0, int(s.Version), nil)
|
||||
|
||||
case obj.SHOSTOBJ:
|
||||
if Headtype == obj.Hwindows || Headtype == obj.Hwindowsgui || Iself {
|
||||
put(ctxt, s, s.Name, 'U', s.Value, 0, int(s.Version), nil)
|
||||
put(ctxt, s, s.Name, UndefinedSym, s.Value, 0, int(s.Version), nil)
|
||||
}
|
||||
|
||||
case obj.SDYNIMPORT:
|
||||
if !s.Attr.Reachable() {
|
||||
continue
|
||||
}
|
||||
put(ctxt, s, s.Extname, 'U', 0, 0, int(s.Version), nil)
|
||||
put(ctxt, s, s.Extname, UndefinedSym, 0, 0, int(s.Version), nil)
|
||||
|
||||
case obj.STLSBSS:
|
||||
if Linkmode == LinkExternal && Headtype != obj.Hopenbsd {
|
||||
put(ctxt, s, s.Name, 't', Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
put(ctxt, s, s.Name, TLSSym, Symaddr(ctxt, s), s.Size, int(s.Version), s.Gotype)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var off int32
|
||||
for _, s := range ctxt.Textp {
|
||||
put(ctxt, s, s.Name, 'T', s.Value, s.Size, int(s.Version), s.Gotype)
|
||||
put(ctxt, s, s.Name, TextSym, s.Value, s.Size, int(s.Version), s.Gotype)
|
||||
|
||||
locals := int32(0)
|
||||
if s.FuncInfo != nil {
|
||||
locals = s.FuncInfo.Locals
|
||||
}
|
||||
// NOTE(ality): acid can't produce a stack trace without .frame symbols
|
||||
put(ctxt, nil, ".frame", 'm', int64(locals)+int64(SysArch.PtrSize), 0, 0, nil)
|
||||
put(ctxt, nil, ".frame", FrameSym, int64(locals)+int64(SysArch.PtrSize), 0, 0, nil)
|
||||
|
||||
if s.FuncInfo == nil {
|
||||
continue
|
||||
|
|
@ -1914,13 +1928,13 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, i
|
|||
|
||||
// FP
|
||||
if off >= 0 {
|
||||
put(ctxt, nil, a.Asym.Name, 'p', int64(off), 0, 0, a.Gotype)
|
||||
put(ctxt, nil, a.Asym.Name, ParamSym, int64(off), 0, 0, a.Gotype)
|
||||
continue
|
||||
}
|
||||
|
||||
// SP
|
||||
if off <= int32(-SysArch.PtrSize) {
|
||||
put(ctxt, nil, a.Asym.Name, 'a', -(int64(off) + int64(SysArch.PtrSize)), 0, 0, a.Gotype)
|
||||
put(ctxt, nil, a.Asym.Name, AutoSym, -(int64(off) + int64(SysArch.PtrSize)), 0, 0, a.Gotype)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -612,7 +612,7 @@ func symkind(s *Symbol) int {
|
|||
return SymKindLocal
|
||||
}
|
||||
|
||||
func addsym(ctxt *Link, s *Symbol, name string, type_ int, addr int64, size int64, ver int, gotype *Symbol) {
|
||||
func addsym(ctxt *Link, s *Symbol, name string, type_ SymbolType, addr int64, size int64, ver int, gotype *Symbol) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -621,7 +621,7 @@ func addsym(ctxt *Link, s *Symbol, name string, type_ int, addr int64, size int6
|
|||
default:
|
||||
return
|
||||
|
||||
case 'D', 'B', 'T':
|
||||
case DataSym, BSSSym, TextSym:
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -656,12 +656,12 @@ func (x machoscmp) Less(i, j int) bool {
|
|||
return s1.Extname < s2.Extname
|
||||
}
|
||||
|
||||
func machogenasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, int, *Symbol)) {
|
||||
genasmsym(ctxt, put)
|
||||
func machogenasmsym(ctxt *Link) {
|
||||
genasmsym(ctxt, addsym)
|
||||
for _, s := range ctxt.Allsym {
|
||||
if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
|
||||
if s.Attr.Reachable() {
|
||||
put(ctxt, s, "", 'D', 0, 0, 0, nil)
|
||||
addsym(ctxt, s, "", DataSym, 0, 0, 0, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -674,10 +674,10 @@ func machosymorder(ctxt *Link) {
|
|||
for i := 0; i < len(dynexp); i++ {
|
||||
dynexp[i].Attr |= AttrReachable
|
||||
}
|
||||
machogenasmsym(ctxt, addsym)
|
||||
machogenasmsym(ctxt)
|
||||
sortsym = make([]*Symbol, nsortsym)
|
||||
nsortsym = 0
|
||||
machogenasmsym(ctxt, addsym)
|
||||
machogenasmsym(ctxt)
|
||||
sort.Sort(machoscmp(sortsym[:nsortsym]))
|
||||
for i := 0; i < nsortsym; i++ {
|
||||
sortsym[i].Dynid = int32(i)
|
||||
|
|
|
|||
|
|
@ -930,17 +930,17 @@ func newPEDWARFSection(ctxt *Link, name string, size int64) *IMAGE_SECTION_HEADE
|
|||
func writePESymTableRecords(ctxt *Link) int {
|
||||
var symcnt int
|
||||
|
||||
put := func(ctxt *Link, s *Symbol, name string, type_ int, addr int64, size int64, ver int, gotype *Symbol) {
|
||||
put := func(ctxt *Link, s *Symbol, name string, type_ SymbolType, addr int64, size int64, ver int, gotype *Symbol) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
if s.Sect == nil && type_ != 'U' {
|
||||
if s.Sect == nil && type_ != UndefinedSym {
|
||||
return
|
||||
}
|
||||
switch type_ {
|
||||
default:
|
||||
return
|
||||
case 'D', 'B', 'T', 'U':
|
||||
case DataSym, BSSSym, TextSym, UndefinedSym:
|
||||
}
|
||||
|
||||
// only windows/386 requires underscore prefix on external symbols
|
||||
|
|
@ -966,7 +966,7 @@ func writePESymTableRecords(ctxt *Link) int {
|
|||
} else if uint64(s.Value) >= Segtext.Vaddr {
|
||||
value = int64(uint64(s.Value) - Segtext.Vaddr)
|
||||
sect = textsect
|
||||
} else if type_ == 'U' {
|
||||
} else if type_ == UndefinedSym {
|
||||
typ = IMAGE_SYM_DTYPE_FUNCTION
|
||||
} else {
|
||||
ctxt.Diag("addpesym %#x", addr)
|
||||
|
|
@ -1000,13 +1000,13 @@ func writePESymTableRecords(ctxt *Link) int {
|
|||
for d := dr; d != nil; d = d.next {
|
||||
for m := d.ms; m != nil; m = m.next {
|
||||
s := m.s.R[0].Xsym
|
||||
put(ctxt, s, s.Name, 'U', 0, int64(SysArch.PtrSize), 0, nil)
|
||||
put(ctxt, s, s.Name, UndefinedSym, 0, int64(SysArch.PtrSize), 0, nil)
|
||||
}
|
||||
}
|
||||
|
||||
s := Linklookup(ctxt, ".text", 0)
|
||||
if s.Type == obj.STEXT {
|
||||
put(ctxt, s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
|
||||
put(ctxt, s, s.Name, TextSym, s.Value, s.Size, int(s.Version), nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,29 +76,26 @@ var numelfsym int = 1 // 0 is reserved
|
|||
|
||||
var elfbind int
|
||||
|
||||
func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, ver int, go_ *Symbol) {
|
||||
var type_ int
|
||||
func putelfsym(ctxt *Link, x *Symbol, s string, t SymbolType, addr int64, size int64, ver int, go_ *Symbol) {
|
||||
var typ int
|
||||
|
||||
switch t {
|
||||
default:
|
||||
return
|
||||
|
||||
case 'T':
|
||||
type_ = STT_FUNC
|
||||
case TextSym:
|
||||
typ = STT_FUNC
|
||||
|
||||
case 'D':
|
||||
type_ = STT_OBJECT
|
||||
case DataSym, BSSSym:
|
||||
typ = STT_OBJECT
|
||||
|
||||
case 'B':
|
||||
type_ = STT_OBJECT
|
||||
|
||||
case 'U':
|
||||
case UndefinedSym:
|
||||
// ElfType is only set for symbols read from Go shared libraries, but
|
||||
// for other symbols it is left as STT_NOTYPE which is fine.
|
||||
type_ = int(x.ElfType)
|
||||
typ = int(x.ElfType)
|
||||
|
||||
case 't':
|
||||
type_ = STT_TLS
|
||||
case TLSSym:
|
||||
typ = STT_TLS
|
||||
}
|
||||
|
||||
xo := x
|
||||
|
|
@ -147,7 +144,7 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
|
|||
if x.Type&obj.SHIDDEN != 0 {
|
||||
other = STV_HIDDEN
|
||||
}
|
||||
if (Buildmode == BuildmodeCArchive || Buildmode == BuildmodePIE || ctxt.DynlinkingGo()) && SysArch.Family == sys.PPC64 && type_ == STT_FUNC && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
|
||||
if (Buildmode == BuildmodeCArchive || Buildmode == BuildmodePIE || ctxt.DynlinkingGo()) && SysArch.Family == sys.PPC64 && typ == STT_FUNC && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
|
||||
// On ppc64 the top three bits of the st_other field indicate how
|
||||
// many instructions separate the global and local entry points. In
|
||||
// our case it is two instructions, indicated by the value 3.
|
||||
|
|
@ -171,7 +168,7 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
|
|||
// (*Symbol).ElfsymForReloc). This is approximately equivalent to the
|
||||
// ELF linker -Bsymbolic-functions option, but that is buggy on
|
||||
// several platforms.
|
||||
putelfsyment(putelfstr("local."+s), addr, size, STB_LOCAL<<4|type_&0xf, elfshnum, other)
|
||||
putelfsyment(putelfstr("local."+s), addr, size, STB_LOCAL<<4|typ&0xf, elfshnum, other)
|
||||
x.LocalElfsym = int32(numelfsym)
|
||||
numelfsym++
|
||||
return
|
||||
|
|
@ -179,7 +176,7 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
|
|||
return
|
||||
}
|
||||
|
||||
putelfsyment(putelfstr(s), addr, size, bind<<4|type_&0xf, elfshnum, other)
|
||||
putelfsyment(putelfstr(s), addr, size, bind<<4|typ&0xf, elfshnum, other)
|
||||
x.Elfsym = int32(numelfsym)
|
||||
numelfsym++
|
||||
}
|
||||
|
|
@ -211,20 +208,16 @@ func Asmelfsym(ctxt *Link) {
|
|||
genasmsym(ctxt, putelfsym)
|
||||
}
|
||||
|
||||
func putplan9sym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, ver int, go_ *Symbol) {
|
||||
switch t {
|
||||
case 'T', 'L', 'D', 'B':
|
||||
func putplan9sym(ctxt *Link, x *Symbol, s string, typ SymbolType, addr int64, size int64, ver int, go_ *Symbol) {
|
||||
t := int(typ)
|
||||
switch typ {
|
||||
case TextSym, DataSym, BSSSym:
|
||||
if ver != 0 {
|
||||
t += 'a' - 'A'
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case 'a',
|
||||
'p',
|
||||
'f',
|
||||
'z',
|
||||
'Z',
|
||||
'm':
|
||||
case AutoSym, ParamSym, FileSym, FrameSym:
|
||||
l := 4
|
||||
if Headtype == obj.Hplan9 && SysArch.Family == sys.AMD64 && !Flag8 {
|
||||
Lputb(uint32(addr >> 32))
|
||||
|
|
@ -235,26 +228,15 @@ func putplan9sym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64,
|
|||
Cput(uint8(t + 0x80)) /* 0x80 is variable length */
|
||||
|
||||
var i int
|
||||
if t == 'z' || t == 'Z' {
|
||||
Cput(s[0])
|
||||
for i = 1; s[i] != 0 || s[i+1] != 0; i += 2 {
|
||||
Cput(s[i])
|
||||
Cput(s[i+1])
|
||||
}
|
||||
|
||||
Cput(0)
|
||||
Cput(0)
|
||||
i++
|
||||
} else {
|
||||
/* skip the '<' in filenames */
|
||||
if t == 'f' {
|
||||
if t == FileSym {
|
||||
s = s[1:]
|
||||
}
|
||||
for i = 0; i < len(s); i++ {
|
||||
Cput(s[i])
|
||||
}
|
||||
Cput(0)
|
||||
}
|
||||
|
||||
Symsize += int32(l) + 1 + int32(i) + 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue