cmd/link: make listsort less generic

It's always called with the same arguments now.

Maybe the real fix is to make Symbol.Sub a slice but that requires a bit more
brain.

Change-Id: I1326d34a0a327554be6d54f9bd402ea328224766
Reviewed-on: https://go-review.googlesource.com/27416
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Michael Hudson-Doyle 2016-08-22 10:53:05 +12:00
parent ec8d49c139
commit 82c1e22e13
4 changed files with 28 additions and 43 deletions

View file

@ -238,46 +238,41 @@ func addaddrplus4(ctxt *Link, s *Symbol, t *Symbol, add int64) int64 {
} }
/* /*
* divide-and-conquer list-link * divide-and-conquer list-link (by Sub) sort of Symbol* by Value.
* sort of Symbol* structures. * Used for sub-symbols when loading host objects (see e.g. ldelf.go).
* Used for the data block.
*/ */
func listsubp(s *Symbol) **Symbol { func listsort(l *Symbol) *Symbol {
return &s.Sub if l == nil || l.Sub == nil {
}
func listsort(l *Symbol, cmp func(*Symbol, *Symbol) int, nextp func(*Symbol) **Symbol) *Symbol {
if l == nil || *nextp(l) == nil {
return l return l
} }
l1 := l l1 := l
l2 := l l2 := l
for { for {
l2 = *nextp(l2) l2 = l2.Sub
if l2 == nil { if l2 == nil {
break break
} }
l2 = *nextp(l2) l2 = l2.Sub
if l2 == nil { if l2 == nil {
break break
} }
l1 = *nextp(l1) l1 = l1.Sub
} }
l2 = *nextp(l1) l2 = l1.Sub
*nextp(l1) = nil l1.Sub = nil
l1 = listsort(l, cmp, nextp) l1 = listsort(l)
l2 = listsort(l2, cmp, nextp) l2 = listsort(l2)
/* set up lead element */ /* set up lead element */
if cmp(l1, l2) < 0 { if l1.Value < l2.Value {
l = l1 l = l1
l1 = *nextp(l1) l1 = l1.Sub
} else { } else {
l = l2 l = l2
l2 = *nextp(l2) l2 = l2.Sub
} }
le := l le := l
@ -285,37 +280,37 @@ func listsort(l *Symbol, cmp func(*Symbol, *Symbol) int, nextp func(*Symbol) **S
for { for {
if l1 == nil { if l1 == nil {
for l2 != nil { for l2 != nil {
*nextp(le) = l2 le.Sub = l2
le = l2 le = l2
l2 = *nextp(l2) l2 = l2.Sub
} }
*nextp(le) = nil le.Sub = nil
break break
} }
if l2 == nil { if l2 == nil {
for l1 != nil { for l1 != nil {
*nextp(le) = l1 le.Sub = l1
le = l1 le = l1
l1 = *nextp(l1) l1 = l1.Sub
} }
break break
} }
if cmp(l1, l2) < 0 { if l1.Value < l2.Value {
*nextp(le) = l1 le.Sub = l1
le = l1 le = l1
l1 = *nextp(l1) l1 = l1.Sub
} else { } else {
*nextp(le) = l2 le.Sub = l2
le = l2 le = l2
l2 = *nextp(l2) l2 = l2.Sub
} }
} }
*nextp(le) = nil le.Sub = nil
return l return l
} }

View file

@ -308,16 +308,6 @@ type ElfSym struct {
var ElfMagic = [4]uint8{0x7F, 'E', 'L', 'F'} var ElfMagic = [4]uint8{0x7F, 'E', 'L', 'F'}
func valuecmp(a *Symbol, b *Symbol) int {
if a.Value < b.Value {
return -1
}
if a.Value > b.Value {
return +1
}
return 0
}
const ( const (
Tag_file = 1 Tag_file = 1
Tag_CPU_name = 4 Tag_CPU_name = 4
@ -835,7 +825,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
continue continue
} }
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp) s.Sub = listsort(s.Sub)
} }
if s.Type == obj.STEXT { if s.Type == obj.STEXT {
if s.Attr.OnList() { if s.Attr.OnList() {

View file

@ -690,7 +690,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
continue continue
} }
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp) s.Sub = listsort(s.Sub)
// assign sizes, now that we know symbols in sorted order. // assign sizes, now that we know symbols in sorted order.
for s1 = s.Sub; s1 != nil; s1 = s1.Sub { for s1 = s.Sub; s1 != nil; s1 = s1.Sub {

View file

@ -428,7 +428,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
continue continue
} }
if s.Sub != nil { if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp) s.Sub = listsort(s.Sub)
} }
if s.Type == obj.STEXT { if s.Type == obj.STEXT {
if s.Attr.OnList() { if s.Attr.OnList() {