[dev.link] cmd/internal/goobj2, cmd/link: add accessors for field of FuncInfo

Add accessors for fields of FuncInfo, so we don't have to read
the whole FuncInfo.

TODO: explore/experiment with an alternative idea -- splitting
FuncInfo to separate Aux symbols.

Change-Id: Ie4bc2613fd76d08fc63fd86956802920da63dd2f
Reviewed-on: https://go-review.googlesource.com/c/go/+/220979
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-02-25 15:14:31 -05:00
parent 90799be8ac
commit e00da38b81
2 changed files with 47 additions and 0 deletions

View file

@ -1527,6 +1527,43 @@ func (x RelocByOff) Len() int { return len(x) }
func (x RelocByOff) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x RelocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off }
// FuncInfo provides hooks to access goobj2.FuncInfo in the objects.
type FuncInfo struct {
l *Loader
r *oReader
data []byte
}
func (fi *FuncInfo) Valid() bool { return fi.r != nil }
func (fi *FuncInfo) Locals() int {
return int((*goobj2.FuncInfo)(nil).ReadLocals(fi.data))
}
func (fi *FuncInfo) Pcsp() []byte {
pcsp, end := (*goobj2.FuncInfo)(nil).ReadPcsp(fi.data)
return fi.r.BytesAt(fi.r.PcdataBase()+pcsp, int(end-pcsp))
}
// TODO: more accessors.
func (l *Loader) FuncInfo(i Sym) FuncInfo {
if l.IsExternal(i) {
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))
return FuncInfo{l, r, b}
}
}
return FuncInfo{}
}
// Preload a package: add autolibs, add defined package symbols to the symbol table.
// Does not add non-package symbols yet, which will be done in LoadNonpkgSyms.
// Does not read symbol data.