Do not emit `#[link_section = ".modinfo"]` on macOS (i.e. when building
userspace tests); .modinfo is not a legal section specifier in mach-o.
Before this change tests failed to compile:
---- ../rust/macros/lib.rs - module (line 66) stdout ----
rustc-LLVM ERROR: Global variable '_ZN8rust_out13__module_init13__module_init27__MY_DEVICE_DRIVER_MODULE_017h141f80536770e0d4E' has an invalid section specifier '.modinfo': mach-o section specifier requires a segment and section separated by a comma.
Couldn't compile the test.
---- ../rust/macros/lib.rs - module (line 33) stdout ----
rustc-LLVM ERROR: Global variable '_ZN8rust_out13__module_init13__module_init20__MY_KERNEL_MODULE_017h5d79189564b41e07E' has an invalid section specifier '.modinfo': mach-o section specifier requires a segment and section separated by a comma.
Couldn't compile the test.
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
rust/macros/module.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index ca1b7e6a71ff..f09431614f2b 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -58,7 +58,7 @@ fn emit_base(&mut self, field: &str, content: &str, builtin: bool) {
"
{cfg}
#[doc(hidden)]
- #[link_section = \".modinfo\"]
+ #[cfg_attr(not(target_os = \"macos\"), link_section = \".modinfo\")]
#[used]
pub static __{module}_{counter}: [u8; {length}] = *{string};
",
--
2.48.1
On Fri, Feb 7, 2025 at 6:22 PM Tamir Duberstein <tamird@gmail.com> wrote: > > Do not emit `#[link_section = ".modinfo"]` on macOS (i.e. when building > userspace tests); .modinfo is not a legal section specifier in mach-o. I thought the changes we already applied were the ones needed for macOS support. Oh, well... Cheers, Miguel
On Fri, Feb 7, 2025 at 1:13 PM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Fri, Feb 7, 2025 at 6:22 PM Tamir Duberstein <tamird@gmail.com> wrote: > > > > Do not emit `#[link_section = ".modinfo"]` on macOS (i.e. when building > > userspace tests); .modinfo is not a legal section specifier in mach-o. > > I thought the changes we already applied were the ones needed for > macOS support. Oh, well... > > Cheers, > Miguel Yeah, that's on me. I didn't know about (and hadn't tried) `make rusttest` until the cstr series[0]. [0] https://lore.kernel.org/all/20250203-cstr-core-v8-0-cb3f26e78686@gmail.com/t/#u
© 2016 - 2026 Red Hat, Inc.