mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Gary Guo <gary@garyguo.net>,
	rust-for-linux@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
	Miguel Ojeda <ojeda@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nsc@kernel.org>,
	linux-kbuild@vger.kernel.org, Huacai Chen <chenhuacai@kernel.org>
Subject: [PATCH v3 13/28] rust: Annotate the intrinsic stubs as returnable
Date: Mon, 21 Sep 2026 15:31:14 -0700	[thread overview]
Message-ID: <93cfd994e314357feb37f524c575a497f33213cc.1790028654.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1790028654.git.jpoimboe@kernel.org>

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


  parent reply	other threads:[~2026-09-21 22:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 22:31 [PATCH v3 00/28] objtool: dynamically detect noreturns Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 01/28] objtool: Remove obsolete noreturns.h entries Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 02/28] kbuild: Add CONFIG_OBJTOOL_DEFERRED Josh Poimboeuf
2026-09-24 11:39   ` Nicolas Schier
2026-09-21 22:31 ` [PATCH v3 03/28] kbuild: Add CONFIG_OBJTOOL_CONTROL_FLOW Josh Poimboeuf
2026-09-24 11:40   ` Nicolas Schier
2026-09-21 22:31 ` [PATCH v3 04/28] objtool: Fix dead end detection for sibling calls Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 05/28] objtool: Refactor the noreturn/dead-end detection Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 06/28] objtool: Ignore traps after noreturn calls in STT_CODE Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 07/28] objtool: Make .discard.stack_frame_non_standard non-allocatable Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 08/28] efi/libstub: Drop .discard.addressable from the stub objects Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 09/28] efi/loongarch: Mark loongarch efi_boot_kernel() non-standard for objtool Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 10/28] objtool: Add ANNOTATE_IGNORE_NORETURN() Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 11/28] LoongArch: Annotate reboot and kexec paths as returnable Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 12/28] kbuild: Defer running objtool to link time for all CFG features Josh Poimboeuf
2026-09-24 11:48   ` Nicolas Schier
2026-09-21 22:31 ` Josh Poimboeuf [this message]
2026-09-21 22:31 ` [PATCH v3 14/28] panic: Mark abort() __noreturn Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 15/28] x86/xen: Ignore noreturn status of weak mem_map_via_hcall() Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 16/28] objtool: Detect noreturns in weak functions Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 17/28] x86/entry: Make rewind_stack_and_make_dead() a real function Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 18/28] x86/xen: Make xen_cpu_bringup_again() " Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 19/28] x86/xen: Make xen_start_kernel() noreturn Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 20/28] x86/boot: Rework how pi startup symbols get exposed to vmlinux Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 21/28] objtool: Fix noreturn detection for non-sibling jumps to SYM_CODE Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 22/28] objtool: Add options to write/read exported noreturns to/from a file Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 23/28] kbuild: Do the per-module objtool pass right before linking Josh Poimboeuf
2026-09-24 11:22   ` Nicolas Schier
2026-09-21 22:31 ` [PATCH v3 24/28] kbuild: Generate the noreturn list and validate modules against it Josh Poimboeuf
2026-09-24 12:18   ` Nicolas Schier
2026-09-21 22:31 ` [PATCH v3 25/28] objtool: Add ANNOTATE_EXPORTED_NORETURN() Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 26/28] objtool: Annotate all module-exported noreturns and remove noreturns.h Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 27/28] objtool: Warn about missing/stale ANNOTATE_EXPORTED_NORETURN() usage Josh Poimboeuf
2026-09-21 22:31 ` [PATCH v3 28/28] fixup! objtool: Add options to write/read exported noreturns to/from a file Josh Poimboeuf

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=93cfd994e314357feb37f524c575a497f33213cc.1790028654.git.jpoimboe@kernel.org \
    --to=jpoimboe@kernel.org \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®