On Thu Aug 13, 2026 at 3:15 PM BST, Petr Pavlu wrote:
> On 8/7/26 3:26 AM, Aaron Tomlin wrote:
>> diff --git a/include/asm-generic/vmlinux.lds.h 
>> b/include/asm-generic/vmlinux.lds.h
>> index 5659f4b5a125..799d912dcbc0 100644
>> --- a/include/asm-generic/vmlinux.lds.h
>> +++ b/include/asm-generic/vmlinux.lds.h
>> @@ -734,7 +734,9 @@
>>      EARLYCON_TABLE()                                                \
>>      LSM_TABLE()                                                     \
>>      EARLY_LSM_TABLE()                                               \
>> -    KUNIT_INIT_TABLE()
>> +    KUNIT_INIT_TABLE()                                              \
>> +    STRUCT_ALIGN();                                                 \
>> +    BOUNDED_SECTION_BY(.initcall.modnames, _initcall_modnames)
>>  
>>  #define INIT_TEXT                                                   \
>>      *(.init.text .init.text.*)                                      \
>
> I realized that instead of using STRUCT_ALIGN(), a cleaner and less
> wasteful approach is to prevent any potential over-alignment of
> individual .initcall.modnames sections by having
> ____define_initcall_modname() define each `struct initcall_modname` with
> `__aligned(__alignof__(struct initcall_modname))`.
>
>> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
>> index 06c18e207508..13353b43b38d 100644
>> --- a/rust/macros/module.rs
>> +++ b/rust/macros/module.rs
>> @@ -479,6 +479,7 @@ pub(crate) fn module(info: ModuleInfo) -> 
>> Result<TokenStream> {
>>      let ident_init = format_ident!("__{ident}_init");
>>      let ident_exit = format_ident!("__{ident}_exit");
>>      let ident_initcall = format_ident!("__{ident}_initcall");
>> +    let ident_modname = format_ident!("__{ident}_modname");
>>      let initcall_section = ".initcall6.init";
>>  
>>      let global_asm = format!(
>> @@ -590,6 +591,21 @@ pub extern "C" fn cleanup_module() {
>>                  #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)]
>>                  ::core::arch::global_asm!(#global_asm);
>>  
>> +                #[cfg(not(MODULE))]
>> +                #[repr(C)]
>> +                struct InitcallModname {
>> +                    initcall_fn: extern "C" fn() -> ::kernel::ffi::c_int,
>> +                    modname: *const ::kernel::ffi::c_char,
>> +                }
>> +
>> +                #[cfg(not(MODULE))]
>> +                #[used(compiler)]
>> +                #[link_section = ".initcall.modnames"]
>> +                static #ident_modname: InitcallModname = InitcallModname {
>
> Can Rust directly use the C definition of initcall_modname via
> ::kernel::bindings::initcall_modname?
>
>> +                    initcall_fn: #ident_init,
>> +                    modname: #name_cstr.as_ptr().cast(),
>
> Can the modname string be placed in .init.rodata to match the behavior
> on the C side?

Putting strings in .init.rodata is more likely to grow the size of kernel
because it cannot be deduplicated with other strings; the names are very likely
to be in .rodata already due to it being added to sysfs when registering with a
bus.

Best,
Gary

>
>> +                };
>> +
>>                  #[cfg(not(MODULE))]
>>                  #[no_mangle]
>>                  pub extern "C" fn #ident_init() -> ::kernel::ffi::c_int {



Reply via email to