mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: add loader method to sort sub-symbols of outer symbol
Add a new loader method SymSortSub that sorts the sub-symbols of a given outer symbol (designed to be compatible with the existing sym.Symbol method). Change-Id: Icd6627b2e6d04524d657e712cfd39fda0e0e080b Reviewed-on: https://go-review.googlesource.com/c/go/+/211297 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>
This commit is contained in:
parent
66c74b78ca
commit
3c3ba97ba5
2 changed files with 76 additions and 0 deletions
|
|
@ -121,6 +121,9 @@ func TestOuterSub(t *testing.T) {
|
|||
es1 := ldr.AddExtSym("outer", 0)
|
||||
es2 := ldr.AddExtSym("sub1", 0)
|
||||
es3 := ldr.AddExtSym("sub2", 0)
|
||||
es4 := ldr.AddExtSym("sub3", 0)
|
||||
es5 := ldr.AddExtSym("sub4", 0)
|
||||
es6 := ldr.AddExtSym("sub5", 0)
|
||||
|
||||
// Should not have an outer sym initially
|
||||
if ldr.OuterSym(es1) != 0 {
|
||||
|
|
@ -162,4 +165,36 @@ func TestOuterSub(t *testing.T) {
|
|||
if ldr.SubSym(es3) != es2 {
|
||||
t.Errorf("ldr.SubSym(es3) got %d wanted %d", ldr.SubSym(es3), es2)
|
||||
}
|
||||
|
||||
// Some more
|
||||
ldr.PrependSub(es1, es4)
|
||||
ldr.PrependSub(es1, es5)
|
||||
ldr.PrependSub(es1, es6)
|
||||
|
||||
// Set values.
|
||||
ldr.SetSymValue(es2, 7)
|
||||
ldr.SetSymValue(es3, 1)
|
||||
ldr.SetSymValue(es4, 13)
|
||||
ldr.SetSymValue(es5, 101)
|
||||
ldr.SetSymValue(es6, 3)
|
||||
|
||||
// Sort
|
||||
news := ldr.SortSub(es1)
|
||||
if news != es3 {
|
||||
t.Errorf("ldr.SortSub leader got %d wanted %d", news, es3)
|
||||
}
|
||||
pv := int64(-1)
|
||||
count := 0
|
||||
for ss := ldr.SubSym(es1); ss != 0; ss = ldr.SubSym(ss) {
|
||||
v := ldr.SymValue(ss)
|
||||
if v <= pv {
|
||||
t.Errorf("ldr.SortSub sortfail at %d: val %d >= prev val %d",
|
||||
ss, v, pv)
|
||||
}
|
||||
pv = v
|
||||
count++
|
||||
}
|
||||
if count != 5 {
|
||||
t.Errorf("expected %d in sub list got %d", 5, count)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue