From 851b1f40b48c02f6eeee160957c40dbad46df3bc Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 25 Oct 2019 12:39:20 -0400 Subject: [PATCH] [dev.link] cmd/link: add new slice interface for querying aux symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Cherry Zhang --- src/cmd/link/internal/ld/deadcode2.go | 8 +++++--- src/cmd/link/internal/loader/loader.go | 27 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/cmd/link/internal/ld/deadcode2.go b/src/cmd/link/internal/ld/deadcode2.go index 368e151377f..04a2e925c31 100644 --- a/src/cmd/link/internal/ld/deadcode2.go +++ b/src/cmd/link/internal/ld/deadcode2.go @@ -105,6 +105,7 @@ func (d *deadcodePass2) init() { func (d *deadcodePass2) flood() { symRelocs := []loader.Reloc{} + auxSyms := []loader.Sym{} for !d.wq.empty() { symIdx := d.wq.pop() @@ -147,9 +148,10 @@ func (d *deadcodePass2) flood() { } d.mark(r.Sym) } - naux := d.ldr.NAux(symIdx) - for i := 0; i < naux; i++ { - d.mark(d.ldr.AuxSym(symIdx, i)) + + auxSyms = d.ldr.ReadAuxSyms(symIdx, auxSyms) + for i := 0; i < len(auxSyms); i++ { + d.mark(auxSyms[i]) } if len(methods) != 0 { diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 95e3005af2e..42a5aa50a79 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -475,6 +475,33 @@ func (l *Loader) AuxSym(i Sym, j int) 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. func (l *Loader) InitReachable() { l.Reachable = makeBitmap(l.NSym())