1
0
mirror of https://github.com/golang/go synced 2024-11-05 17:26:11 -07:00

[dev.link] cmd/internal/goobj2, cmd/link: avoid some repeated offset calculations

When iterating relocations, do the offset calculation just once.
This gives some speedup:

(linking cmd/compile)
Deadcode      52.8ms ± 1%    47.6ms ± 1%  -10.01%  (p=0.008 n=5+5)
Dostkcheck    44.2ms ± 1%    41.0ms ± 1%   -7.29%  (p=0.008 n=5+5)

Change-Id: I09e38bc29afc379a81f99e3ee4ff467bc1b5f8a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/222302
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-03-11 17:00:08 -04:00
parent 3277db4ccf
commit 8e100a05a5
3 changed files with 21 additions and 5 deletions

View File

@ -595,6 +595,13 @@ func (r *Reader) Reloc2(i int, j int) *Reloc2 {
return (*Reloc2)(unsafe.Pointer(&r.b[off]))
}
// Relocs2 returns a pointer to the relocations of the i-th symbol.
func (r *Reader) Relocs2(i int) []Reloc2 {
off := r.RelocOff(i, 0)
n := r.NReloc(i)
return (*[1 << 20]Reloc2)(unsafe.Pointer(&r.b[off]))[:n:n]
}
// NAux returns the number of aux symbols of the i-th symbol.
func (r *Reader) NAux(i int) int {
auxIdxOff := r.h.Offsets[BlkAuxIdx] + uint32(i*4)

View File

@ -172,8 +172,10 @@ func (d *deadcodePass2) flood() {
// so we make sure we're pulling in all outer symbols, and their sub
// symbols. This is not ideal, and these carrier/section symbols could
// be removed.
d.mark(d.ldr.OuterSym(symIdx), symIdx)
d.mark(d.ldr.SubSym(symIdx), symIdx)
if d.ldr.IsExternal(symIdx) {
d.mark(d.ldr.OuterSym(symIdx), symIdx)
d.mark(d.ldr.SubSym(symIdx), symIdx)
}
if len(methods) != 0 {
if !isgotype {

View File

@ -31,7 +31,9 @@ type Sym int
// Relocs encapsulates the set of relocations on a given symbol; an
// instance of this type is returned by the Loader Relocs() method.
type Relocs struct {
Count int // number of relocs
Count int // == len(rs), TODO: remove
rs []goobj2.Reloc2
li int // local index of symbol whose relocs we're examining
r *oReader // object reader for containing package
@ -1469,11 +1471,13 @@ func (relocs *Relocs) At2(j int) Reloc2 {
// XXX populate a goobj2.Reloc from external reloc record.
// Ugly. Maybe we just want to use this format to store the
// reloc record in the first place?
// Also there is more speedup if we could remove the
// conditional here.
var b goobj2.Reloc2
b.Set(r.Off, r.Size, 0, r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)})
return Reloc2{&b, relocs.r, relocs.l, r.Type}
}
return Reloc2{relocs.r.Reloc2(relocs.li, j), relocs.r, relocs.l, 0}
return Reloc2{&relocs.rs[j], relocs.r, relocs.l, 0}
}
// ReadAll method reads all relocations for a symbol into the
@ -1539,14 +1543,17 @@ func (l *Loader) Relocs(i Sym) Relocs {
// Relocs returns a Relocs object given a local sym index and reader.
func (l *Loader) relocs(r *oReader, li int) Relocs {
var n int
var rs []goobj2.Reloc2
if l.isExtReader(r) {
pp := l.payloads[li]
n = len(pp.relocs)
} else {
n = r.NReloc(li)
rs = r.Relocs2(li)
n = len(rs)
}
return Relocs{
Count: n,
rs: rs,
li: li,
r: r,
l: l,