rust: bug: skip arch-specific asm in `testlib` builds
PATCH 1/1 rust: bug: skip arch-specific asm in `testlib` builds
From: FUJITA Tomonori <[email protected]>
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: invalid instruction mnemonic 'brk'
--> rust/kernel/bug.rs:63:17
|
63 | / concat!(
64 | | "/* {size} */",
65 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")),
66 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs")));
| |_______________________________________________________________________________________________________^
|
note: instantiated into assembly here
--> <inline asm>:1:115
|
1 | /* 8 */.pushsection __bug_table,"aw"; .align 2; 14470: .long 14471f - .;.short 2305;.align 2; .popsection; 14471:brk 0x800
| ^^^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. warn_flags! 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 warn_on! has no user inside the kernel crate itself yet, but it will as soon as one is added.
--- rust/kernel/bug.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
rust/kernel/bug.rs +5 -1
@@ -8,6 +8,7 @@#[macro_export] #[doc(hidden)] +#[cfg(not(testlib))] #[cfg(all( CONFIG_BUG , not( CONFIG_UML ), not( CONFIG_LOONGARCH ), not( CONFIG_ARM )))] #[cfg( CONFIG_DEBUG_BUGVERBOSE )] macro_rules! warn_flags {
@@ -47,6 +48,7 @@ macro_rules! warn_flags {#[macro_export] #[doc(hidden)] +#[cfg(not(testlib))] #[cfg(all( CONFIG_BUG , not( CONFIG_UML ), not( CONFIG_LOONGARCH ), not( CONFIG_ARM )))] #[cfg(not( CONFIG_DEBUG_BUGVERBOSE ))] macro_rules! warn_flags {
@@ -73,6 +75,7 @@ macro_rules! warn_flags {#[macro_export] #[doc(hidden)] +#[cfg(not(testlib))] #[cfg(all( CONFIG_BUG , CONFIG_UML ))] macro_rules! warn_flags { ($file:expr, $flags:expr) => {
@@ -91,6 +94,7 @@ macro_rules! warn_flags {#[macro_export] #[doc(hidden)] +#[cfg(not(testlib))] #[cfg(all( CONFIG_BUG , any( CONFIG_LOONGARCH , CONFIG_ARM )))] macro_rules! warn_flags { ($file:expr, $flags:expr) => {
@@ -101,7 +105,7 @@ macro_rules! warn_flags {#[macro_export] #[doc(hidden)] -#[cfg(not( CONFIG_BUG ))] +#[cfg(any(testlib, not( CONFIG_BUG )))] macro_rules! warn_flags { ($file:expr, $flags:expr) => {}; }
base-commit: 075b74841bd0065a3bda3440873c747938e69b68
Signature · 1 line
2.43.0
Miguel Ojeda
AppliedQuoted 27 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
Running
make rusttestwithARCH=set to an architecture other than the host's fails, e.g.ARCH=arm64on anx86_64host:error: invalid instruction mnemonic 'brk'
-->rust/kernel/bug.rs:63:17| 63 | / concat!( 64 | | "/* {size} */", 65 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_warn_asm.rs")), 66 | | include!(concat!(env!("OBJTREE"), "/rust/kernel/generated_arch_reachable_asm.rs"))); | |_______________________________________________________________________________________________________^ | note: instantiated into assembly here --> <inline asm>:1:115 | 1 | /* 8 */.pushsection __bug_table,"aw"; .align 2; 14470: .long 14471f - .;.short 2305;.align 2; .popsection; 14471:brk 0x800 | ^^^The reason is that
rusttestbuilds thekernelcrate as a host
library: it passes theCONFIG_*cfgs of the configured architecture, but not--target, so code generation happens for the host.warn_flags!then selects the arch-specific inline asm arm based onCONFIG_*, and the host assembler rejects it.
Quoted 7 lines
This does not happen with the current
masterbecausewarn_on!has no user inside thekernelcrate itself yet, but it will as soon as one is added.
Applied to rust-next -- thanks!
Cc: [email protected] Fixes: dff64b072708 ("rust: Add warn_on macro")
Cheers,
Miguel