Skip to contentSkip to conversation

rust: bitfield: always inline test conversions

PATCH Applied Miguel Ojeda 5 participants 5 messages Aug 7 – Aug 10

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: bitfield: always inline test conversions

From: Antoni Boucher <[email protected]>

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

[ 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 ]

---
 rust/kernel/bitfield.rs | 2 ++
 1 file changed, 2 insertions(+)
rust/kernel/bitfield.rs +2 -0
index 35ede53f2b8e..a0d089423f21 100644
@@ -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

Signature · 1 line
2.55.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Miguel Ojeda

From: Antoni Boucher <[email protected]>

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)].

Quoted 6 lines
Assisted-by Claude:claude-opus-4-8

[ 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 ]

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Miguel Ojeda
Quoted 14 lines · Miguel Ojeda

From: Antoni Boucher <[email protected]>

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)].

Quoted 6 lines
Assisted-by Claude:claude-opus-4-8

[ 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 ]

Quoted 3 lines
---
 rust/kernel/bitfield.rs | 2 ++
 1 file changed, 2 insertions(+)
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Miguel Ojeda
Quoted 14 lines · Miguel Ojeda

From: Antoni Boucher <[email protected]>

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)].

Quoted 6 lines
Assisted-by Claude:claude-opus-4-8

[ 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 ]

There always are a couple of these going through the cracks, aren't there. :)

Applied
#4 lore raw
In reply to Miguel Ojeda
Quoted 15 lines · Miguel Ojeda

From: Antoni Boucher <[email protected]>

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)].

Quoted 6 lines
Assisted-by Claude:claude-opus-4-8

[ 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 ]

Applied to rust-next -- thanks everyone!

Cheers,
Miguel