diff options
| author | Cherry Zhang <cherryyz@google.com> | 2020-03-05 16:43:37 -0500 |
|---|---|---|
| committer | Cherry Zhang <cherryyz@google.com> | 2020-03-13 01:19:15 +0000 |
| commit | cf5c718cbaa479da9257fa8f16bb081dfc89fd6b (patch) | |
| tree | f538d9caabf93bfdcf2d829a877c5b2d7dc718e0 /src/cmd/link/internal/loader/loader.go | |
| parent | c951514da987b0e4ed629962ed773c6cb47d96f9 (diff) | |
| download | go-cf5c718cbaa479da9257fa8f16bb081dfc89fd6b.tar.xz | |
[dev.link] cmd/link: experiment new reloc accessors in deadcode pass
There is a small speedup:
(linking cmd/compile)
name old time/op new time/op delta
Deadcode 57.1ms ± 1% 53.5ms ± 1% -6.44% (p=0.008 n=5+5)
With this, we don't need a slice to read the relocations, reduce
some allocations.
name old alloc/op new alloc/op delta
Deadcode 4.16MB ± 0% 3.84MB ± 0% -7.85% (p=0.008 n=5+5)
Change-Id: Icd41c05682ba3f293a8cb9d2fe818e39d7276e5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/222244
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/cmd/link/internal/loader/loader.go')
| -rw-r--r-- | src/cmd/link/internal/loader/loader.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 979d94402e..102fee5a41 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -520,6 +520,12 @@ func (l *Loader) resolve(r *oReader, s goobj2.SymRef) Sym { var rr *oReader switch p := s.PkgIdx; p { case goobj2.PkgIdxInvalid: + // {0, X} with non-zero X is never a valid sym reference from a Go object. + // We steal this space for symbol references from external objects. + // In this case, X is just the global index. + if l.isExtReader(r) { + return Sym(s.SymIdx) + } if s.SymIdx != 0 { panic("bad sym ref") } @@ -1448,10 +1454,14 @@ func (relocs *Relocs) At(j int) Reloc { func (relocs *Relocs) At2(j int) Reloc2 { if relocs.l.isExtReader(relocs.r) { - // TODO: implement this. How? Maybe we can construct the reloc - // data for external symbols in the same byte form as the one - // in the object file? - panic("not implemented") + pp := relocs.l.payloads[relocs.li] + r := pp.relocs[j] + // XXX populate a goobj2.Reloc from external reloc record. + // Ugly. Maybe we just want to use this format to store the + // reloc record in the first place? + var b goobj2.Reloc2 + b.Set(r.Off, r.Size, uint8(r.Type), r.Add, goobj2.SymRef{PkgIdx: 0, SymIdx: uint32(r.Sym)}) + return Reloc2{&b, relocs.r, relocs.l} } return Reloc2{relocs.r.Reloc2(relocs.li, j), relocs.r, relocs.l} } |
