You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add support for mod_init_funcs (was compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM) #1588
I noticed when switching to the cranelift backend that my typetag types stopped working: dtolnay/typetag#35
I'm not sure what exactly is to blame, but figured it warranted reporting as a compat issue. Through some subsequent debugging, I've identified noticed an issue specific to Cranelift on MacOS where the rust-ctor crate to fails to trigger #[ctor]-annotated code on module initialization: mmastrac/linktime#339
changed the title [-]Cranelift on MacOS fails to[/-][+]compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM[/+]on Jul 8, 2025
Looks like on Mach-O constructor sections should get the S_MOD_INIT_FUNC_POINTERS flag. It seems like LLVM sets this flag for __DATA,__mod_init_func even if you miss the mod_init_funcs flag specified in the #[link_section]. I suspect this is a side-effect of https://github.com/llvm/llvm-project/blob/2e8e254d18f51b6ca898bf0b1e4d12109b5b16c7/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L1292-L1304 combined with merging the flags of identically named sections. The rust-ctor crate should probably use __DATA,__mod_init_func,mod_init_funcs as #[link_section]. That alone won't fix this issue though as handling for mod_init_funcs hasn't been added at
changed the title [-]compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM[/-][+]add support for mod_init_funcs (was compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM)[/+]on Jul 8, 2025
Activity
[-]Cranelift on MacOS fails to[/-][+]compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM[/+]bjorn3 commentedon Jul 8, 2025
Looks like on Mach-O constructor sections should get the
S_MOD_INIT_FUNC_POINTERSflag. It seems like LLVM sets this flag for__DATA,__mod_init_funceven if you miss themod_init_funcsflag specified in the#[link_section]. I suspect this is a side-effect of https://github.com/llvm/llvm-project/blob/2e8e254d18f51b6ca898bf0b1e4d12109b5b16c7/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L1292-L1304 combined with merging the flags of identically named sections. The rust-ctor crate should probably use__DATA,__mod_init_func,mod_init_funcsas#[link_section]. That alone won't fix this issue though as handling formod_init_funcshasn't been added atrustc_codegen_cranelift/src/constant.rs
Lines 396 to 433 in 87e71fe
[-]compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM[/-][+]add support for mod_init_funcs (was compat: rust-ctor fails to trigger with Cranelift on MacOS, but works with LLVM)[/+]Add macOS `mod_init_funcs` flag (#344)
mmastrac commentedon Aug 10, 2025
ctornow emits the full flag (fixed in mmastrac/linktime#344).Support mod_init_funcs section type, fix inline asm target features, …
bjorn3 commentedon Aug 24, 2026
Fixed by 2bc05d4.