aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/loader/loader.go
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2020-03-06 01:15:07 -0500
committerCherry Zhang <cherryyz@google.com>2020-03-16 17:33:43 +0000
commit8a074fa275261a3dd1690f81e4fa6c45bdbb0471 (patch)
treed97d31b8473df5b991ba28450e8885e098c0a598 /src/cmd/link/internal/loader/loader.go
parent8e100a05a5d72c2f2b079d8791edf700c612e45e (diff)
downloadgo-8a074fa275261a3dd1690f81e4fa6c45bdbb0471.tar.xz
[dev.link] cmd/internal/goobj2, cmd/link: experiment new aux symbol accessors
Following the previous CLs, do the same for aux symbols. This has some small speedup: (linking cmd/compile) Dostkcheck 41.0ms ± 1% 38.6ms ± 1% -6.00% (p=0.008 n=5+5) Change-Id: Id62b2fc9e4ef1be92e60e4c03faec0a953eee94e Reviewed-on: https://go-review.googlesource.com/c/go/+/222303 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
-rw-r--r--src/cmd/link/internal/loader/loader.go44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 93cfd44b8f..a3028fcc86 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -69,6 +69,16 @@ type Reloc2 struct {
func (rel Reloc2) Type() objabi.RelocType { return objabi.RelocType(rel.Reloc2.Type()) + rel.typ }
func (rel Reloc2) Sym() Sym { return rel.l.resolve(rel.r, rel.Reloc2.Sym()) }
+// Aux2 holds a "handle" to access an aux symbol record from an
+// object file.
+type Aux2 struct {
+ *goobj2.Aux2
+ r *oReader
+ l *Loader
+}
+
+func (a Aux2) Sym() Sym { return a.l.resolve(a.r, a.Aux2.Sym()) }
+
// oReader is a wrapper type of obj.Reader, along with some
// extra information.
// TODO: rename to objReader once the old one is gone?
@@ -1164,13 +1174,12 @@ func (l *Loader) SymGoType(i Sym) Sym {
return pp.gotype
}
r, li := l.toLocal(i)
- naux := r.NAux(li)
- for j := 0; j < naux; j++ {
- a := goobj2.Aux{}
- a.Read(r.Reader, r.AuxOff(li, j))
- switch a.Type {
+ auxs := r.Auxs2(li)
+ for j := range auxs {
+ a := &auxs[j]
+ switch a.Type() {
case goobj2.AuxGotype:
- return l.resolve(r, a.Sym)
+ return l.resolve(r, a.Sym())
}
}
return 0
@@ -1266,6 +1275,18 @@ func (l *Loader) AuxSym(i Sym, j int) Sym {
return l.resolve(r, a.Sym)
}
+// Returns the "handle" to the j-th aux symbol of the i-th symbol.
+func (l *Loader) Aux2(i Sym, j int) Aux2 {
+ if l.IsExternal(i) {
+ return Aux2{}
+ }
+ r, li := l.toLocal(i)
+ if j >= r.NAux(li) {
+ return Aux2{}
+ }
+ return Aux2{r.Aux2(li, j), r, l}
+}
+
// GetFuncDwarfAuxSyms collects and returns the auxiliary DWARF
// symbols associated with a given function symbol. Prior to the
// introduction of the loader, this was done purely using name
@@ -1593,12 +1614,11 @@ func (l *Loader) FuncInfo(i Sym) FuncInfo {
return FuncInfo{}
}
r, li := l.toLocal(i)
- n := r.NAux(li)
- for j := 0; j < n; j++ {
- a := goobj2.Aux{}
- a.Read(r.Reader, r.AuxOff(li, j))
- if a.Type == goobj2.AuxFuncInfo {
- b := r.Data(int(a.Sym.SymIdx))
+ auxs := r.Auxs2(li)
+ for j := range auxs {
+ a := &auxs[j]
+ if a.Type() == goobj2.AuxFuncInfo {
+ b := r.Data(int(a.Sym().SymIdx))
return FuncInfo{l, r, b}
}
}