* [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
@ 2026-08-02 17:43 ` Fangrui Song
0 siblings, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2026-08-02 17:43 UTC (permalink / raw)
To: Peter Zijlstra
Cc: K Prateek Nayak, Guo Ren, Palmer Dabbelt, Charlie Jenkins,
linux-riscv, linux-kernel, llvm, Fangrui Song, Nathan Chancellor
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.
arch/riscv/include/asm/runtime-const.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
index a472ebbf0971..ce2008bb5227 100644
--- a/arch/riscv/include/asm/runtime-const.h
+++ b/arch/riscv/include/asm/runtime-const.h
@@ -23,6 +23,7 @@
typeof(sym) __ret; \
asm_inline(".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"addi %[__ret],%[__ret], %%lo(" RUNTIME_MAGIC ")\n\t" \
@@ -47,6 +48,7 @@
#define RISCV_RUNTIME_CONST_64_PREAMBLE \
".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"lui %[__tmp], %%hi(" RUNTIME_MAGIC ")\n\t" \
base-commit: 5e601ab3615c86be7c4068ce992f94654693a032
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
@ 2026-08-02 17:43 ` Fangrui Song
0 siblings, 0 replies; 7+ messages in thread
From: Fangrui Song @ 2026-08-02 17:43 UTC (permalink / raw)
To: Peter Zijlstra
Cc: K Prateek Nayak, Guo Ren, Palmer Dabbelt, Charlie Jenkins,
linux-riscv, linux-kernel, llvm, Fangrui Song, Nathan Chancellor
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.
arch/riscv/include/asm/runtime-const.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
index a472ebbf0971..ce2008bb5227 100644
--- a/arch/riscv/include/asm/runtime-const.h
+++ b/arch/riscv/include/asm/runtime-const.h
@@ -23,6 +23,7 @@
typeof(sym) __ret; \
asm_inline(".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"addi %[__ret],%[__ret], %%lo(" RUNTIME_MAGIC ")\n\t" \
@@ -47,6 +48,7 @@
#define RISCV_RUNTIME_CONST_64_PREAMBLE \
".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"lui %[__tmp], %%hi(" RUNTIME_MAGIC ")\n\t" \
base-commit: 5e601ab3615c86be7c4068ce992f94654693a032
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
2026-08-02 17:43 ` Fangrui Song
@ 2026-08-03 8:27 ` Peter Zijlstra
-1 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2026-08-03 8:27 UTC (permalink / raw)
To: Fangrui Song
Cc: K Prateek Nayak, Guo Ren, Palmer Dabbelt, Charlie Jenkins,
linux-riscv, linux-kernel, llvm, Nathan Chancellor
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
@ 2026-08-03 8:27 ` Peter Zijlstra
0 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2026-08-03 8:27 UTC (permalink / raw)
To: Fangrui Song
Cc: K Prateek Nayak, Guo Ren, Palmer Dabbelt, Charlie Jenkins,
linux-riscv, linux-kernel, llvm, Nathan Chancellor
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.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
2026-08-02 17:43 ` Fangrui Song
@ 2026-08-03 16:12 ` Nathan Chancellor
-1 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2026-08-03 16:12 UTC (permalink / raw)
To: Fangrui Song
Cc: Peter Zijlstra, K Prateek Nayak, Guo Ren, Palmer Dabbelt,
Charlie Jenkins, linux-riscv, linux-kernel, llvm
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>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Thanks a lot for the quick fix!
> ---
> Applies to tip/locking/core; the RISC-V tree (riscv/linux.git) does not
> carry ee10b1028129.
>
> arch/riscv/include/asm/runtime-const.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
> index a472ebbf0971..ce2008bb5227 100644
> --- a/arch/riscv/include/asm/runtime-const.h
> +++ b/arch/riscv/include/asm/runtime-const.h
> @@ -23,6 +23,7 @@
> typeof(sym) __ret; \
> asm_inline(".option push\n\t" \
> ".option norvc\n\t" \
> + ".option norelax\n\t" \
> "1:\t" \
> "lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
> "addi %[__ret],%[__ret], %%lo(" RUNTIME_MAGIC ")\n\t" \
> @@ -47,6 +48,7 @@
> #define RISCV_RUNTIME_CONST_64_PREAMBLE \
> ".option push\n\t" \
> ".option norvc\n\t" \
> + ".option norelax\n\t" \
> "1:\t" \
> "lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
> "lui %[__tmp], %%hi(" RUNTIME_MAGIC ")\n\t" \
>
> base-commit: 5e601ab3615c86be7c4068ce992f94654693a032
> --
> 2.43.0
>
>
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
@ 2026-08-03 16:12 ` Nathan Chancellor
0 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2026-08-03 16:12 UTC (permalink / raw)
To: Fangrui Song
Cc: Peter Zijlstra, K Prateek Nayak, Guo Ren, Palmer Dabbelt,
Charlie Jenkins, linux-riscv, linux-kernel, llvm
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>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Thanks a lot for the quick fix!
> ---
> Applies to tip/locking/core; the RISC-V tree (riscv/linux.git) does not
> carry ee10b1028129.
>
> arch/riscv/include/asm/runtime-const.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
> index a472ebbf0971..ce2008bb5227 100644
> --- a/arch/riscv/include/asm/runtime-const.h
> +++ b/arch/riscv/include/asm/runtime-const.h
> @@ -23,6 +23,7 @@
> typeof(sym) __ret; \
> asm_inline(".option push\n\t" \
> ".option norvc\n\t" \
> + ".option norelax\n\t" \
> "1:\t" \
> "lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
> "addi %[__ret],%[__ret], %%lo(" RUNTIME_MAGIC ")\n\t" \
> @@ -47,6 +48,7 @@
> #define RISCV_RUNTIME_CONST_64_PREAMBLE \
> ".option push\n\t" \
> ".option norvc\n\t" \
> + ".option norelax\n\t" \
> "1:\t" \
> "lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
> "lui %[__tmp], %%hi(" RUNTIME_MAGIC ")\n\t" \
>
> base-commit: 5e601ab3615c86be7c4068ce992f94654693a032
> --
> 2.43.0
>
>
--
Cheers,
Nathan
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip: locking/core] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
2026-08-02 17:43 ` Fangrui Song
` (2 preceding siblings ...)
(?)
@ 2026-08-04 10:31 ` tip-bot2 for Fangrui Song
-1 siblings, 0 replies; 7+ messages in thread
From: tip-bot2 for Fangrui Song @ 2026-08-04 10:31 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nathan Chancellor, Fangrui Song, Peter Zijlstra (Intel), x86,
linux-kernel
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 0f289334af68a1331d4a2d2a95799ffa4ff8a046
Gitweb: https://git.kernel.org/tip/0f289334af68a1331d4a2d2a95799ffa4ff8a046
Author: Fangrui Song <i@maskray.me>
AuthorDate: Sun, 02 Aug 2026 10:43:42 -07:00
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 04 Aug 2026 12:29:45 +02:00
riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC
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")
Closes: https://github.com/ClangBuiltLinux/linux/issues/2179
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Fangrui Song <i@maskray.me>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260802174342.597092-1-i@maskray.me
---
arch/riscv/include/asm/runtime-const.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/riscv/include/asm/runtime-const.h b/arch/riscv/include/asm/runtime-const.h
index a472ebb..ce2008b 100644
--- a/arch/riscv/include/asm/runtime-const.h
+++ b/arch/riscv/include/asm/runtime-const.h
@@ -23,6 +23,7 @@
typeof(sym) __ret; \
asm_inline(".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"addi %[__ret],%[__ret], %%lo(" RUNTIME_MAGIC ")\n\t" \
@@ -47,6 +48,7 @@
#define RISCV_RUNTIME_CONST_64_PREAMBLE \
".option push\n\t" \
".option norvc\n\t" \
+ ".option norelax\n\t" \
"1:\t" \
"lui %[__ret], %%hi(" RUNTIME_MAGIC ")\n\t" \
"lui %[__tmp], %%hi(" RUNTIME_MAGIC ")\n\t" \
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-04 10:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-02 17:43 [PATCH] riscv/runtime-const: Disable linker relaxation for RUNTIME_MAGIC Fangrui Song
2026-08-02 17:43 ` Fangrui Song
2026-08-03 8:27 ` Peter Zijlstra
2026-08-03 8:27 ` Peter Zijlstra
2026-08-03 16:12 ` Nathan Chancellor
2026-08-03 16:12 ` Nathan Chancellor
2026-08-04 10:31 ` [tip: locking/core] " tip-bot2 for Fangrui Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.