]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: add loader methods to access unit, gotype
authorThan McIntosh <thanm@google.com>
Wed, 8 Jan 2020 17:57:41 +0000 (12:57 -0500)
committerThan McIntosh <thanm@google.com>
Fri, 10 Jan 2020 12:37:31 +0000 (12:37 +0000)
Add loader hooks to get at the 'gotype' and 'unit' symbol properties.

Change-Id: Icdf5dd151e84a548fa2574efdb998c3b698a17d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/214137
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/loader/loader.go

index d6edffc3dd719ac8e5a19ab2e666155c9186ecb2..f7bbd7a38fda109b222c599778661417f552b079 100644 (file)
@@ -1201,6 +1201,51 @@ func (l *Loader) SetSymElfType(i Sym, et elf.SymType) {
        }
 }
 
+// SymGoType returns the 'Gotype' property for a given symbol (set by
+// the Go compiler for variable symbols). This version relies on
+// reading aux symbols for the target sym -- it could be that a faster
+// approach would be to check for gotype during preload and copy the
+// results in to a map (might want to try this at some point and see
+// if it helps speed things up).
+func (l *Loader) SymGoType(i Sym) Sym {
+       if l.IsExternal(i) {
+               if l.Syms[i] != nil {
+                       panic("gotype already converted to sym.Symbol")
+               }
+               pp := l.getPayload(i)
+               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 {
+               case goobj2.AuxGotype:
+                       return l.resolve(r, a.Sym)
+               }
+       }
+       return 0
+}
+
+// SymUnit returns the compilation unit for a given symbol (which will
+// typically be nil for external or linker-manufactured symbols).
+func (l *Loader) SymUnit(i Sym) *sym.CompilationUnit {
+       if l.IsExternal(i) {
+               if l.Syms[i] != nil {
+                       return l.Syms[i].Unit
+               }
+               pp := l.getPayload(i)
+               if pp.objidx != 0 {
+                       r := l.objs[pp.objidx].r
+                       return r.unit
+               }
+               return nil
+       }
+       r, _ := l.toLocal(i)
+       return r.unit
+}
+
 // SymFile returns the file for a symbol, which is normally the
 // package the symbol came from (for regular compiler-generated Go
 // symbols), but in the case of building with "-linkshared" (when a