mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: store external relocations in Reloc2 format
Store external relocations in (almost) the same format as the Go objects, so we can handle them more uniformly. There is a small speedup: (linking cmd/compile) Deadcode 67.8ms ± 3% 61.1ms ± 3% -9.94% (p=0.008 n=5+5) Dostkcheck 41.2ms ± 2% 38.8ms ± 3% -5.99% (p=0.008 n=5+5) Change-Id: I8616e10b26235904201d6c9465f5ae32a49c9949 Reviewed-on: https://go-review.googlesource.com/c/go/+/226365 Run-TryBot: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
aef23f5be9
commit
6e3bde5f30
6 changed files with 103 additions and 160 deletions
|
|
@ -5,6 +5,7 @@
|
|||
package loader
|
||||
|
||||
import (
|
||||
"cmd/internal/goobj2"
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/sys"
|
||||
"cmd/link/internal/sym"
|
||||
|
|
@ -121,23 +122,37 @@ func (sb *SymbolBuilder) AddBytes(data []byte) {
|
|||
sb.size = int64(len(sb.data))
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) Relocs() []Reloc {
|
||||
return sb.relocs
|
||||
func (sb *SymbolBuilder) Relocs() Relocs {
|
||||
return sb.l.Relocs(sb.symIdx)
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) SetRelocs(rslice []Reloc) {
|
||||
sb.relocs = rslice
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) WriteRelocs(rslice []Reloc) {
|
||||
if len(sb.relocs) != len(rslice) {
|
||||
panic("src/dest length mismatch")
|
||||
n := len(rslice)
|
||||
if cap(sb.relocs) < n {
|
||||
sb.relocs = make([]goobj2.Reloc2, n)
|
||||
sb.reltypes = make([]objabi.RelocType, n)
|
||||
} else {
|
||||
sb.relocs = sb.relocs[:n]
|
||||
sb.reltypes = sb.reltypes[:n]
|
||||
}
|
||||
for i := range rslice {
|
||||
sb.SetReloc(i, rslice[i])
|
||||
}
|
||||
copy(sb.relocs, rslice)
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) AddReloc(r Reloc) {
|
||||
sb.relocs = append(sb.relocs, r)
|
||||
// Populate a goobj2.Reloc from external reloc record.
|
||||
var b goobj2.Reloc2
|
||||
b.Set(r.Off, r.Size, 0, r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)})
|
||||
sb.relocs = append(sb.relocs, b)
|
||||
sb.reltypes = append(sb.reltypes, r.Type)
|
||||
}
|
||||
|
||||
// Update the j-th relocation in place.
|
||||
func (sb *SymbolBuilder) SetReloc(j int, r Reloc) {
|
||||
// Populate a goobj2.Reloc from external reloc record.
|
||||
sb.relocs[j].Set(r.Off, r.Size, 0, r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)})
|
||||
sb.reltypes[j] = r.Type
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) Reachable() bool {
|
||||
|
|
@ -277,11 +292,6 @@ func (sb *SymbolBuilder) Addstring(str string) int64 {
|
|||
return r
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) addRel() *Reloc {
|
||||
sb.relocs = append(sb.relocs, Reloc{})
|
||||
return &sb.relocs[len(sb.relocs)-1]
|
||||
}
|
||||
|
||||
func (sb *SymbolBuilder) addSymRef(tgt Sym, add int64, typ objabi.RelocType, rsize int) int64 {
|
||||
if sb.kind == 0 {
|
||||
sb.kind = sym.SDATA
|
||||
|
|
@ -291,12 +301,13 @@ func (sb *SymbolBuilder) addSymRef(tgt Sym, add int64, typ objabi.RelocType, rsi
|
|||
sb.size += int64(rsize)
|
||||
sb.Grow(sb.size)
|
||||
|
||||
r := sb.addRel()
|
||||
var r Reloc
|
||||
r.Sym = tgt
|
||||
r.Off = int32(i)
|
||||
r.Size = uint8(rsize)
|
||||
r.Type = typ
|
||||
r.Add = add
|
||||
sb.AddReloc(r)
|
||||
|
||||
return i + int64(r.Size)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue