[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CANiq72kfe=k+vuJ13yvwzfNg-or3Np-4+XiZ0nX-YFoDTY=n4Q@mail.gmail.com>
Date: Sun, 23 Nov 2025 22:51:38 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Alexandre Courbot <acourbot@...dia.com>
Cc: 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 <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, kernel test robot <lkp@...el.com>
Subject: Re: [PATCH] rust: num: bounded: Always inline fits_within and from_expr
On Sat, Nov 22, 2025 at 5:01 AM Alexandre Courbot <acourbot@...dia.com> wrote:
>
> `from_expr` relies on `build_assert` to infer that the passed expression
> fits the type's boundaries at build time. That inference can only be
> successful its code (and that of `fits_within`, which performs the
> check) is inlined, as a dedicated function would need to work with a
> variable and cannot verify that property.
>
> While inlining happens as expected in most cases, it is not guaranteed.
> In particular, kernel options that optimize for size like
> `CONFIG_CC_OPTIMIZE_FOR_SIZE` can result in `from_expr` not being
> inlined.
>
> Add `#[inline(always)]` attributes to both `fits_within` and `from_expr`
> to make the compiler inline these functions more aggressively, as it
> does not make sense to use them non-inlined anyway.
>
> Fixes: 01e345e82ec3 ("rust: num: add Bounded integer wrapping type")
> Reported-by: kernel test robot <lkp@...el.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202511210055.RUsFNku1-lkp@intel.com/
> Suggested-by: Gary Guo <gary@...yguo.net>
> Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
Applied to `rust-next` -- thanks!
[ For reference, the errors look like:
ld.lld: error: undefined symbol: rust_build_error
>>> referenced by build_assert.rs:83 (rust/kernel/build_assert.rs:83)
>>>
rust/doctests_kernel_generated.o:(<kernel::num::bounded::Bounded<u8,
1>>::from_expr) in archive vmlinux.a
- Miguel ]
I could have rebased, but since you sent this nice patch with a good
commit message and kernel test robot reported it, let's add it :)
Cheers,
Miguel
Powered by blists - more mailing lists