mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/goobj: store relocation type as uint16
Currently, relocation type is stored as uint8 in object files, as
Go relocations do not exceed 255. In the linker, however, it is
used as a 16-bit type, because external relocations can exceed
255. The linker has to store the extra byte in a side table. This
complicates many things.
Just store it as uint16 in object files. This simplifies things,
with a small cost of increasing the object file sizes.
before after
hello.o 1672 1678
runtime.a 7927784 8056194
Change-Id: I313cf44ad0b8b3b76e35055ae55d911ff35e3158
Reviewed-on: https://go-review.googlesource.com/c/go/+/268477
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
87d29939c8
commit
f901ea701d
6 changed files with 40 additions and 64 deletions
|
|
@ -121,13 +121,11 @@ func (sb *SymbolBuilder) Relocs() Relocs {
|
|||
// ResetRelocs removes all relocations on this symbol.
|
||||
func (sb *SymbolBuilder) ResetRelocs() {
|
||||
sb.relocs = sb.relocs[:0]
|
||||
sb.reltypes = sb.reltypes[:0]
|
||||
}
|
||||
|
||||
// SetRelocType sets the type of the 'i'-th relocation on this sym to 't'
|
||||
func (sb *SymbolBuilder) SetRelocType(i int, t objabi.RelocType) {
|
||||
sb.relocs[i].SetType(0)
|
||||
sb.reltypes[i] = t
|
||||
sb.relocs[i].SetType(uint16(t))
|
||||
}
|
||||
|
||||
// SetRelocSym sets the target sym of the 'i'-th relocation on this sym to 's'
|
||||
|
|
@ -143,7 +141,6 @@ func (sb *SymbolBuilder) SetRelocAdd(i int, a int64) {
|
|||
// Add n relocations, return a handle to the relocations.
|
||||
func (sb *SymbolBuilder) AddRelocs(n int) Relocs {
|
||||
sb.relocs = append(sb.relocs, make([]goobj.Reloc, n)...)
|
||||
sb.reltypes = append(sb.reltypes, make([]objabi.RelocType, n)...)
|
||||
return sb.l.Relocs(sb.symIdx)
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +149,7 @@ func (sb *SymbolBuilder) AddRelocs(n int) Relocs {
|
|||
func (sb *SymbolBuilder) AddRel(typ objabi.RelocType) (Reloc, int) {
|
||||
j := len(sb.relocs)
|
||||
sb.relocs = append(sb.relocs, goobj.Reloc{})
|
||||
sb.reltypes = append(sb.reltypes, typ)
|
||||
sb.relocs[j].SetType(uint16(typ))
|
||||
relocs := sb.Relocs()
|
||||
return relocs.At(j), j
|
||||
}
|
||||
|
|
@ -169,7 +166,6 @@ func (p *relocsByOff) Len() int { return len(p.relocs) }
|
|||
func (p *relocsByOff) Less(i, j int) bool { return p.relocs[i].Off() < p.relocs[j].Off() }
|
||||
func (p *relocsByOff) Swap(i, j int) {
|
||||
p.relocs[i], p.relocs[j] = p.relocs[j], p.relocs[i]
|
||||
p.reltypes[i], p.reltypes[j] = p.reltypes[j], p.reltypes[i]
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) Reachable() bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue