[dev.link] cmd/link: add storage and methods for read/write of Sym value

Add loader methods SymValue() and SetSymValue() to get/set the
value of a symbol by global index.

Change-Id: Ifc71480fc34c719ad00506d0828edf36c1a57119
Reviewed-on: https://go-review.googlesource.com/c/go/+/211302
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Than McIntosh 2019-12-13 11:51:15 -05:00
parent b658c62e9c
commit e6b044b200
2 changed files with 36 additions and 3 deletions

View file

@ -32,7 +32,7 @@ func TestAddMaterializedSymbol(t *testing.T) {
// Create some syms from a dummy object file symbol to get things going.
addDummyObjSym(t, ldr, or, "type.uint8")
addDummyObjSym(t, ldr, or, "mumble")
ts2 := addDummyObjSym(t, ldr, or, "mumble")
addDummyObjSym(t, ldr, or, "type.string")
// Create some external symbols.
@ -96,4 +96,17 @@ func TestAddMaterializedSymbol(t *testing.T) {
if !ldr.AttrVisibilityHidden(es3) {
t.Errorf("expected hidden after update")
}
// Test get/set symbol value.
toTest := []Sym{ts2, es3}
for i, s := range toTest {
if v := ldr.SymValue(s); v != 0 {
t.Errorf("ldr.Value(%d): expected 0 got %d\n", s, v)
}
nv := int64(i + 101)
ldr.SetSymValue(s, nv)
if v := ldr.SymValue(s); v != nv {
t.Errorf("ldr.SetValue(%d,%d): expected %d got %d\n", s, nv, nv, v)
}
}
}