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

[dev.link] cmd/link: add new slice interface for querying aux symbols

Add a new loader.Loader.ReadAuxSyms method that returns a slice
containing the ids of the aux symbols for a specified global symbol.
This is similar to the new interface recently added that allows you to
get back a slice of relocations (as opposed to making calls into the
loader for each one). This was idea suggested by Cherry. Compilebench
numbers:

name                      old time/op       new time/op       delta
LinkCompiler                    1.63s ± 9%        1.57s ± 7%  -3.84%  (p=0.006 n=20+20)
LinkWithoutDebugCompiler        1.15s ±11%        1.11s ±11%    ~     (p=0.108 n=20+20)

name                      old user-time/op  new user-time/op  delta
LinkCompiler                    1.99s ± 8%        2.00s ±12%    ~     (p=0.751 n=19+19)
LinkWithoutDebugCompiler        1.14s ±11%        1.19s ±21%    ~     (p=0.183 n=20+20)

Change-Id: Iab6cbe18419aaa61d9cadb3f626a4515c71f2686
Reviewed-on: https://go-review.googlesource.com/c/go/+/203501
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2019-10-25 12:39:20 -04:00
parent e90e6e75f8
commit 851b1f40b4
2 changed files with 32 additions and 3 deletions

View File

@ -105,6 +105,7 @@ func (d *deadcodePass2) init() {
func (d *deadcodePass2) flood() { func (d *deadcodePass2) flood() {
symRelocs := []loader.Reloc{} symRelocs := []loader.Reloc{}
auxSyms := []loader.Sym{}
for !d.wq.empty() { for !d.wq.empty() {
symIdx := d.wq.pop() symIdx := d.wq.pop()
@ -147,9 +148,10 @@ func (d *deadcodePass2) flood() {
} }
d.mark(r.Sym) d.mark(r.Sym)
} }
naux := d.ldr.NAux(symIdx)
for i := 0; i < naux; i++ { auxSyms = d.ldr.ReadAuxSyms(symIdx, auxSyms)
d.mark(d.ldr.AuxSym(symIdx, i)) for i := 0; i < len(auxSyms); i++ {
d.mark(auxSyms[i])
} }
if len(methods) != 0 { if len(methods) != 0 {

View File

@ -475,6 +475,33 @@ func (l *Loader) AuxSym(i Sym, j int) Sym {
return l.resolve(r, a.Sym) return l.resolve(r, a.Sym)
} }
// ReadAuxSyms reads the aux symbol ids for the specified symbol into the
// slice passed as a parameter. If the slice capacity is not large enough, a new
// larger slice will be allocated. Final slice is returned.
func (l *Loader) ReadAuxSyms(symIdx Sym, dst []Sym) []Sym {
if l.isExternal(symIdx) {
return dst[:0]
}
naux := l.NAux(symIdx)
if naux == 0 {
return dst[:0]
}
if cap(dst) < naux {
dst = make([]Sym, naux)
}
dst = dst[:0]
r, li := l.toLocal(symIdx)
for i := 0; i < naux; i++ {
a := goobj2.Aux{}
a.Read(r.Reader, r.AuxOff(li, i))
dst = append(dst, l.resolve(r, a.Sym))
}
return dst
}
// Initialize Reachable bitmap for running deadcode pass. // Initialize Reachable bitmap for running deadcode pass.
func (l *Loader) InitReachable() { func (l *Loader) InitReachable() {
l.Reachable = makeBitmap(l.NSym()) l.Reachable = makeBitmap(l.NSym())