[PATCH v3 13/28] rust: Annotate the intrinsic stubs as returnable
From: Josh Poimboeuf <jpoimboe@kernel.org>
Date: 2026-09-21 22:31:43
Also in:
lkml, rust-for-linux
Subsystem:
rust, the rest · Maintainers:
Miguel Ojeda, Linus Torvalds
When building the Rust core library, the compiler emits calls to compiler-rt builtins like __udivti3() for 128-bit arithmetic, which the kernel doesn't want, so objcopy is used to redirect those calls to stubs which just panic. Problem is, their call sites still expect them to return, which confuses objtool. Objtool doesn't report any warnings today because the stubs are weak, which noreturn detection currently ignores. In preparation for removing that restriction, annotate them as returnable. Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> --- rust/Makefile | 6 ++++++ rust/compiler_builtins.rs | 12 ++++++++++++ rust/kernel/.gitignore | 1 + rust/kernel/generated_ignore_noreturn_asm.rs.S | 7 +++++++ 4 files changed, 26 insertions(+) create mode 100644 rust/kernel/generated_ignore_noreturn_asm.rs.S
diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d9845..02795bcd54d62 100644
--- a/rust/Makefile
+++ b/rust/Makefile@@ -49,6 +49,8 @@ ifndef CONFIG_UML always-$(subst y,$(CONFIG_RUST),$(CONFIG_BUG)) += kernel/generated_arch_warn_asm.rs kernel/generated_arch_reachable_asm.rs endif +always-$(subst y,$(CONFIG_RUST),$(CONFIG_OBJTOOL_DEFERRED)) += kernel/generated_ignore_noreturn_asm.rs + # Avoids running `$(RUSTC)` when it may not be available. ifdef CONFIG_RUST
@@ -749,6 +751,10 @@ $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*' $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE +$(call if_changed_rule,rustc_library) +ifdef CONFIG_OBJTOOL_DEFERRED +$(obj)/compiler_builtins.o: $(obj)/kernel/generated_ignore_noreturn_asm.rs +endif + $(obj)/zerocopy.o: private skip_clippy = 1 $(obj)/zerocopy.o: private skip_gendwarfksyms = 1 $(obj)/zerocopy.o: private rustc_target_envs := $(zerocopy-envs)
diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs
index fc6b54636dd54..2d8461c75ec59 100644
--- a/rust/compiler_builtins.rs
+++ b/rust/compiler_builtins.rs@@ -33,6 +33,18 @@ macro_rules! define_panicking_intrinsics( pub extern "C" fn $ident() { panic!($reason); } + + // The redirected call sites were compiled against the real + // intrinsics, which return. Tell objtool to ignore the noreturn + // status of the panicking intrinsics. + #[cfg(CONFIG_OBJTOOL_DEFERRED)] + ::core::arch::global_asm!( + include!(concat!( + env!("OBJTREE"), + "/rust/kernel/generated_ignore_noreturn_asm.rs" + )), + sym = sym $ident, + ); )* } );
diff --git a/rust/kernel/.gitignore b/rust/kernel/.gitignore
index f636ad95aaf3d..a78a3e0e220a1 100644
--- a/rust/kernel/.gitignore
+++ b/rust/kernel/.gitignore@@ -3,3 +3,4 @@ /generated_arch_static_branch_asm.rs /generated_arch_warn_asm.rs /generated_arch_reachable_asm.rs +/generated_ignore_noreturn_asm.rs
diff --git a/rust/kernel/generated_ignore_noreturn_asm.rs.S b/rust/kernel/generated_ignore_noreturn_asm.rs.S
new file mode 100644
index 0000000000000..e2a531cba8acd
--- /dev/null
+++ b/rust/kernel/generated_ignore_noreturn_asm.rs.S@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/annotate.h> + +// Cut here. + +ASM_ANNOTATE_LABEL({sym}, ANNOTYPE_IGNORE_NORETURN)
--
2.55.0