]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: add new slice interface for querying aux symbols
authorThan McIntosh <thanm@google.com>
Fri, 25 Oct 2019 16:39:20 +0000 (12:39 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 31 Oct 2019 01:09:14 +0000 (01:09 +0000)
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>
src/cmd/link/internal/ld/deadcode2.go
src/cmd/link/internal/loader/loader.go

index 368e151377f84fd2df038055302bfa57fb00d31b..04a2e925c31b961e6f60b67f26c30978fd77579b 100644 (file)
@@ -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 {
index 95e3005af2ec8f15a657e02f415b0d32539e0a09..42a5aa50a793aab47f966ba3e98a8e5a51e34005 100644 (file)
@@ -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())