about summary refs log tree commit diff
path: root/tests/ui/linking/export-executable-symbols.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/linking/export-executable-symbols.rs')
-rw-r--r--tests/ui/linking/export-executable-symbols.rs30
1 files changed, 25 insertions, 5 deletions
diff --git a/tests/ui/linking/export-executable-symbols.rs b/tests/ui/linking/export-executable-symbols.rs
index aea5527b6a1..2bff58ca38a 100644
--- a/tests/ui/linking/export-executable-symbols.rs
+++ b/tests/ui/linking/export-executable-symbols.rs
@@ -1,22 +1,22 @@
 //@ run-pass
-//@ only-linux
-//@ only-gnu
-//@ compile-flags: -Zexport-executable-symbols
+//@ compile-flags: -Ctarget-feature=-crt-static -Zexport-executable-symbols
+//@ ignore-wasm
+//@ ignore-cross-compile
 //@ edition: 2024
 
 // Regression test for <https://github.com/rust-lang/rust/issues/101610>.
 
 #![feature(rustc_private)]
 
-extern crate libc;
-
 #[unsafe(no_mangle)]
 fn hack() -> u64 {
     998244353
 }
 
 fn main() {
+    #[cfg(unix)]
     unsafe {
+        extern crate libc;
         let handle = libc::dlopen(std::ptr::null(), libc::RTLD_NOW);
         let ptr = libc::dlsym(handle, c"hack".as_ptr());
         let ptr: Option<unsafe fn() -> u64> = std::mem::transmute(ptr);
@@ -27,4 +27,24 @@ fn main() {
             panic!("symbol `hack` is not found");
         }
     }
+    #[cfg(windows)]
+    unsafe {
+        type PCSTR = *const u8;
+        type HMODULE = *mut core::ffi::c_void;
+        type FARPROC = Option<unsafe extern "system" fn() -> isize>;
+        #[link(name = "kernel32", kind = "raw-dylib")]
+        unsafe extern "system" {
+            fn GetModuleHandleA(lpmodulename: PCSTR) -> HMODULE;
+            fn GetProcAddress(hmodule: HMODULE, lpprocname: PCSTR) -> FARPROC;
+        }
+        let handle = GetModuleHandleA(std::ptr::null_mut());
+        let ptr = GetProcAddress(handle, b"hack\0".as_ptr());
+        let ptr: Option<unsafe fn() -> u64> = std::mem::transmute(ptr);
+        if let Some(f) = ptr {
+            assert!(f() == 998244353);
+            println!("symbol `hack` is found successfully");
+        } else {
+            panic!("symbol `hack` is not found");
+        }
+    }
 }