]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/goobj2, cmd/link: add accessors for field of FuncInfo
authorCherry Zhang <cherryyz@google.com>
Tue, 25 Feb 2020 20:14:31 +0000 (15:14 -0500)
committerCherry Zhang <cherryyz@google.com>
Tue, 25 Feb 2020 20:34:34 +0000 (20:34 +0000)
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>
src/cmd/internal/goobj2/funcinfo.go
src/cmd/link/internal/loader/loader.go

index d8cfd3d02d9dbe7e919a2a1aec78fdca68003728..053d7adc155283b23b38c63ddbb6972d05e9d489 100644 (file)
@@ -100,6 +100,16 @@ func (a *FuncInfo) Read(b []byte) {
        }
 }
 
+// Accessors reading only some fields.
+// TODO: more accessors.
+
+func (*FuncInfo) ReadLocals(b []byte) uint32 { return binary.LittleEndian.Uint32(b[4:]) }
+
+// return start and end offsets.
+func (*FuncInfo) ReadPcsp(b []byte) (uint32, uint32) {
+       return binary.LittleEndian.Uint32(b[8:]), binary.LittleEndian.Uint32(b[12:])
+}
+
 // InlTreeNode is the serialized form of FileInfo.InlTree.
 type InlTreeNode struct {
        Parent   int32
index 1ff123efbb7c7f86d27bc71540d2621ec9d36294..51d210d9f5b9dfa00514e2fea50933fb8b300b01 100644 (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.