[dev.link] cmd/link: store external relocations in Reloc2 format

Store external relocations in (almost) the same format as the Go
objects, so we can handle them more uniformly.

There is a small speedup:

(linking cmd/compile)
Deadcode        67.8ms ± 3%    61.1ms ± 3%   -9.94%  (p=0.008 n=5+5)
Dostkcheck      41.2ms ± 2%    38.8ms ± 3%   -5.99%  (p=0.008 n=5+5)

Change-Id: I8616e10b26235904201d6c9465f5ae32a49c9949
Reviewed-on: https://go-review.googlesource.com/c/go/+/226365
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Cherry Zhang 2020-03-28 16:46:47 -04:00
parent aef23f5be9
commit 6e3bde5f30
6 changed files with 103 additions and 160 deletions

View file

@ -173,14 +173,9 @@ func TestAddMaterializedSymbol(t *testing.T) {
for k, sb := range []*SymbolBuilder{sb1, sb2} {
rsl := sb.Relocs()
exp := expRel[k]
if !sameRelocSlice(rsl, exp) {
if !sameRelocSlice(&rsl, exp) {
t.Errorf("expected relocs %v, got %v", exp, rsl)
}
relocs := ldr.Relocs(sb.Sym())
r0 := relocs.At(0)
if r0 != exp[0] {
t.Errorf("expected reloc %v, got %v", exp[0], r0)
}
}
// ... then data.
@ -213,12 +208,18 @@ func TestAddMaterializedSymbol(t *testing.T) {
}
}
func sameRelocSlice(s1 []Reloc, s2 []Reloc) bool {
if len(s1) != len(s2) {
func sameRelocSlice(s1 *Relocs, s2 []Reloc) bool {
if s1.Count != len(s2) {
return false
}
for i := 0; i < len(s1); i++ {
if s1[i] != s2[i] {
for i := 0; i < s1.Count; i++ {
r1 := s1.At2(i)
r2 := &s2[i]
if r1.Sym() != r2.Sym ||
r1.Type() != r2.Type ||
r1.Off() != r2.Off ||
r1.Add() != r2.Add ||
r1.Siz() != r2.Size {
return false
}
}
@ -342,10 +343,9 @@ func TestAddDataMethods(t *testing.T) {
t.Fatalf("testing Loader.%s: sym updated should be reachable", tp.which)
}
relocs := ldr.Relocs(mi)
rsl := relocs.ReadAll(nil)
if !sameRelocSlice(rsl, tp.expRel) {
if !sameRelocSlice(&relocs, tp.expRel) {
t.Fatalf("testing Loader.%s: got relocslice %+v wanted %+v",
tp.which, rsl, tp.expRel)
tp.which, relocs, tp.expRel)
}
pmi = mi
}