[lld] [lld] Properly diagnose R_AARCH64_PREL32 overflow (PR #205963)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 27 14:32:09 PDT 2026


MaskRay wrote:

A single 32-bit `s+a` relocation covers two legimitate cases:

- unsigned use: `.long sym`, 0 to `2**32-1`
- signed use: `.long sym - 0x1000` with `sym < 0x1000`.

so many arches define their 32-bit `s+a` relocation types to have the union range `[-2**(n-1), 2**n)`.
x86-64 additionally provides `R_X86_64_32S` for the `int32_t` use.

`S-A+P` relocation types (PC-relative) don't need the union range: the value is a displacement, only ever consumed as signed.
I think every other 64-bit port checks PC-relative 32-bit as signed.

GNU ld's aarch64 port already uses `[-2**(n-1), 2**(n-1))`:
```
% ~/dev/binutils-gdb/out/aarch64/ld/ld-new a.o --defsym foo=2157483905
a.o:(.data+0x0): relocation truncated to fit: r_aarch64_prel32 against symbol `foo' defined in *abs* section in a.out
```

If the ABI maintainer makes `r_aarch64_prel32` stricter, then this lld change is fine.


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


More information about the llvm-commits mailing list