mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: use new-style relocation accessors in LoadFull
This gives some small speedup: (linking cmd/compile) Loadlibfull 77.8ms ± 6% 68.6ms ± 5% -11.88% (p=0.008 n=5+5) Also convert some Relocs.At to At2, which should have been done earlier. Change-Id: I2a66aeb5857234c6e645e1b23380149cffc8221f Reviewed-on: https://go-review.googlesource.com/c/go/+/226363 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
3e6ff18247
commit
f095b570fe
3 changed files with 17 additions and 20 deletions
|
|
@ -272,7 +272,7 @@ func deadcode2(ctxt *Link) {
|
||||||
s := loader.Sym(i)
|
s := loader.Sym(i)
|
||||||
if ldr.IsItabLink(s) {
|
if ldr.IsItabLink(s) {
|
||||||
relocs := ldr.Relocs(s)
|
relocs := ldr.Relocs(s)
|
||||||
if relocs.Count > 0 && ldr.AttrReachable(relocs.At(0).Sym) {
|
if relocs.Count > 0 && ldr.AttrReachable(relocs.At2(0).Sym()) {
|
||||||
ldr.SetAttrReachable(s, true)
|
ldr.SetAttrReachable(s, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1480,9 +1480,9 @@ func addpersrc(ctxt *Link) {
|
||||||
// relocation
|
// relocation
|
||||||
relocs := ctxt.loader.Relocs(rsrcsym)
|
relocs := ctxt.loader.Relocs(rsrcsym)
|
||||||
for i := 0; i < relocs.Count; i++ {
|
for i := 0; i < relocs.Count; i++ {
|
||||||
r := relocs.At(i)
|
r := relocs.At2(i)
|
||||||
p := data[r.Off:]
|
p := data[r.Off():]
|
||||||
val := uint32(int64(h.virtualAddress) + r.Add)
|
val := uint32(int64(h.virtualAddress) + r.Add())
|
||||||
|
|
||||||
// 32-bit little-endian
|
// 32-bit little-endian
|
||||||
p[0] = byte(val)
|
p[0] = byte(val)
|
||||||
|
|
|
||||||
|
|
@ -1865,7 +1865,8 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols) {
|
||||||
batch := l.relocBatch
|
batch := l.relocBatch
|
||||||
s.R = batch[:len(pp.relocs):len(pp.relocs)]
|
s.R = batch[:len(pp.relocs):len(pp.relocs)]
|
||||||
l.relocBatch = batch[len(pp.relocs):]
|
l.relocBatch = batch[len(pp.relocs):]
|
||||||
l.convertRelocations(pp.relocs, s, false)
|
relocs := l.Relocs(i)
|
||||||
|
l.convertRelocations(&relocs, s, false)
|
||||||
|
|
||||||
// Copy data
|
// Copy data
|
||||||
s.P = pp.data
|
s.P = pp.data
|
||||||
|
|
@ -1977,7 +1978,6 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, anonVerReplace
|
||||||
// sym.Symbols are created.
|
// sym.Symbols are created.
|
||||||
|
|
||||||
// First pass, symbol creation and symbol data fixup.
|
// First pass, symbol creation and symbol data fixup.
|
||||||
rslice := []Reloc{}
|
|
||||||
for _, cand := range toconvert {
|
for _, cand := range toconvert {
|
||||||
|
|
||||||
sn := l.SymName(cand)
|
sn := l.SymName(cand)
|
||||||
|
|
@ -2063,11 +2063,10 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, anonVerReplace
|
||||||
for _, cand := range relocfixup {
|
for _, cand := range relocfixup {
|
||||||
s := l.Syms[cand]
|
s := l.Syms[cand]
|
||||||
relocs := l.Relocs(cand)
|
relocs := l.Relocs(cand)
|
||||||
rslice = relocs.ReadAll(rslice)
|
if len(s.R) != relocs.Count {
|
||||||
if len(s.R) != len(rslice) {
|
s.R = make([]sym.Reloc, relocs.Count)
|
||||||
s.R = make([]sym.Reloc, len(rslice))
|
|
||||||
}
|
}
|
||||||
l.convertRelocations(rslice, s, true)
|
l.convertRelocations(&relocs, s, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
@ -2426,7 +2425,6 @@ func loadObjFull(l *Loader, r *oReader) {
|
||||||
fdsyms := []*sym.Symbol{}
|
fdsyms := []*sym.Symbol{}
|
||||||
var funcAllocCounts funcAllocInfo
|
var funcAllocCounts funcAllocInfo
|
||||||
pcdataBase := r.PcdataBase()
|
pcdataBase := r.PcdataBase()
|
||||||
rslice := []Reloc{}
|
|
||||||
for i, n := 0, r.NSym()+r.NNonpkgdef(); i < n; i++ {
|
for i, n := 0, r.NSym()+r.NNonpkgdef(); i < n; i++ {
|
||||||
// A symbol may be a dup or overwritten. In this case, its
|
// A symbol may be a dup or overwritten. In this case, its
|
||||||
// content will actually be provided by a different object
|
// content will actually be provided by a different object
|
||||||
|
|
@ -2471,11 +2469,10 @@ func loadObjFull(l *Loader, r *oReader) {
|
||||||
|
|
||||||
// Relocs
|
// Relocs
|
||||||
relocs := l.relocs(r, i)
|
relocs := l.relocs(r, i)
|
||||||
rslice = relocs.ReadAll(rslice)
|
|
||||||
batch := l.relocBatch
|
batch := l.relocBatch
|
||||||
s.R = batch[:relocs.Count:relocs.Count]
|
s.R = batch[:relocs.Count:relocs.Count]
|
||||||
l.relocBatch = batch[relocs.Count:]
|
l.relocBatch = batch[relocs.Count:]
|
||||||
l.convertRelocations(rslice, s, false)
|
l.convertRelocations(&relocs, s, false)
|
||||||
|
|
||||||
// Aux symbol info
|
// Aux symbol info
|
||||||
isym := -1
|
isym := -1
|
||||||
|
|
@ -2645,12 +2642,12 @@ func loadObjFull(l *Loader, r *oReader) {
|
||||||
// etc. It is assumed that the caller has pre-allocated the dst symbol
|
// etc. It is assumed that the caller has pre-allocated the dst symbol
|
||||||
// relocations slice. If 'strict' is set, then this method will
|
// relocations slice. If 'strict' is set, then this method will
|
||||||
// panic if it finds a relocation targeting a nil symbol.
|
// panic if it finds a relocation targeting a nil symbol.
|
||||||
func (l *Loader) convertRelocations(src []Reloc, dst *sym.Symbol, strict bool) {
|
func (l *Loader) convertRelocations(src *Relocs, dst *sym.Symbol, strict bool) {
|
||||||
for j := range dst.R {
|
for j := range dst.R {
|
||||||
r := src[j]
|
r := src.At2(j)
|
||||||
rs := r.Sym
|
rs := r.Sym()
|
||||||
sz := r.Size
|
sz := r.Siz()
|
||||||
rt := r.Type
|
rt := r.Type()
|
||||||
if rt == objabi.R_METHODOFF {
|
if rt == objabi.R_METHODOFF {
|
||||||
if l.attrReachable.Has(rs) {
|
if l.attrReachable.Has(rs) {
|
||||||
rt = objabi.R_ADDROFF
|
rt = objabi.R_ADDROFF
|
||||||
|
|
@ -2671,10 +2668,10 @@ func (l *Loader) convertRelocations(src []Reloc, dst *sym.Symbol, strict bool) {
|
||||||
panic("nil reloc target in convertRelocations")
|
panic("nil reloc target in convertRelocations")
|
||||||
}
|
}
|
||||||
dst.R[j] = sym.Reloc{
|
dst.R[j] = sym.Reloc{
|
||||||
Off: r.Off,
|
Off: r.Off(),
|
||||||
Siz: sz,
|
Siz: sz,
|
||||||
Type: rt,
|
Type: rt,
|
||||||
Add: r.Add,
|
Add: r.Add(),
|
||||||
Sym: l.Syms[rs],
|
Sym: l.Syms[rs],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue