[ELF][RISCV] Support PLT, GOT, copy and relative relocations
authorFangrui Song <maskray@google.com>
Mon, 1 Jul 2019 17:12:18 +0000 (17:12 +0000)
committerFangrui Song <maskray@google.com>
Mon, 1 Jul 2019 17:12:18 +0000 (17:12 +0000)
commitf01fa40a00614fb2ca0282644375849e0aa650ce
tree5e47d290098a3ca2c6eabc7945a4968bfbdd547e
parent1094e6a81430e76f0a6b836f52fa6e21726f5e6d
[ELF][RISCV] Support PLT, GOT, copy and relative relocations

* Handle initial relocation types: R_RISCV_CALL_PLT and R_RISCV_GOT_HI20.
* Produce dynamic relocation types: R_RISCV_COPY, R_RISCV_RELATIVE, R_RISCV_JUMP_SLOT.
* Define SymbolRel as R_RISCV_{32,64}
* Generate PLT header: it is used by lazy binding PLT in glibc.
* R_RISCV_CALL is changed from R_PC to R_PC_PLT. If the target symbol is preemptable, this will suppress an unnecessary "canonical PLT".
  This behavior is different from ld.bfd but it is agreed the current lld behavior is favored.
  I have received positive responses from the binutils maintainer that the ABI/binutils implementation can be improved, see:
  https://github.com/riscv/riscv-elf-psabi-doc/issues/98
  https://sourceware.org/bugzilla/show_bug.cgi?id=24685

Many -no-pie/-pie/-shared programs linked against musl or glibc should work with this patch.

Reviewed By: jrtc27

Differential Revision: https://reviews.llvm.org/D63076

llvm-svn: 364812
lld/ELF/Arch/RISCV.cpp
lld/ELF/InputSection.cpp
lld/test/ELF/riscv-plt.s [new file with mode: 0644]
lld/test/ELF/riscv-reloc-64-pic.s [new file with mode: 0644]
lld/test/ELF/riscv-reloc-copy.s [new file with mode: 0644]
lld/test/ELF/riscv-reloc-got.s [new file with mode: 0644]
lld/test/ELF/riscv32-reloc-32-pic.s [new file with mode: 0644]
lld/test/ELF/riscv64-reloc-64-pic.s [new file with mode: 0644]