Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax GOT indirection into PC-relative addressing
Some psABIs define the linker optimizations to relax a GOT load into a PC-relative address materialization. AArch64 [1] allows the linker to rewrite ADRP+ADD into ADR. x86-64 does the same thing with the `R_X86_64_GOTPCRELX` and `R_X86_64_REX_GOTPCRELX` relocations. In our case, we have lots of AUIPC+LD instruction pairs to load an address from the GOT in our RISC-V programs because `la` assembly pseudo instruction is expanded to that instruction pair. If the PC-relative address loaded by the instruction pair is a link-time constant, we can rewrite the instructions with AUIPC+ADDI to directly materialize the value into a register, which eliminates one memory load. We can't rewrite existing AUIPC+ADDI instruction pairs unconditionally because technically there may exist code that jumps to the middle of the instruction pair. That should be extremely rare, but we can't deny the possibility. Therefore, `R_RISCV_GOT_HI20` is required to be annotated with `R_RISCV_RELAX` in this proposal. Currently, neither gas nor LLVM assembler emit `R_RISCV_RELAX` for `R_RISCV_GOT_HI20`. I have a WIP patch to emit `R_RISCV_RELAX` only for the `la` pseudo instruction. [1] https://github.com/ARM-software/abi-aa/blob/844a79fd4c77252a11342709e3b27b2c9f590cf1/aaelf64/aaelf64.rst#relocation-optimization
- Loading branch information