[PATCH v2 13/27] rust: Annotate the intrinsic stubs as returnable

From
Josh Poimboeuf <jpoimboe@kernel.org>
Date
2026-09-08 20:34:35
Also in
linux-kbuild, lkml
Reply to
Josh Poimboeuf, 2026-09-08
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/.gitignore |  1 +
 rust/Makefile   | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
diff --git a/rust/.gitignore b/rust/.gitignore
index d3829ffab80ba..c198d1a52e60e 100644
--- a/rust/.gitignore
+++ b/rust/.gitignore
@@ -6,5 +6,6 @@ doctests_kernel_generated.rs
 doctests_kernel_generated_kunit.c
 uapi_generated.rs
 exports_*_generated.h
+intrinsics_annotate_generated.c
 doc/
 test/
diff --git a/rust/Makefile b/rust/Makefile
index da1a7409d9845..0aa9f298a2757 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -36,6 +36,9 @@ endif
 
 obj-$(CONFIG_RUST) += exports.o
 
+always-$(CONFIG_RUST) += intrinsics_annotate_generated.c
+obj-$(CONFIG_RUST)    += intrinsics_annotate_generated.o
+
 always-$(CONFIG_RUST) += host/libproc_macro2.rlib host/libquote.rlib host/libsyn.rlib
 
 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs
@@ -702,6 +705,20 @@ ifdef CONFIG_PPC32
 		__udivdi3 __umoddi3
 endif
 
+# For objtool, annotate the redirect-intrinsics as returnable.  Their call
+# sites were compiled against the returnable intrinsics, but the redirected
+# versions are noreturn.
+quiet_cmd_intrinsics_annotate = GEN     $@
+      cmd_intrinsics_annotate = { \
+	echo '/* Generated by rust/Makefile - do not edit */'; \
+	echo '\#include <linux/annotate.h>'; \
+	for s in $(redirect-intrinsics); do \
+		echo "ANNOTATE_IGNORE_NORETURN(__rust$$s);"; \
+	done; } > $@
+
+$(obj)/intrinsics_annotate_generated.c: $(srctree)/rust/Makefile FORCE
+	$(call if_changed,intrinsics_annotate)
+
 ifdef CONFIG_MODVERSIONS
 cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \
 	$(call rust_exports,$@,"%s\n") | \
-- 
2.55.0
Thread (29 messages) 29 messages, 2 authors, last reply 2026-09-10
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help