]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: add loader.Loader apis for symbol dynamic id
authorThan McIntosh <thanm@google.com>
Wed, 18 Mar 2020 18:32:17 +0000 (14:32 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 23 Mar 2020 15:10:20 +0000 (15:10 +0000)
Add SymDynid and SetSymDynid methods to the loader. This symbol
property is currently backed by a map.

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

index a916c50f19ddb4bbd97328ea227e64f952cbfe15..13c4e5843c2e25cd2db215a79d0403f96c18dced 100644 (file)
@@ -240,6 +240,7 @@ type Loader struct {
        symFile    map[Sym]string      // stores file for shlib-derived syms
        plt        map[Sym]int32       // stores dynimport for pe objects
        got        map[Sym]int32       // stores got for pe objects
+       dynid      map[Sym]int32       // stores Dynid for symbol
 
        // Used to implement field tracking; created during deadcode if
        // field tracking is enabled. Reachparent[K] contains the index of
@@ -302,6 +303,7 @@ func NewLoader(flags uint32, elfsetstring elfsetstringFunc) *Loader {
                symFile:              make(map[Sym]string),
                plt:                  make(map[Sym]int32),
                got:                  make(map[Sym]int32),
+               dynid:                make(map[Sym]int32),
                attrTopFrame:         make(map[Sym]struct{}),
                attrSpecial:          make(map[Sym]struct{}),
                attrCgoExportDynamic: make(map[Sym]struct{}),
@@ -1127,7 +1129,7 @@ func (l *Loader) SetPlt(i Sym, v int32) {
 // SetGot sets the got value for pe symbols.
 func (l *Loader) SetGot(i Sym, v int32) {
        if i >= Sym(len(l.objSyms)) || i == 0 {
-               panic("bad symbol for SetPlt")
+               panic("bad symbol for SetGot")
        }
        if v == 0 {
                delete(l.got, i)
@@ -1136,6 +1138,27 @@ func (l *Loader) SetGot(i Sym, v int32) {
        }
 }
 
+// SymDynid returns the "dynid" property for the specified symbol.
+func (l *Loader) SymDynid(i Sym) int32 {
+       if s, ok := l.dynid[i]; ok {
+               return s
+       }
+       return -1
+}
+
+// SetSymDynid sets the "dynid" property for a symbol.
+func (l *Loader) SetSymDynid(i Sym, val int32) {
+       // reject bad symbols
+       if i >= Sym(len(l.objSyms)) || i == 0 {
+               panic("bad symbol index in SetSymDynid")
+       }
+       if val == -1 {
+               delete(l.dynid, i)
+       } else {
+               l.dynid[i] = val
+       }
+}
+
 // 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