[PATCH] D80496: [ELF] Add -z rel and -z rela

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 13:52:00 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, mcgrathr, psmith, ruiu.
Herald added subscribers: llvm-commits, s.egerton, simoncook, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

LLD supports both REL and RELA for static relocations, but emits either
of REL and RELA for dynamic relocations. The relocation entry format is
specified by each psABI.

musl ld.so supports both REL and RELA. For such ld.so implementations,
REL (.rel.dyn .rel.plt) has size benefits even if the psABI chooses RELA:
sizeof(Elf64_Rel)=16 < sizeof(Elf64_Rela)=24.

- COPY, GLOB_DAT and J[U]MP_SLOT always have 0 addend. A ld.so implementation does not need to read the implicit addend. REL is strictly better.
- A RELATIVE has a non-zero addend. Such relocations can be packed compactly with the RELR relocation entry format, which is out of scope of this patch.
- For other dynamic relocation types (e.g. symbolic relocation R_X86_64_64), a ld.so implementation needs to read the implicit addend. REL may have minor performance impact, because reading implicit addends forces random access reads instead of being able to blast out a bunch of writes while chasing the relocation array.

This patch adds -z rel and -z rela to change the relocation entry format
for dynamic relocations. I have tested that a -z rel produced x86-64
executable works with musl ld.so


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80496

Files:
  lld/ELF/Driver.cpp
  lld/docs/ld.lld.1
  lld/test/ELF/i386-zrela.s
  lld/test/ELF/x86-64-zrel.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80496.265940.patch
Type: text/x-patch
Size: 7033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200524/2933dba7/attachment-0001.bin>


More information about the llvm-commits mailing list