Re: [PATCH v3 5/5] rust: Add warn_on and warn_on_once
From: FUJITA Tomonori
Date: Wed Mar 05 2025 - 00:13:24 EST
On Mon, 3 Mar 2025 14:33:39 +0100
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>> +#[macro_export]
>> +#[doc(hidden)]
>> +#[cfg(all(CONFIG_BUG, not(CONFIG_UML)))]
>> +macro_rules! warn_flags {
>> + ($flags:expr) => {
>> + const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
>> + // SAFETY: Just an FFI call.
>> + #[cfg(CONFIG_DEBUG_BUGVERBOSE)]
>> + unsafe {
>> + $crate::asm!(concat!(
>> + "/* {size} */",
>> + ".pushsection .rodata.str1.1, \"aMS\",@progbits, 1\n",
>> + "111:\t .string ", "\"", file!(), "\"\n",
>> + ".popsection\n",
>
> It looks like you're doing this so that you can reference the filename
> with "111b", but could you do this instead:
>
> const _FILE: &[u8] = file!().as_bytes();
> // Plus one for nul-terminator.
> static FILE: [u8; 1 + _FILE.len()] = {
> let mut bytes = [0; 1 + _FILE.len()];
> let mut i = 0;
> while i < _FILE.len() {
> bytes[i] = _FILE[i];
> i += 1;
> }
> bytes
> };
Neat! I will use this in the next version.
> and then use
>
> asm!(
> concat!(
> "/* {size} */",
> include!(concat!(env!("OBJTREE"),
> "/rust/kernel/generated_arch_warn_asm.rs")),
> include!(concat!(env!("OBJTREE"),
> "/rust/kernel/generated_arch_reachable_asm.rs")));
> file = sym FILE,
> line = const line!(),
> ...
> );
>
> with
> ::kernel::concat_literals!(ARCH_WARN_ASM("{file}", "{line}",
> "{flags}", "{size}")),
>
> That would be a lot simpler to understand than what you are doing.
Indeed.
Thanks a lot!