about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArlie Davis <ardavis@microsoft.com>2021-01-31 08:49:23 -0800
committerArlie Davis <ardavis@microsoft.com>2021-01-31 08:49:23 -0800
commit3acd1a4f92013945667f025167cfccdcf6cd73e4 (patch)
treed28f5c00188904138306e469841f90dffa13aefa
parent0e63af5da3400ace48a0345117980473fd21ad73 (diff)
downloadrust-3acd1a4f92013945667f025167cfccdcf6cd73e4.tar.gz
rust-3acd1a4f92013945667f025167cfccdcf6cd73e4.zip
Fix calling convention for CRT startup
My PR #81478 used the wrong calling convention for a set of
functions that are called by the CRT. These functions need to use
`extern "C"`.

This would only affect x86, which is the only target (that I know of)
that has multiple calling conventions.
-rw-r--r--library/std/src/sys/windows/compat.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs
index 017a4bbe97c..cbd3366b189 100644
--- a/library/std/src/sys/windows/compat.rs
+++ b/library/std/src/sys/windows/compat.rs
@@ -74,9 +74,9 @@ macro_rules! compat_fn {
             /// used, and would remove it.
             #[used]
             #[link_section = ".CRT$XCU"]
-            static INIT_TABLE_ENTRY: fn() = init;
+            static INIT_TABLE_ENTRY: unsafe extern "C" fn() = init;
 
-            fn init() {
+            unsafe extern "C" fn init() {
                 // There is no locking here. This code is executed before main() is entered, and
                 // is guaranteed to be single-threaded.
                 //
@@ -84,16 +84,14 @@ macro_rules! compat_fn {
                 // any Rust functions or CRT functions, if those functions touch any global state,
                 // because this function runs during global initialization. For example, DO NOT
                 // do any dynamic allocation, don't call LoadLibrary, etc.
-                unsafe {
-                    let module_name: *const u8 = concat!($module, "\0").as_ptr();
-                    let symbol_name: *const u8 = concat!(stringify!($symbol), "\0").as_ptr();
-                    let module_handle = $crate::sys::c::GetModuleHandleA(module_name as *const i8);
-                    if !module_handle.is_null() {
-                        match $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8) as usize {
-                            0 => {}
-                            n => {
-                                PTR = Some(mem::transmute::<usize, F>(n));
-                            }
+                let module_name: *const u8 = concat!($module, "\0").as_ptr();
+                let symbol_name: *const u8 = concat!(stringify!($symbol), "\0").as_ptr();
+                let module_handle = $crate::sys::c::GetModuleHandleA(module_name as *const i8);
+                if !module_handle.is_null() {
+                    match $crate::sys::c::GetProcAddress(module_handle, symbol_name as *const i8) as usize {
+                        0 => {}
+                        n => {
+                            PTR = Some(mem::transmute::<usize, F>(n));
                         }
                     }
                 }