Skip to content

Commit

Permalink
cmd/link: move Localentry field in sym.Symbol to cold section
Browse files Browse the repository at this point in the history
The sym.Symbol 'Localentry' field is used only with cgo and/or
external linking on MachoPPC. Relocate it to sym.AuxSymbol since it is
infrequently used, so as to shrink the main Symbol struct.

Updates #26186

Change-Id: I5872aa3f059270c2a091016d235a1a732695e411
Reviewed-on: https://go-review.googlesource.com/125477
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
thanm committed Aug 30, 2018
1 parent 09df9b0 commit 2975914
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cmd/link/internal/loadelf/ldelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i
if elfobj.machine == ElfMachPower64 {
flag := int(elfsym.other) >> 5
if 2 <= flag && flag <= 6 {
s.Localentry = 1 << uint(flag-2)
s.SetLocalentry(1 << uint(flag-2))
} else if flag == 7 {
return errorf("%v: invalid sym.other 0x%x", s, elfsym.other)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ppc64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
// callee. Hence, we need to go to the local entry
// point. (If we don't do this, the callee will try
// to use r12 to compute r2.)
r.Add += int64(r.Sym.Localentry) * 4
r.Add += int64(r.Sym.Localentry()) * 4

if targ.Type == sym.SDYNIMPORT {
// Should have been handled in elfsetupplt
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/sym/sizeof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
_32bit uintptr // size on 32bit platforms
_64bit uintptr // size on 64bit platforms
}{
{Symbol{}, 124, 200},
{Symbol{}, 120, 192},
}

for _, tt := range tests {
Expand Down
19 changes: 18 additions & 1 deletion src/cmd/link/internal/sym/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Symbol struct {
Type SymKind
Version int16
Attr Attribute
Localentry uint8
Dynid int32
Plt int32
Got int32
Expand Down Expand Up @@ -49,6 +48,7 @@ type AuxSymbol struct {
extname string
dynimplib string
dynimpvers string
localentry uint8
}

func (s *Symbol) String() string {
Expand Down Expand Up @@ -327,6 +327,23 @@ func (s *Symbol) ResetDyninfo() {
}
}

func (s *Symbol) Localentry() uint8 {
if s.auxinfo == nil {
return 0
}
return s.auxinfo.localentry
}

func (s *Symbol) SetLocalentry(val uint8) {
if s.auxinfo == nil {
if val != 0 {
return
}
s.makeAuxInfo()
}
s.auxinfo.localentry = val
}

// SortSub sorts a linked-list (by Sub) of *Symbol by Value.
// Used for sub-symbols when loading host objects (see e.g. ldelf.go).
func SortSub(l *Symbol) *Symbol {
Expand Down

0 comments on commit 2975914

Please sign in to comment.