[lld][RISCV] Implement GP relaxation for R_RISCV_HI20/R_RISCV_LO12_I/R_RISCV_LO12_S.
authorCraig Topper <craig.topper@sifive.com>
Thu, 13 Apr 2023 17:39:47 +0000 (10:39 -0700)
committerCraig Topper <craig.topper@sifive.com>
Thu, 13 Apr 2023 17:52:15 +0000 (10:52 -0700)
commit85444794cdde8211b916767cc51a37547dbd17e9
treea64ff5dc1e7dfb59873ca9fdea9207c8ccf8f3ea
parentb60513e384bf0253464d2ff9070f10b488e3701a
[lld][RISCV] Implement GP relaxation for R_RISCV_HI20/R_RISCV_LO12_I/R_RISCV_LO12_S.

This implements support for relaxing these relocations to use the GP
register to compute addresses of globals in the .sdata and .sbss
sections.

This feature is off by default and must be enabled by passing
--relax-gp to the linker.

The GP register might not always be the "global pointer". It can
be used for other purposes. See discussion here
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/371

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143673
lld/ELF/Arch/RISCV.cpp
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/Writer.cpp
lld/docs/ld.lld.1
lld/test/ELF/riscv-relax-hi20-lo12-pie.s [new file with mode: 0644]
lld/test/ELF/riscv-relax-hi20-lo12.s [new file with mode: 0644]