[dev.link] cmd/link: remove elf sym fields from sym.Symbol

Remove the "ElfSym" and "LocalElfSym" fields from sym.Symbol,
replacing uses with loader method calls as needed.

Change-Id: I3828f13203ece2bdc03eeb09ab37a5c94e21a726
Reviewed-on: https://go-review.googlesource.com/c/go/+/230462
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2020-04-28 10:51:40 -04:00
parent 3f408fc7fd
commit 0722a49b37
13 changed files with 38 additions and 38 deletions

View file

@ -396,7 +396,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write64(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -252,7 +252,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write32(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -328,7 +328,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write64(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -1411,7 +1411,8 @@ func elfrelocsect(ctxt *Link, sect *sym.Section, syms []*sym.Symbol) {
Errorf(s, "missing xsym in relocation %#v %#v", r.Sym.Name, s)
continue
}
if r.Xsym.ElfsymForReloc() == 0 {
esr := ElfSymForReloc(ctxt, r.Xsym)
if esr == 0 {
Errorf(s, "reloc %d (%s) to non-elf symbol %s (outer=%s) %d (%s)", r.Type, sym.RelocName(ctxt.Arch, r.Type), r.Sym.Name, r.Xsym.Name, r.Sym.Type, r.Sym.Type)
}
if !r.Xsym.Attr.Reachable() {

View file

@ -2918,6 +2918,17 @@ func symPkg(ctxt *Link, s *sym.Symbol) string {
return ctxt.loader.SymPkg(loader.Sym(s.SymIdx))
}
func ElfSymForReloc(ctxt *Link, s *sym.Symbol) int32 {
// If putelfsym created a local version of this symbol, use that in all
// relocations.
les := ctxt.loader.SymLocalElfSym(loader.Sym(s.SymIdx))
if les != 0 {
return les
} else {
return ctxt.loader.SymElfSym(loader.Sym(s.SymIdx))
}
}
func (ctxt *Link) dumpsyms() {
for _, s := range ctxt.loader.Syms {
if s == nil {

View file

@ -185,7 +185,7 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64) {
// ELF linker -Bsymbolic-functions option, but that is buggy on
// several platforms.
putelfsyment(ctxt.Out, putelfstr("local."+s), addr, size, STB_LOCAL<<4|typ&0xf, elfshnum, other)
x.LocalElfsym = int32(ctxt.numelfsym)
ctxt.loader.SetSymLocalElfSym(loader.Sym(x.SymIdx), int32(ctxt.numelfsym))
ctxt.numelfsym++
return
} else if bind != ctxt.elfbind {
@ -193,13 +193,13 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64) {
}
putelfsyment(ctxt.Out, putelfstr(s), addr, size, bind<<4|typ&0xf, elfshnum, other)
x.Elfsym = int32(ctxt.numelfsym)
ctxt.loader.SetSymElfSym(loader.Sym(x.SymIdx), int32(ctxt.numelfsym))
ctxt.numelfsym++
}
func putelfsectionsym(ctxt *Link, out *OutBuf, s *sym.Symbol, shndx int) {
putelfsyment(out, 0, 0, 0, STB_LOCAL<<4|STT_SECTION, shndx, 0)
s.Elfsym = int32(ctxt.numelfsym)
ctxt.loader.SetSymElfSym(loader.Sym(s.SymIdx), int32(ctxt.numelfsym))
ctxt.numelfsym++
}

View file

@ -54,7 +54,7 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s *sym.
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write32(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -61,7 +61,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write64(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
ctxt.Out.Write32(uint32(elfsym))
ctxt.Out.Write8(0)
ctxt.Out.Write8(0)

View file

@ -453,7 +453,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
}
ctxt.Out.Write64(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -224,7 +224,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write64(uint64(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false

View file

@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
_32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms
}{
{Symbol{}, 92, 144},
{Symbol{}, 84, 136},
}
for _, tt := range tests {

View file

@ -15,21 +15,19 @@ import (
// Symbol is an entry in the symbol table.
type Symbol struct {
Name string
Type SymKind
Version int16
Attr Attribute
Dynid int32
Align int32
Elfsym int32
LocalElfsym int32
Value int64
Size int64
Sub *Symbol
Outer *Symbol
SymIdx LoaderSym
auxinfo *AuxSymbol
Sect *Section
Name string
Type SymKind
Version int16
Attr Attribute
Dynid int32
Align int32
Value int64
Size int64
Sub *Symbol
Outer *Symbol
SymIdx LoaderSym
auxinfo *AuxSymbol
Sect *Section
// P contains the raw symbol data.
P []byte
R []Reloc
@ -86,16 +84,6 @@ func (s *Symbol) IsFileLocal() bool {
return s.Version >= SymVerStatic
}
func (s *Symbol) ElfsymForReloc() int32 {
// If putelfsym created a local version of this symbol, use that in all
// relocations.
if s.LocalElfsym != 0 {
return s.LocalElfsym
} else {
return s.Elfsym
}
}
func (s *Symbol) Len() int64 {
return s.Size
}

View file

@ -343,7 +343,7 @@ func adddynrel2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s load
func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
ctxt.Out.Write32(uint32(sectoff))
elfsym := r.Xsym.ElfsymForReloc()
elfsym := ld.ElfSymForReloc(ctxt, r.Xsym)
switch r.Type {
default:
return false