Commit dd9e81f6 authored by Than McIntosh's avatar Than McIntosh

cmd/link: move ElfType field in sym.Symbol to cold section

The sym.Symbol 'ElfType' field is used only for symbols corresponding
to things in imported shared libraries, hence is not needed in the
common case. Relocate it to sym.AuxSymbol so as to shrink the main
Symbol struct.

Updates #26186

Change-Id: I803efc561c31a0ca1d93eca434fda1c862a7b2c5
Reviewed-on: https://go-review.googlesource.com/125479Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent f78cc132
...@@ -410,7 +410,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { ...@@ -410,7 +410,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
} }
case objabi.R_PCREL: case objabi.R_PCREL:
if r.Siz == 4 { if r.Siz == 4 {
if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC { if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType() == elf.STT_FUNC {
ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32) ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32)
} else { } else {
ctxt.Out.Write64(uint64(elf.R_X86_64_PC32) | uint64(elfsym)<<32) ctxt.Out.Write64(uint64(elf.R_X86_64_PC32) | uint64(elfsym)<<32)
......
...@@ -1706,7 +1706,7 @@ func ldshlibsyms(ctxt *Link, shlib string) { ...@@ -1706,7 +1706,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
continue continue
} }
lsym.Type = sym.SDYNIMPORT lsym.Type = sym.SDYNIMPORT
lsym.ElfType = elf.ST_TYPE(elfsym.Info) lsym.SetElfType(elf.ST_TYPE(elfsym.Info))
lsym.Size = int64(elfsym.Size) lsym.Size = int64(elfsym.Size)
if elfsym.Section != elf.SHN_UNDEF { if elfsym.Section != elf.SHN_UNDEF {
// Set .File for the library that actually defines the symbol. // Set .File for the library that actually defines the symbol.
......
...@@ -93,7 +93,7 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64, go ...@@ -93,7 +93,7 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64, go
case UndefinedSym: case UndefinedSym:
// 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.
typ = int(x.ElfType) typ = int(x.ElfType())
case TLSSym: case TLSSym:
typ = STT_TLS typ = STT_TLS
......
...@@ -285,7 +285,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { ...@@ -285,7 +285,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
case objabi.R_PCRELDBL, objabi.R_CALL: case objabi.R_PCRELDBL, objabi.R_CALL:
isdbl = true isdbl = true
} }
if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == objabi.R_CALL) { if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType() == elf.STT_FUNC || r.Type == objabi.R_CALL) {
if isdbl { if isdbl {
switch r.Siz { switch r.Siz {
case 2: case 2:
......
...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
_32bit uintptr // size on 32bit platforms _32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms _64bit uintptr // size on 64bit platforms
}{ }{
{Symbol{}, 112, 184}, {Symbol{}, 108, 176},
} }
for _, tt := range tests { for _, tt := range tests {
......
...@@ -24,18 +24,14 @@ type Symbol struct { ...@@ -24,18 +24,14 @@ type Symbol struct {
LocalElfsym int32 LocalElfsym int32
Value int64 Value int64
Size int64 Size int64
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It Sub *Symbol
// is not set for symbols defined by the packages being linked or by symbols Outer *Symbol
// read by ldelf (and so is left as elf.STT_NOTYPE). Gotype *Symbol
ElfType elf.SymType File string
Sub *Symbol auxinfo *AuxSymbol
Outer *Symbol Sect *Section
Gotype *Symbol FuncInfo *FuncInfo
File string Lib *Library // Package defining this symbol
auxinfo *AuxSymbol
Sect *Section
FuncInfo *FuncInfo
Lib *Library // Package defining this symbol
// P contains the raw symbol data. // P contains the raw symbol data.
P []byte P []byte
R []Reloc R []Reloc
...@@ -49,6 +45,10 @@ type AuxSymbol struct { ...@@ -49,6 +45,10 @@ type AuxSymbol struct {
localentry uint8 localentry uint8
plt int32 plt int32
got int32 got int32
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It
// is not set for symbols defined by the packages being linked or by symbols
// read by ldelf (and so is left as elf.STT_NOTYPE).
elftype elf.SymType
} }
func (s *Symbol) String() string { func (s *Symbol) String() string {
...@@ -378,6 +378,23 @@ func (s *Symbol) SetGot(val int32) { ...@@ -378,6 +378,23 @@ func (s *Symbol) SetGot(val int32) {
s.auxinfo.got = val s.auxinfo.got = val
} }
func (s *Symbol) ElfType() elf.SymType {
if s.auxinfo == nil {
return elf.STT_NOTYPE
}
return s.auxinfo.elftype
}
func (s *Symbol) SetElfType(val elf.SymType) {
if s.auxinfo == nil {
if val == elf.STT_NOTYPE {
return
}
s.makeAuxInfo()
}
s.auxinfo.elftype = val
}
// SortSub sorts a linked-list (by Sub) of *Symbol by Value. // SortSub sorts a linked-list (by Sub) of *Symbol by Value.
// Used for sub-symbols when loading host objects (see e.g. ldelf.go). // Used for sub-symbols when loading host objects (see e.g. ldelf.go).
func SortSub(l *Symbol) *Symbol { func SortSub(l *Symbol) *Symbol {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment