mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: sort relocs by off when printing
This makes the output of compiling with -S more stable in the face of unimportant variation in the order in which relocs are generated. It is also more pleasant to read the relocs when they are sorted. Also, do some minor cleanup. For #14786 Change-Id: Id92020b13fd21777dfb5b29c2722c3b2eb27001b Reviewed-on: https://go-review.googlesource.com/20641 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
a2a48069fe
commit
af1c29c1c1
1 changed files with 11 additions and 5 deletions
|
|
@ -104,6 +104,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -417,11 +418,9 @@ func writesym(ctxt *Link, b *Biobuf, s *LSym) {
|
||||||
i += 16
|
i += 16
|
||||||
}
|
}
|
||||||
|
|
||||||
var r *Reloc
|
sort.Sort(relocByOff(s.R)) // generate stable output
|
||||||
var name string
|
for _, r := range s.R {
|
||||||
for i := 0; i < len(s.R); i++ {
|
name := ""
|
||||||
r = &s.R[i]
|
|
||||||
name = ""
|
|
||||||
if r.Sym != nil {
|
if r.Sym != nil {
|
||||||
name = r.Sym.Name
|
name = r.Sym.Name
|
||||||
}
|
}
|
||||||
|
|
@ -562,3 +561,10 @@ func wrsym(b *Biobuf, s *LSym) {
|
||||||
wrstring(b, s.Name)
|
wrstring(b, s.Name)
|
||||||
wrint(b, int64(s.Version))
|
wrint(b, int64(s.Version))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// relocByOff sorts relocations by their offsets.
|
||||||
|
type relocByOff []Reloc
|
||||||
|
|
||||||
|
func (x relocByOff) Len() int { return len(x) }
|
||||||
|
func (x relocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off }
|
||||||
|
func (x relocByOff) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue