@@ -60,37 +60,36 @@ pub mod eh_frames {
60
60
}
61
61
62
62
// Unwind info registration/deregistration routines.
63
- // See the docs of `unwind` module in libstd .
63
+ // See the docs of libpanic_unwind .
64
64
extern "C" {
65
65
fn rust_eh_register_frames ( eh_frame_begin : * const u8 , object : * mut u8 ) ;
66
66
fn rust_eh_unregister_frames ( eh_frame_begin : * const u8 , object : * mut u8 ) ;
67
67
}
68
68
69
- unsafe fn init ( ) {
69
+ unsafe extern "C" fn init ( ) {
70
70
// register unwind info on module startup
71
71
rust_eh_register_frames ( & __EH_FRAME_BEGIN__ as * const u8 , & mut OBJ as * mut _ as * mut u8 ) ;
72
72
}
73
73
74
- unsafe fn uninit ( ) {
74
+ unsafe extern "C" fn uninit ( ) {
75
75
// unregister on shutdown
76
76
rust_eh_unregister_frames ( & __EH_FRAME_BEGIN__ as * const u8 , & mut OBJ as * mut _ as * mut u8 ) ;
77
77
}
78
78
79
- // MSVC-specific init/uninit routine registration
80
- pub mod ms_init {
81
- // .CRT$X?? sections are roughly analogous to ELF's .init_array and .fini_array,
82
- // except that they exploit the fact that linker will sort them alphabitically,
83
- // so e.g., sections with names between .CRT$XIA and .CRT$XIZ are guaranteed to be
84
- // placed between those two, without requiring any ordering of objects on the linker
85
- // command line.
86
- // Note that ordering of same-named sections from different objects is not guaranteed.
87
- // Since .CRT$XIA contains init array's header symbol, which must always come first,
88
- // we place our initialization callback into .CRT$XIB.
79
+ // MinGW-specific init/uninit routine registration
80
+ pub mod mingw_init {
81
+ // MinGW's startup objects (crt0.o / dllcrt0.o) will invoke global constructors in the
82
+ // .ctors and .dtors sections on startup and exit. In the case of DLLs, this is done when
83
+ // the DLL is loaded and unloaded.
84
+ //
85
+ // The linker will sort the sections, which ensures that our callbacks are located at the
86
+ // end of the list. Since constructors are run in reverse order, this ensures that our
87
+ // callbacks are the first and last ones executed.
89
88
90
- #[ link_section = ".CRT$XIB " ] // .CRT$XI? : C initialization callbacks
91
- pub static P_INIT : unsafe fn ( ) = super :: init;
89
+ #[ link_section = ".ctors.65535 " ] // .ctors.* : C initialization callbacks
90
+ pub static P_INIT : unsafe extern "C" fn ( ) = super :: init;
92
91
93
- #[ link_section = ".CRT$XTY " ] // .CRT$XT? : C termination callbacks
94
- pub static P_UNINIT : unsafe fn ( ) = super :: uninit;
92
+ #[ link_section = ".dtors.65535 " ] // .dtors.* : C termination callbacks
93
+ pub static P_UNINIT : unsafe extern "C" fn ( ) = super :: uninit;
95
94
}
96
95
}
0 commit comments