* [PATCH v1] rust: jump_label: skip arch-specific asm in `testlib` builds
@ 2026-08-09 13:48 FUJITA Tomonori
0 siblings, 0 replies; only message in thread
From: FUJITA Tomonori @ 2026-08-09 13:48 UTC (permalink / raw)
To: aliceryhl, jbaron, jpoimboe, ojeda, peterz
Cc: a.hindborg, acourbot, ardb, bjorn3_gh, boqun, dakr,
daniel.almeida, gary, lossin, rostedt, tamird, tmgross, work,
rust-for-linux, FUJITA Tomonori
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Running `make rusttest` with `ARCH=` set to an architecture other than
the host's fails, e.g. `ARCH=arm64` on an x86_64 host:
error: alignment must be a power of 2
--> rust/kernel/jump_label.rs:51:13
|
51 | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_static_branch_asm.rs"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: instantiated into assembly here
--> <inline asm>:3:10
|
3 | .align 3
| ^
The reason is that `rusttest` builds the kernel crate as a host
library: it passes the `CONFIG_*` cfgs of the configured architecture,
but not `--target`, so code generation happens for the
host. `arch_static_branch!` then selects the arch-specific inline asm
arm based on CONFIG_*, and the host assembler rejects it.
This does not happen with the current master because
`arch_static_branch!` has no user inside the kernel crate itself yet,
but fix it now to avoid surprises later.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/jump_label.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/rust/kernel/jump_label.rs b/rust/kernel/jump_label.rs
index 4e974c768dbd..f54cedcb6fd5 100644
--- a/rust/kernel/jump_label.rs
+++ b/rust/kernel/jump_label.rs
@@ -44,6 +44,7 @@ macro_rules! static_branch_unlikely {
#[macro_export]
#[doc(hidden)]
+#[cfg(not(testlib))]
#[cfg(CONFIG_JUMP_LABEL)]
macro_rules! arch_static_branch {
($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {
@@ -61,6 +62,17 @@ macro_rules! arch_static_branch {
}};
}
+#[macro_export]
+#[doc(hidden)]
+#[cfg(testlib)]
+#[cfg(CONFIG_JUMP_LABEL)]
+macro_rules! arch_static_branch {
+ ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {
+ // The asm falls through until patched, which never happens on the host.
+ false
+ };
+}
+
#[cfg(CONFIG_JUMP_LABEL)]
pub use arch_static_branch;
base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-09 13:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09 13:48 [PATCH v1] rust: jump_label: skip arch-specific asm in `testlib` builds FUJITA Tomonori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox