[dev.link] cmd/link: write ELF relocations in mmap on all architectures

In CL 240399 we changed to precompute the size for ELF relocation
records and use mmap to write them, but we left architectures
where elfreloc1 write non-fixed number of bytes. This CL handles
those architectures. When a Go relocation will turn into multiple
ELF relocations, in relocsym we account this difference and add
it to the size calculation. So when emitting ELF relocations, we
know the number of ELF relocations to be emitted.

Change-Id: I6732ab674b442f4618405e5412a77f6e4a3315d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/241079
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-07-04 18:14:08 -04:00
parent 36939aef77
commit 8c46cb1bf5
15 changed files with 122 additions and 100 deletions

View file

@ -206,11 +206,12 @@ type Arch struct {
// containing the chunk of data to which the relocation applies, and "off"
// is the contents of the to-be-relocated data item (from sym.P). Return
// value is the appropriately relocated value (to be written back to the
// same spot in sym.P), a boolean indicating if the external relocations'
// been used, and a boolean indicating success/failure (a failing value
// indicates a fatal error).
// same spot in sym.P), number of external _host_ relocations needed (i.e.
// ELF/Mach-O/etc. relocations, not Go relocations, this must match Elfreloc1,
// etc.), and a boolean indicating success/failure (a failing value indicates
// a fatal error).
Archreloc func(*Target, *loader.Loader, *ArchSyms, loader.Reloc2, *loader.ExtReloc,
loader.Sym, int64) (relocatedOffset int64, needExtReloc bool, ok bool)
loader.Sym, int64) (relocatedOffset int64, nExtReloc int, ok bool)
// Archrelocvariant is a second arch-specific hook used for
// relocation processing; it handles relocations where r.Type is
// insufficient to describe the relocation (r.Variant !=
@ -237,7 +238,7 @@ type Arch struct {
Asmb2 func(*Link, *loader.Loader)
Elfreloc1 func(*Link, *OutBuf, *loader.Loader, loader.Sym, loader.ExtRelocView, int64) bool
ElfrelocSize uint32 // size of an ELF relocation record, must match Elfreloc1. Currently this can be 0, meaning that the size is not fixed (a Go reloc may turn into multiple ELF reloc).
ElfrelocSize uint32 // size of an ELF relocation record, must match Elfreloc1.
Elfsetupplt func(ctxt *Link, plt, gotplt *loader.SymbolBuilder, dynamic loader.Sym)
Gentext func(*Link, *loader.Loader)
Machoreloc1 func(*sys.Arch, *OutBuf, *loader.Loader, loader.Sym, loader.ExtRelocView, int64) bool