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:
Michael Hudson-Doyle 2016-09-16 16:22:08 +12:00
parent c1bee49cac
commit 2266047556
5 changed files with 68 additions and 72 deletions

View file

@ -814,7 +814,7 @@ func synthesizechantypes(ctxt *Link, die *dwarf.DWDie) {
} }
// For use with pass.c::genasmsym // 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.") { if strings.HasPrefix(s, "go.string.") {
return return
} }
@ -834,7 +834,7 @@ func defdwsymb(ctxt *Link, sym *Symbol, s string, t int, v int64, size int64, ve
default: default:
return return
case 'd', 'b', 'D', 'B': case DataSym, BSSSym:
dv = newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, s, ver) dv = newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, s, ver)
newabslocexprattr(dv, v, sym) newabslocexprattr(dv, v, sym)
if ver == 0 { if ver == 0 {
@ -842,7 +842,7 @@ func defdwsymb(ctxt *Link, sym *Symbol, s string, t int, v int64, size int64, ve
} }
fallthrough fallthrough
case 'a', 'p': case AutoSym, ParamSym:
dt = defgotype(ctxt, gotype) dt = defgotype(ctxt, gotype)
} }

View file

@ -1804,16 +1804,30 @@ func doversion() {
Exitf("version %s", obj.Version) 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 // These symbols won't show up in the first loop below because we
// skip STEXT symbols. Normal STEXT symbols are emitted by walking textp. // skip STEXT symbols. Normal STEXT symbols are emitted by walking textp.
s := Linklookup(ctxt, "runtime.text", 0) s := Linklookup(ctxt, "runtime.text", 0)
if s.Type == obj.STEXT { 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) s = Linklookup(ctxt, "runtime.etext", 0)
if s.Type == obj.STEXT { 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 { 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() { if !s.Attr.Reachable() {
continue 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: case obj.SBSS, obj.SNOPTRBSS:
if !s.Attr.Reachable() { 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 { 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()) 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: 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: case obj.SHOSTOBJ:
if Headtype == obj.Hwindows || Headtype == obj.Hwindowsgui || Iself { 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: case obj.SDYNIMPORT:
if !s.Attr.Reachable() { if !s.Attr.Reachable() {
continue 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: case obj.STLSBSS:
if Linkmode == LinkExternal && Headtype != obj.Hopenbsd { 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 var off int32
for _, s := range ctxt.Textp { 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) locals := int32(0)
if s.FuncInfo != nil { if s.FuncInfo != nil {
locals = s.FuncInfo.Locals locals = s.FuncInfo.Locals
} }
// NOTE(ality): acid can't produce a stack trace without .frame symbols // 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 { if s.FuncInfo == nil {
continue continue
@ -1914,13 +1928,13 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, i
// FP // FP
if off >= 0 { 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 continue
} }
// SP // SP
if off <= int32(-SysArch.PtrSize) { 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 continue
} }
} }

View file

@ -612,7 +612,7 @@ func symkind(s *Symbol) int {
return SymKindLocal 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 { if s == nil {
return return
} }
@ -621,7 +621,7 @@ func addsym(ctxt *Link, s *Symbol, name string, type_ int, addr int64, size int6
default: default:
return return
case 'D', 'B', 'T': case DataSym, BSSSym, TextSym:
break break
} }
@ -656,12 +656,12 @@ func (x machoscmp) Less(i, j int) bool {
return s1.Extname < s2.Extname return s1.Extname < s2.Extname
} }
func machogenasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, int, *Symbol)) { func machogenasmsym(ctxt *Link) {
genasmsym(ctxt, put) genasmsym(ctxt, addsym)
for _, s := range ctxt.Allsym { for _, s := range ctxt.Allsym {
if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ { if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
if s.Attr.Reachable() { 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++ { for i := 0; i < len(dynexp); i++ {
dynexp[i].Attr |= AttrReachable dynexp[i].Attr |= AttrReachable
} }
machogenasmsym(ctxt, addsym) machogenasmsym(ctxt)
sortsym = make([]*Symbol, nsortsym) sortsym = make([]*Symbol, nsortsym)
nsortsym = 0 nsortsym = 0
machogenasmsym(ctxt, addsym) machogenasmsym(ctxt)
sort.Sort(machoscmp(sortsym[:nsortsym])) sort.Sort(machoscmp(sortsym[:nsortsym]))
for i := 0; i < nsortsym; i++ { for i := 0; i < nsortsym; i++ {
sortsym[i].Dynid = int32(i) sortsym[i].Dynid = int32(i)

View file

@ -930,17 +930,17 @@ func newPEDWARFSection(ctxt *Link, name string, size int64) *IMAGE_SECTION_HEADE
func writePESymTableRecords(ctxt *Link) int { func writePESymTableRecords(ctxt *Link) int {
var symcnt 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 { if s == nil {
return return
} }
if s.Sect == nil && type_ != 'U' { if s.Sect == nil && type_ != UndefinedSym {
return return
} }
switch type_ { switch type_ {
default: default:
return return
case 'D', 'B', 'T', 'U': case DataSym, BSSSym, TextSym, UndefinedSym:
} }
// only windows/386 requires underscore prefix on external symbols // 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 { } else if uint64(s.Value) >= Segtext.Vaddr {
value = int64(uint64(s.Value) - Segtext.Vaddr) value = int64(uint64(s.Value) - Segtext.Vaddr)
sect = textsect sect = textsect
} else if type_ == 'U' { } else if type_ == UndefinedSym {
typ = IMAGE_SYM_DTYPE_FUNCTION typ = IMAGE_SYM_DTYPE_FUNCTION
} else { } else {
ctxt.Diag("addpesym %#x", addr) ctxt.Diag("addpesym %#x", addr)
@ -1000,13 +1000,13 @@ func writePESymTableRecords(ctxt *Link) int {
for d := dr; d != nil; d = d.next { for d := dr; d != nil; d = d.next {
for m := d.ms; m != nil; m = m.next { for m := d.ms; m != nil; m = m.next {
s := m.s.R[0].Xsym 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) s := Linklookup(ctxt, ".text", 0)
if s.Type == obj.STEXT { 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)
} }
} }

View file

@ -76,29 +76,26 @@ var numelfsym int = 1 // 0 is reserved
var elfbind int var elfbind int
func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, ver int, go_ *Symbol) { func putelfsym(ctxt *Link, x *Symbol, s string, t SymbolType, addr int64, size int64, ver int, go_ *Symbol) {
var type_ int var typ int
switch t { switch t {
default: default:
return return
case 'T': case TextSym:
type_ = STT_FUNC typ = STT_FUNC
case 'D': case DataSym, BSSSym:
type_ = STT_OBJECT typ = STT_OBJECT
case 'B': case UndefinedSym:
type_ = STT_OBJECT
case 'U':
// ElfType is only set for symbols read from Go shared libraries, but // ElfType is only set for symbols read from Go shared libraries, but
// for other symbols it is left as STT_NOTYPE which is fine. // for other symbols it is left as STT_NOTYPE which is fine.
type_ = int(x.ElfType) typ = int(x.ElfType)
case 't': case TLSSym:
type_ = STT_TLS typ = STT_TLS
} }
xo := x 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 { if x.Type&obj.SHIDDEN != 0 {
other = STV_HIDDEN 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 // On ppc64 the top three bits of the st_other field indicate how
// many instructions separate the global and local entry points. In // many instructions separate the global and local entry points. In
// our case it is two instructions, indicated by the value 3. // 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 // (*Symbol).ElfsymForReloc). This is approximately equivalent to the
// ELF linker -Bsymbolic-functions option, but that is buggy on // ELF linker -Bsymbolic-functions option, but that is buggy on
// several platforms. // 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) x.LocalElfsym = int32(numelfsym)
numelfsym++ numelfsym++
return return
@ -179,7 +176,7 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
return 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) x.Elfsym = int32(numelfsym)
numelfsym++ numelfsym++
} }
@ -211,20 +208,16 @@ func Asmelfsym(ctxt *Link) {
genasmsym(ctxt, putelfsym) genasmsym(ctxt, putelfsym)
} }
func putplan9sym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, ver int, go_ *Symbol) { func putplan9sym(ctxt *Link, x *Symbol, s string, typ SymbolType, addr int64, size int64, ver int, go_ *Symbol) {
switch t { t := int(typ)
case 'T', 'L', 'D', 'B': switch typ {
case TextSym, DataSym, BSSSym:
if ver != 0 { if ver != 0 {
t += 'a' - 'A' t += 'a' - 'A'
} }
fallthrough fallthrough
case 'a', case AutoSym, ParamSym, FileSym, FrameSym:
'p',
'f',
'z',
'Z',
'm':
l := 4 l := 4
if Headtype == obj.Hplan9 && SysArch.Family == sys.AMD64 && !Flag8 { if Headtype == obj.Hplan9 && SysArch.Family == sys.AMD64 && !Flag8 {
Lputb(uint32(addr >> 32)) 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 */ Cput(uint8(t + 0x80)) /* 0x80 is variable length */
var i int 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) /* skip the '<' in filenames */
Cput(0) if t == FileSym {
i++ s = s[1:]
} else {
/* skip the '<' in filenames */
if t == 'f' {
s = s[1:]
}
for i = 0; i < len(s); i++ {
Cput(s[i])
}
Cput(0)
} }
for i = 0; i < len(s); i++ {
Cput(s[i])
}
Cput(0)
Symsize += int32(l) + 1 + int32(i) + 1 Symsize += int32(l) + 1 + int32(i) + 1