Skip to content

Commit d21fb06

Browse files
authored
[lld][ELF] Allow Arm PC-relative relocations in PIC links (#77304)
The relocations that map to R_ARM_PCA are equivalent to R_PC. They are PC-relative and safe to use in shared libraries, but have a different relocation code as they are evaluated differently. Now that LLVM may generate these relocations in object files, they may occur in shared libraries or position-independent executables.
1 parent 3b3da7c commit d21fb06

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lld/ELF/Relocations.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ bool lld::elf::needsGot(RelExpr expr) {
210210
// True if this expression is of the form Sym - X, where X is a position in the
211211
// file (PC, or GOT for example).
212212
static bool isRelExpr(RelExpr expr) {
213-
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,
214-
R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC,
215-
R_RISCV_PC_INDIRECT, R_PPC64_RELAX_GOT_PC, R_LOONGARCH_PAGE_PC>(
216-
expr);
213+
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_ARM_PCA, R_MIPS_GOTREL,
214+
R_PPC64_CALL, R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC,
215+
R_RELAX_GOT_PC, R_RISCV_PC_INDIRECT, R_PPC64_RELAX_GOT_PC,
216+
R_LOONGARCH_PAGE_PC>(expr);
217217
}
218218

219219
static RelExpr toPlt(RelExpr expr) {

lld/test/ELF/arm-adr.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// REQUIRES: arm
22
// RUN: llvm-mc --triple=armv7a-none-eabi --arm-add-build-attributes -filetype=obj -o %t.o %s
33
// RUN: ld.lld %t.o -o %t
4+
/// R_ARM_ALU_PC_G0 referencing a non-preemptible symbol can be used in PIC links.
5+
// RUN: ld.lld %t.o --shared -o /dev/null
46
// RUN: llvm-objdump -d --no-show-raw-insn --triple=armv7a-none-eabi %t | FileCheck %s
57

68
/// Test the short range cases of R_ARM_ALU_PC_G0. The range of the instruction

0 commit comments

Comments
 (0)