Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
Peter Zijlstra <[email protected]> Mon, 3 Aug 2026 10:27:32 +0200
| Newsgroups | dev.linux.lists.llvm,org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Aug 02, 2026 at 10:43:42AM -0700, Fangrui Song wrote:
> Commit ee10b1028129 ("riscv/runtime-const: Replace open-coded
> placeholder with RUNTIME_MAGIC") switched the lui + addi[w] placeholder
> from hand-encoded immediates to %hi()/%lo() of RUNTIME_MAGIC.
>
> GNU Assembler folds %hi()/%lo() of an absolute expression at assembly
> time. LLVM's integrated assembler since 21.1 defers it to the linker
> instead, which range checks it: on riscv64 R_RISCV_HI20 must fit a
> signed 20-bit field, and RUNTIME_MAGIC (0x89ABCDEF) is a positive 64-bit
> value rather than a sign-extended 32-bit one, so it does not:
>
> ld.lld: error: relocation R_RISCV_HI20 out of range: 563901 is not in
> [-524288, 524287]
>
> The sequence is patched at runtime and its instruction offsets are
> recorded via ".long 1b - .", so the linker must not touch it in the
> first place. Add ".option norelax", as is already done for
> ALTERNATIVE() and static keys; the integrated assembler then resolves
> %hi()/%lo() itself and emits no relocation, restoring the exact
> encoding the open-coded placeholder produced.
>
> Fixes: ee10b1028129 ("riscv/runtime-const: Replace open-coded placeholder with RUNTIME_MAGIC")
> Reported-by: Nathan Chancellor <[email protected]>
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2179
> Signed-off-by: Fangrui Song <[email protected]>
> ---
> Applies to tip/locking/core; the RISC-V tree (riscv/linux.git) does not
> carry ee10b1028129.
Thanks, I'll stick this on top.