[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250201-remove_intrinsic-v1-1-4283ce8e4764@gmail.com>
Date: Sat, 01 Feb 2025 15:39:16 +0100
From: Christian Schrefl <chrisi.schrefl@...il.com>
To: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Arnd Bergmann <arnd@...db.de>
Cc: Andrew Lunn <andrew@...n.ch>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, Christian Schrefl <chrisi.schrefl@...il.com>
Subject: [PATCH RFC WIP] rust: remove x86 panicking intrinsics.
This removes the panicking implementation of the x86 intrinsics.
This requires a PR [0] for the rust core library to remove the need for
the `__udivti3` intrinsic. This PR disables formatting support for the
`i/u128` rust primitives when the `no_iu128_fmt` config option is set.
In order to remove the need for the other intrinsics a recent rust
version is required (Tested with 1.84).
Link: https://github.com/rust-lang/rust/pull/136385 [0]
Signed-off-by: Christian Schrefl <chrisi.schrefl@...il.com>
---
This patch removes the need to use `define_panicking_intrinsics` for
adding stub intrinsics implementations on x86.
This came up in a discussion [0] on my 32-bit arm support. The
`define_panicking_intrinsics` macro is kept, because it will still be
needed for 32-bit arm (and possibly other architecures).
Removing the `__udivti3` intrinsic requires a Rust PR [1] and the other
intrinsics only require a recent rust version (tested with 1.84),
so when building with older rust versions would still require these
intrinsics.
For now this is mostly done as a demonstration that this should be
possible to do once the MSRV is bumped high enough (and possibly my
Rust PR is merged).
I have tested building a x86_64 kernel and running the rust samples
in qemu.
Link: https://lore.kernel.org/rust-for-linux/defddc25-eb8b-420a-b64c-6ce57ebb3f6b@gmail.com/ [0]
Link: https://github.com/rust-lang/rust/pull/136385 [1]
---
rust/Makefile | 15 +--------------
rust/compiler_builtins.rs | 37 +------------------------------------
2 files changed, 2 insertions(+), 50 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index a40a3936126d603836e0ec9b42a1285916b60e45..7d3be8fb257a7f2cb9ddb69ce6b6529ce989aee7 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -53,7 +53,7 @@ rustdoc_test_kernel_quiet=>/dev/null
endif
core-cfgs = \
- --cfg no_fp_fmt_parse
+ --cfg no_fp_fmt_parse --cfg no_iu128_fmt
quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
cmd_rustdoc = \
@@ -388,19 +388,6 @@ rust-analyzer:
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
> rust-project.json
-redirect-intrinsics = \
- __addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \
- __adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \
- __muloti4 __multi3 \
- __udivmodti4 __udivti3 __umodti3
-
-ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
- # These intrinsics are defined for ARM64 and RISCV64
- redirect-intrinsics += \
- __ashrti3 \
- __ashlti3 __lshrti3
-endif
-
define rule_rustc_library
$(call cmd_and_fixdep,rustc_library)
$(call cmd,gen_objtooldep)
diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs
index f14b8d7caf89964198313deace1bcb06fea82964..c4ca246abd8e789bb0ed8d8b6736a88ce3f961f7 100644
--- a/rust/compiler_builtins.rs
+++ b/rust/compiler_builtins.rs
@@ -25,6 +25,7 @@
#![no_builtins]
#![no_std]
+#[expect(unused_macros)]
macro_rules! define_panicking_intrinsics(
($reason: tt, { $($ident: ident, )* }) => {
$(
@@ -37,41 +38,5 @@ pub extern "C" fn $ident() {
}
);
-define_panicking_intrinsics!("`f32` should not be used", {
- __addsf3,
- __eqsf2,
- __extendsfdf2,
- __gesf2,
- __lesf2,
- __ltsf2,
- __mulsf3,
- __nesf2,
- __truncdfsf2,
- __unordsf2,
-});
-
-define_panicking_intrinsics!("`f64` should not be used", {
- __adddf3,
- __eqdf2,
- __ledf2,
- __ltdf2,
- __muldf3,
- __unorddf2,
-});
-
-define_panicking_intrinsics!("`i128` should not be used", {
- __ashrti3,
- __muloti4,
- __multi3,
-});
-
-define_panicking_intrinsics!("`u128` should not be used", {
- __ashlti3,
- __lshrti3,
- __udivmodti4,
- __udivti3,
- __umodti3,
-});
-
// NOTE: if you are adding a new intrinsic here, you should also add it to
// `redirect-intrinsics` in `rust/Makefile`.
---
base-commit: ffd294d346d185b70e28b1a28abe367bbfe53c04
change-id: 20250201-remove_intrinsic-27749d5f93ac
Best regards,
--
Christian Schrefl <chrisi.schrefl@...il.com>
Powered by blists - more mailing lists