rust: arm64: set uwtable llvm module flag for CONFIG_UNWIND_TABLES
Alice Ryhl
reviewerPATCH 1/1 rust: arm64: set uwtable llvm module flag for CONFIG_UNWIND_TABLES
Due to a rustc bug [1] the -Cforce-unwind-tables=y flag only emits the uwtable annotation for functions, but not for the module. This means that compiler-generated functions such as 'asan.module_ctor' do not receive the uwtable annotation.
When CONFIG_UNWIND_PATCH_PAC_INTO_SCS is enabled, this leads to boot failures because the dwarf information emitted for the kasan constructors is wrong, which causes the SCS boot patching code to patch the constructor in an illegal manner. Specifically, the paciasp instruction is patched, but the autiasp instruction is not. This mismatch leads to a crash when the constructor is called during boot.
================================================================== BUG: KASAN: global-out-of-bounds in do_basic_setup+0x4c/0x90 Read of size 8 at addr ffffffe3cc7eb488 by task swapper/0/1
Specifically the faulting instruction is the (*fn)() to invoke the constructor in do_ctors() of the init/main.c file.
Once the fix lands in rustc, this flag can be made conditional on the rustc version. Note that passing the flag on a rustc with the fix present has no effect.
--- arch/arm64/Makefile | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/Makefile +3 -0
@@ -63,6 +63,9 @@ else KBUILD_CFLAGS += -fasynchronous-unwind-tables KBUILD_AFLAGS += -fasynchronous-unwind-tables KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n +# Work around rustc bug on compilers without below change: +# https://github.com/rust-lang/rust/pull/156973 +KBUILD_RUSTFLAGS += -Zllvm_module_flag=uwtable:u32:2:max endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
---
base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32
change-id: 20260527-uwtable-module-flag-6a0595bf0e97
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Alice Ryhl
reviewerQuoted 1 line · Alice Ryhl
Oops, should be 156973.
Quoted 4 lines · Alice Ryhl
Once the fix lands in rustc, this flag can be made conditional on the rustc version. Note that passing the flag on a rustc with the fix present has no effect.
Already landed now, so if the uwtable one is enough, we could already do that since it will be 1.98. But since it has no effect, we can keep the fix as-is and do that on top too.
Added and linked both issues (i.e. uwtable and the frame-pointer one) to:
https://github.com/Rust-for-Linux/linux/issues/355
I have to send a fixes PR in the coming days, so I can pick this one up, but if arm64 will do so then:
Thanks!
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 10 lines · Miguel Ojeda
Quoted 4 lines · Alice Ryhl
Once the fix lands in rustc, this flag can be made conditional on the rustc version. Note that passing the flag on a rustc with the fix present has no effect.
Already landed now, so if the uwtable one is enough, we could already do that since it will be 1.98. But since it has no effect, we can keep the fix as-is and do that on top too.
Ah, yes, let's just add the version check.
With regards to the frame-pointer one, it's probably a good idea to do the same for that one. It's not necessary to fix the boot crash I encountered, but may help with other issues such as backtraces of ftrace.
Quoted 13 lines
Added and linked both issues (i.e.
uwtableand theframe-pointerone) to:https://github.com/Rust-for-Linux/linux/issues/355
I have to send a fixes PR in the coming days, so I can pick this one up, but if arm64 will do so then:
Acked-by Miguel Ojeda <[email protected]>Thanks!
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 9 lines · Miguel Ojeda
Quoted 4 lines · Alice Ryhl
Once the fix lands in rustc, this flag can be made conditional on the rustc version. Note that passing the flag on a rustc with the fix present has no effect.
Already landed now, so if the uwtable one is enough, we could already do that since it will be 1.98. But since it has no effect, we can keep the fix as-is and do that on top too.
Hrm, is there a way to perform the version check in the Makefile, or do I need a Kconfig for whether the fix is needed?
Alice
Quoted 3 lines · Alice Ryhl
Hrm, is there a way to perform the version check in the
Makefile, or do I need aKconfigfor whether the fix is needed?
We shouldn't need a Kconfig -- we can do e.g.
KBUILD_RUSTFLAGS += $(if $(call
rustc-min-version,109800),,-Zllvm_module_flag=uwtable:u32:2:max)
I tested with 1.96 and nightly -- I can apply it to the Rust tree if arm64 prefers.
I hope that helps!
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 8 lines · Miguel Ojeda
Quoted 3 lines · Alice Ryhl
Hrm, is there a way to perform the version check in the
Makefile, or do I need aKconfigfor whether the fix is needed?We shouldn't need a
Kconfig-- we can do e.g.KBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109800),,-Zllvm_module_flag=uwtable:u32:2:max)
Ah, right we can do it like that! LGTM.
Alice
Catalin Marinas
maintainerQuoted 11 lines · Miguel Ojeda
Quoted 2 lines · Alice Ryhl
Hrm, is there a way to perform the version check in the
Makefile, or do I need aKconfigfor whether the fix is needed?We shouldn't need a
Kconfig-- we can do e.g.
KBUILD_RUSTFLAGS+= $(if $(call
rustc-min-version,109800),,-Zllvm_module_flag=uwtable:u32:2:max)I tested with 1.96 and nightly -- I can apply it to the Rust tree if arm64 prefers.
Please do.
Signature · 1 line
Catalin
Miguel Ojeda
AppliedQuoted 24 lines · Alice Ryhl
Due to a rustc bug [1] the -Cforce-unwind-tables=y flag only emits the uwtable annotation for functions, but not for the module. This means that compiler-generated functions such as 'asan.module_ctor' do not receive the uwtable annotation.
When
CONFIG_UNWIND_PATCH_PAC_INTO_SCSis enabled, this leads to boot failures because the dwarf information emitted for the kasan constructors is wrong, which causes the SCS boot patching code to patch the constructor in an illegal manner. Specifically, the paciasp instruction is patched, but the autiasp instruction is not. This mismatch leads to a crash when the constructor is called during boot.================================================================== BUG: KASAN: global-out-of-bounds in do_basic_setup+0x4c/0x90 Read of size 8 at addr ffffffe3cc7eb488 by task swapper/0/1Specifically the faulting instruction is the (*fn)() to invoke the constructor in
do_ctors()of theinit/main.cfile.Once the fix lands in rustc, this flag can be made conditional on the rustc version. Note that passing the flag on a rustc with the fix present has no effect.
Quoted 8 lines
Fixes d077242d68a3 ("rust: support for shadow call stack sanitizer")Reported-by Bo Ye <[email protected]>Debugged-by Isaac Manjarres <[email protected]>Debugged-by Sami Tolvanen <[email protected]>Tested-by Isaac Manjarres <[email protected]>Signed-off-by Alice Ryhl <[email protected]>
Applied to rust-fixes -- thanks everyone!
[ The fix [1] has landed for Rust 1.98.0 (expected release on
2026-08-20).
Thus add a version check as discussed.
- Miguel ]
[ Adjusted link and comment. - Miguel ]
Cheers,
Miguel