Skip to content

Commit dd9e81f

Browse files
committed
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/125479 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f78cc13 commit dd9e81f

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

src/cmd/link/internal/amd64/asm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
410410
}
411411
case objabi.R_PCREL:
412412
if r.Siz == 4 {
413-
if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC {
413+
if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType() == elf.STT_FUNC {
414414
ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32)
415415
} else {
416416
ctxt.Out.Write64(uint64(elf.R_X86_64_PC32) | uint64(elfsym)<<32)

src/cmd/link/internal/ld/lib.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
17061706
continue
17071707
}
17081708
lsym.Type = sym.SDYNIMPORT
1709-
lsym.ElfType = elf.ST_TYPE(elfsym.Info)
1709+
lsym.SetElfType(elf.ST_TYPE(elfsym.Info))
17101710
lsym.Size = int64(elfsym.Size)
17111711
if elfsym.Section != elf.SHN_UNDEF {
17121712
// Set .File for the library that actually defines the symbol.

src/cmd/link/internal/ld/symtab.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64, go
9393
case UndefinedSym:
9494
// ElfType is only set for symbols read from Go shared libraries, but
9595
// for other symbols it is left as STT_NOTYPE which is fine.
96-
typ = int(x.ElfType)
96+
typ = int(x.ElfType())
9797

9898
case TLSSym:
9999
typ = STT_TLS

src/cmd/link/internal/s390x/asm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool {
285285
case objabi.R_PCRELDBL, objabi.R_CALL:
286286
isdbl = true
287287
}
288-
if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == objabi.R_CALL) {
288+
if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType() == elf.STT_FUNC || r.Type == objabi.R_CALL) {
289289
if isdbl {
290290
switch r.Siz {
291291
case 2:

src/cmd/link/internal/sym/sizeof_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
2323
_32bit uintptr // size on 32bit platforms
2424
_64bit uintptr // size on 64bit platforms
2525
}{
26-
{Symbol{}, 112, 184},
26+
{Symbol{}, 108, 176},
2727
}
2828

2929
for _, tt := range tests {

src/cmd/link/internal/sym/symbol.go

+29-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ type Symbol struct {
2424
LocalElfsym int32
2525
Value int64
2626
Size int64
27-
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It
28-
// is not set for symbols defined by the packages being linked or by symbols
29-
// read by ldelf (and so is left as elf.STT_NOTYPE).
30-
ElfType elf.SymType
31-
Sub *Symbol
32-
Outer *Symbol
33-
Gotype *Symbol
34-
File string
35-
auxinfo *AuxSymbol
36-
Sect *Section
37-
FuncInfo *FuncInfo
38-
Lib *Library // Package defining this symbol
27+
Sub *Symbol
28+
Outer *Symbol
29+
Gotype *Symbol
30+
File string
31+
auxinfo *AuxSymbol
32+
Sect *Section
33+
FuncInfo *FuncInfo
34+
Lib *Library // Package defining this symbol
3935
// P contains the raw symbol data.
4036
P []byte
4137
R []Reloc
@@ -49,6 +45,10 @@ type AuxSymbol struct {
4945
localentry uint8
5046
plt int32
5147
got int32
48+
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It
49+
// is not set for symbols defined by the packages being linked or by symbols
50+
// read by ldelf (and so is left as elf.STT_NOTYPE).
51+
elftype elf.SymType
5252
}
5353

5454
func (s *Symbol) String() string {
@@ -378,6 +378,23 @@ func (s *Symbol) SetGot(val int32) {
378378
s.auxinfo.got = val
379379
}
380380

381+
func (s *Symbol) ElfType() elf.SymType {
382+
if s.auxinfo == nil {
383+
return elf.STT_NOTYPE
384+
}
385+
return s.auxinfo.elftype
386+
}
387+
388+
func (s *Symbol) SetElfType(val elf.SymType) {
389+
if s.auxinfo == nil {
390+
if val == elf.STT_NOTYPE {
391+
return
392+
}
393+
s.makeAuxInfo()
394+
}
395+
s.auxinfo.elftype = val
396+
}
397+
381398
// SortSub sorts a linked-list (by Sub) of *Symbol by Value.
382399
// Used for sub-symbols when loading host objects (see e.g. ldelf.go).
383400
func SortSub(l *Symbol) *Symbol {

0 commit comments

Comments
 (0)