History

rust: jump_label: skip arch-specific asm in `testlib` builds

Running `make rusttest` with `ARCH=` set to an architecture other than the host's may fail in the future, 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.

FUJITA Tomonori committed 3 months ago

Commit dea1bf31 parent 993f2351 file · +12 −0Browse files

Unified · Split

rust/kernel/jump_label.rs+12−0
@@ -44,6 +44,7 @@ const _: &str = include!(concat!( · 43 unmodified lines
44 44
45#[macro_export]45#[macro_export]
46#[doc(hidden)]46#[doc(hidden)]
47#[cfg(not(testlib))]
47#[cfg(CONFIG_JUMP_LABEL)]48#[cfg(CONFIG_JUMP_LABEL)]
48macro_rules! arch_static_branch {49macro_rules! arch_static_branch {
49 ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {50 ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {'my_label: {
@@ -61,6 +62,17 @@ macro_rules! arch_static_branch { · 11 unmodified lines
61 }};62 }};
62}63}
63 64
65#[macro_export]
66#[doc(hidden)]
67#[cfg(testlib)]
68#[cfg(CONFIG_JUMP_LABEL)]
69macro_rules! arch_static_branch {
70 ($key:path, $keytyp:ty, $field:ident, $branch:expr) => {
71 // The asm falls through until patched, which never happens on the host.
72 false
73 };
74}
75
64#[cfg(CONFIG_JUMP_LABEL)]76#[cfg(CONFIG_JUMP_LABEL)]
65pub use arch_static_branch;77pub use arch_static_branch;
66 78

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t