[lld] Allow Arm PC-relative relocations in pic or shared library (PR #77304)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 8 09:24:11 PST 2024


https://github.com/smithp35 commented:

The addition of R_PC_A looks good to me.

Please could you add a test?

The tests are in lld/test/ELF . All the arm ones are prefixed with `arm-` and must start with REQUIRES ARM (so that they are skipped if the ARM backend isn't present).

A suitable test that fails currently:
```
psmith at R910YRK0:~/work/llvm-project/build$ cat adr.s
        .text
        .type _start, %function
        .global _start
        .arm
_start: adr r0, .Ldest
        bx lr
        .section .text.1, "ax", %progbits
.Ldest: .word 10
```
using:
```
llvm-mc --triple=armv7-a adr.s -filetype=obj -o adr.o
ld.lld adr.o --shared -o adr.so
ld.lld: error: relocation R_ARM_ALU_PC_G0 cannot be used against symbol '.Ldest'; recompile with -fPIC
>>> defined in adr.o
>>> referenced by adr.o:(.text+0x0)
```
After your change that error should disappear.

Please can you add a description for the commit message too. Something like.
```
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-libries or position-independent executables.
```

https://github.com/llvm/llvm-project/pull/77304


More information about the llvm-commits mailing list