[dev.link] cmd/link: support marking outer/sub for external loader.Sym

Add a loader mechanism for recording outer/sub relationships between
symbols without falling back on sym.Symbol. Also includes a new
"PrependSub" method that provides a way to chain a sub-symbol only the
list of an outer symbol (a common operation when manipulating
outer/sub relationships in the linker).

Change-Id: I70c72356945ceec2bacdcdc25bcc352bfb6765a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/210777
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-11 14:17:14 -05:00
parent e6b044b200
commit 66c74b78ca
2 changed files with 120 additions and 2 deletions

View file

@ -110,3 +110,56 @@ func TestAddMaterializedSymbol(t *testing.T) {
}
}
}
func TestOuterSub(t *testing.T) {
ldr := NewLoader(0)
dummyOreader := oReader{version: -1}
or := &dummyOreader
// Populate loader with some symbols.
addDummyObjSym(t, ldr, or, "type.uint8")
es1 := ldr.AddExtSym("outer", 0)
es2 := ldr.AddExtSym("sub1", 0)
es3 := ldr.AddExtSym("sub2", 0)
// Should not have an outer sym initially
if ldr.OuterSym(es1) != 0 {
t.Errorf("es1 outer sym set ")
}
if ldr.SubSym(es2) != 0 {
t.Errorf("es2 outer sym set ")
}
// Establish first outer/sub relationship
ldr.PrependSub(es1, es2)
if ldr.OuterSym(es1) != 0 {
t.Errorf("ldr.OuterSym(es1) got %d wanted %d", ldr.OuterSym(es1), 0)
}
if ldr.OuterSym(es2) != es1 {
t.Errorf("ldr.OuterSym(es2) got %d wanted %d", ldr.OuterSym(es2), es1)
}
if ldr.SubSym(es1) != es2 {
t.Errorf("ldr.SubSym(es1) got %d wanted %d", ldr.SubSym(es1), es2)
}
if ldr.SubSym(es2) != 0 {
t.Errorf("ldr.SubSym(es2) got %d wanted %d", ldr.SubSym(es2), 0)
}
// Establish second outer/sub relationship
ldr.PrependSub(es1, es3)
if ldr.OuterSym(es1) != 0 {
t.Errorf("ldr.OuterSym(es1) got %d wanted %d", ldr.OuterSym(es1), 0)
}
if ldr.OuterSym(es2) != es1 {
t.Errorf("ldr.OuterSym(es2) got %d wanted %d", ldr.OuterSym(es2), es1)
}
if ldr.OuterSym(es3) != es1 {
t.Errorf("ldr.OuterSym(es3) got %d wanted %d", ldr.OuterSym(es3), es1)
}
if ldr.SubSym(es1) != es3 {
t.Errorf("ldr.SubSym(es1) got %d wanted %d", ldr.SubSym(es1), es3)
}
if ldr.SubSym(es3) != es2 {
t.Errorf("ldr.SubSym(es3) got %d wanted %d", ldr.SubSym(es3), es2)
}
}