Reland [ELF] Split scanRelocations into scanRelocations/postScanRelocations
authorFangrui Song <i@maskray.me>
Tue, 14 Dec 2021 04:11:24 +0000 (20:11 -0800)
committerFangrui Song <i@maskray.me>
Tue, 14 Dec 2021 04:11:24 +0000 (20:11 -0800)
commite7a95b067490dc90faea1baa78a66d08e1b2a7d4
treebfaf76d80f02043775d11f1de22f010ab1dc463c
parentd1014d9e6d98c11356861d69199d7bacab45e609
Reland [ELF] Split scanRelocations into scanRelocations/postScanRelocations

(Fixed an issue about GOT on a copy relocated alias.)

The idea is to make scanRelocations mark some actions are needed (GOT/PLT/etc)
and postpone the real work to postScanRelocations. It gives some flexibility:

* Make it feasible to support .plt.got (PR32938): we need to know whether GLOB_DAT and JUMP_SLOT are both needed.
* Make non-preemptible IFUNC handling slightly cleaner: avoid setting/clearing sym.gotInIgot
* -z nocopyrel: report all copy relocation places for one symbol
* Make GOT deduplication feasible
* Make parallel relocation scanning feasible (if we can avoid all stateful operations and make Symbol attributes atomic), but parallelism may not be the appealing choice

Since this patch moves a large chunk of code out of ELFT templates. My x86-64
executable is actually a few hundred bytes smaller.

For ppc32-ifunc-nonpreemptible-pic.s: I remove absolute relocation references to non-preemptible ifunc
because absolute relocation references are incorrect in -fpie mode.

Reviewed By: peter.smith, ikudrin

Differential Revision: https://reviews.llvm.org/D114783
24 files changed:
lld/ELF/Relocations.cpp
lld/ELF/Relocations.h
lld/ELF/Symbols.h
lld/ELF/Writer.cpp
lld/test/ELF/aarch64-ifunc-bti.s
lld/test/ELF/aarch64-thunk-pi.s
lld/test/ELF/arm-branch-undef-weak-plt-thunk.s
lld/test/ELF/arm-gnu-ifunc.s
lld/test/ELF/arm-thumb-interwork-thunk.s
lld/test/ELF/bsymbolic.s
lld/test/ELF/gnu-ifunc-i386.s
lld/test/ELF/ppc32-canonical-plt.s
lld/test/ELF/ppc32-ifunc-nonpreemptible-pic.s
lld/test/ELF/ppc32-reloc-got.s
lld/test/ELF/ppc64-ifunc.s
lld/test/ELF/relocation-nocopy.s
lld/test/ELF/riscv-reloc-got.s
lld/test/ELF/symver.s
lld/test/ELF/version-script-symver.s
lld/test/ELF/wrap-no-real.s
lld/test/ELF/wrap-plt.s
lld/test/ELF/x86-64-gotpc-relax-und-dso.s
lld/test/ELF/x86-64-plt.s
lld/test/ELF/x86-x32-plt.s