Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: bitfield: always inline test conversions
@ 2026-08-07 17:50 Miguel Ojeda
  2026-08-07 18:11 ` Danilo Krummrich
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-08-07 17:50 UTC (permalink / raw)
  To: Alexandre Courbot, Miguel Ojeda
  Cc: Yury Norov, rust-for-linux, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan, Antoni Boucher

From: Antoni Boucher <bouanto@zoho.com>

When using the Rust GCC backend (i.e. `rustc_codegen_gcc`), GCC does not
inline enough these `Bounded::from_expr` calls:

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `<kernel::num::bounded::Bounded<u16, 2> as core::convert::From<kernel::bitfield::tests::Priority>>::from':
    fake.c:(.text.unlikely+0x7be): undefined reference to `rust_build_error'

    /usr/bin/x86_64-linux-gnu-ld.bfd: rust/kernel.o: in function `<kernel::num::bounded::Bounded<u64, 4> as core::convert::From<kernel::bitfield::tests::MemoryType>>::from':
    fake.c:(.text.unlikely+0x90d): undefined reference to `rust_build_error'

Thus, similar to commit bc197e24a3ac ("rust: num: bounded: Always inline
fits_within and from_expr"), mark them as `#[inline(always)]`.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Antoni Boucher <bouanto@zoho.com>
[ Reworded to add the error and to follow our usual style and sent on
  behalf of Antoni, who found this during his work to support Rust for
  Linux with the GCC backend, i.e. with `rustc_codegen_gcc`.- Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 rust/kernel/bitfield.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
index 35ede53f2b8e..a0d089423f21 100644
--- a/rust/kernel/bitfield.rs
+++ b/rust/kernel/bitfield.rs
@@ -581,6 +581,7 @@ fn try_from(value: Bounded<u64, 4>) -> Result<Self, Self::Error> {
     }
 
     impl From<MemoryType> for Bounded<u64, 4> {
+        #[inline(always)]
         fn from(mt: MemoryType) -> Bounded<u64, 4> {
             Bounded::from_expr(mt as u64)
         }
@@ -606,6 +607,7 @@ fn from(value: Bounded<u16, 2>) -> Self {
     }
 
     impl From<Priority> for Bounded<u16, 2> {
+        #[inline(always)]
         fn from(p: Priority) -> Bounded<u16, 2> {
             Bounded::from_expr(p as u16)
         }

base-commit: dc01dfb37b34beeefcfe1c3055364d41a4070c7e
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-10  5:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 17:50 [PATCH] rust: bitfield: always inline test conversions Miguel Ojeda
2026-08-07 18:11 ` Danilo Krummrich
2026-08-07 19:14 ` Gary Guo
2026-08-09  2:11 ` Alexandre Courbot
2026-08-10  5:01 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox