From: Peter Zijlstra <peterz@infradead.org>
To: Fangrui Song <i@maskray.me>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>,
Guo Ren <guoren@kernel.org>, Palmer Dabbelt <palmer@dabbelt.com>,
Charlie Jenkins <thecharlesjenkins@gmail.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
Date: Mon, 3 Aug 2026 10:27:32 +0200 [thread overview]
Message-ID: <20260803082732.GZ49951@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260802174342.597092-1-i@maskray.me>
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 <nathan@kernel.org>
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2179
> Signed-off-by: Fangrui Song <i@maskray.me>
> ---
> Applies to tip/locking/core; the RISC-V tree (riscv/linux.git) does not
> carry ee10b1028129.
Thanks, I'll stick this on top.
next prev parent reply other threads:[~2026-08-03 8:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 17:43 [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC Fangrui Song
2026-08-03 8:27 ` Peter Zijlstra [this message]
2026-08-03 16:12 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260803082732.GZ49951@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=guoren@kernel.org \
--cc=i@maskray.me \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=palmer@dabbelt.com \
--cc=thecharlesjenkins@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox