1
0
mirror of https://github.com/golang/go synced 2024-11-23 16:00:06 -07:00

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

View File

@ -308,16 +308,6 @@ type ElfSym struct {
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 (
Tag_file = 1
Tag_CPU_name = 4
@ -835,7 +825,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
continue
}
if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp)
s.Sub = listsort(s.Sub)
}
if s.Type == obj.STEXT {
if s.Attr.OnList() {

View File

@ -690,7 +690,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
continue
}
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.
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
}
if s.Sub != nil {
s.Sub = listsort(s.Sub, valuecmp, listsubp)
s.Sub = listsort(s.Sub)
}
if s.Type == obj.STEXT {
if s.Attr.OnList() {