Commit 851b1f40 authored by Than McIntosh's avatar Than McIntosh

[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/+/203501Reviewed-by: default avatarJeremy Faller <jeremy@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent e90e6e75
......@@ -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 {
......
......@@ -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())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment