summaryrefslogtreecommitdiffstats
path: root/src/test/run-make/raw-dylib-import-name-type
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/run-make/raw-dylib-import-name-type')
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/Makefile22
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/driver.rs125
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/extern.c103
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/extern.gnu.def21
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/extern.msvc.def25
-rw-r--r--src/test/run-make/raw-dylib-import-name-type/output.txt19
6 files changed, 315 insertions, 0 deletions
diff --git a/src/test/run-make/raw-dylib-import-name-type/Makefile b/src/test/run-make/raw-dylib-import-name-type/Makefile
new file mode 100644
index 000000000..fcc60e88e
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/Makefile
@@ -0,0 +1,22 @@
+# Test the behavior of #[link(.., kind = "raw-dylib")] with alternative calling conventions.
+
+# only-x86
+# only-windows
+
+-include ../../run-make-fulldeps/tools.mk
+
+all:
+ $(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)"
+ $(call COMPILE_OBJ,"$(TMPDIR)"/extern.obj,extern.c)
+ifdef IS_MSVC
+ $(CC) "$(TMPDIR)"/extern.obj extern.msvc.def -link -dll -out:"$(TMPDIR)"/extern.dll -noimplib
+else
+ $(CC) "$(TMPDIR)"/extern.obj extern.gnu.def --no-leading-underscore -shared -o "$(TMPDIR)"/extern.dll
+endif
+ "$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt
+
+ifdef RUSTC_BLESS_TEST
+ cp "$(TMPDIR)"/output.txt output.txt
+else
+ $(DIFF) output.txt "$(TMPDIR)"/output.txt
+endif
diff --git a/src/test/run-make/raw-dylib-import-name-type/driver.rs b/src/test/run-make/raw-dylib-import-name-type/driver.rs
new file mode 100644
index 000000000..a38849fc8
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/driver.rs
@@ -0,0 +1,125 @@
+#![feature(raw_dylib)]
+#![feature(abi_vectorcall)]
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")]
+extern "C" {
+ fn cdecl_fn_undecorated(i: i32);
+ #[link_name = "cdecl_fn_undecorated2"]
+ fn cdecl_fn_undecorated_renamed(i: i32);
+ static mut extern_variable_undecorated: i32;
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "noprefix")]
+extern "C" {
+ fn cdecl_fn_noprefix(i: i32);
+ static mut extern_variable_noprefix: i32;
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "decorated")]
+extern "C" {
+ fn cdecl_fn_decorated(i: i32);
+ static mut extern_variable_decorated: i32;
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")]
+extern "stdcall" {
+ fn stdcall_fn_undecorated(i: i32);
+ #[link_name = "stdcall_fn_undecorated2"]
+ fn stdcall_fn_undecorated_renamed(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "noprefix")]
+extern "stdcall" {
+ fn stdcall_fn_noprefix(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "decorated")]
+extern "stdcall" {
+ fn stdcall_fn_decorated(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")]
+extern "fastcall" {
+ fn fastcall_fn_undecorated(i: i32);
+ #[link_name = "fastcall_fn_undecorated2"]
+ fn fastcall_fn_undecorated_renamed(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "noprefix")]
+extern "fastcall" {
+ fn fastcall_fn_noprefix(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "decorated")]
+extern "fastcall" {
+ fn fastcall_fn_decorated(i: i32);
+}
+
+#[cfg(target_env = "msvc")]
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")]
+extern "vectorcall" {
+ fn vectorcall_fn_undecorated(i: i32);
+ #[link_name = "vectorcall_fn_undecorated2"]
+ fn vectorcall_fn_undecorated_renamed(i: i32);
+}
+
+#[cfg(target_env = "msvc")]
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "noprefix")]
+extern "vectorcall" {
+ fn vectorcall_fn_noprefix(i: i32);
+}
+
+#[cfg(target_env = "msvc")]
+#[link(name = "extern", kind = "raw-dylib", import_name_type = "decorated")]
+extern "vectorcall" {
+ fn vectorcall_fn_decorated(i: i32);
+}
+
+#[link(name = "extern", kind = "raw-dylib")]
+extern {
+ fn print_extern_variable_undecorated();
+ fn print_extern_variable_noprefix();
+ fn print_extern_variable_decorated();
+}
+
+pub fn main() {
+ unsafe {
+ cdecl_fn_undecorated(1);
+ cdecl_fn_undecorated_renamed(10);
+ cdecl_fn_noprefix(2);
+ cdecl_fn_decorated(3);
+
+ stdcall_fn_undecorated(4);
+ stdcall_fn_undecorated_renamed(14);
+ stdcall_fn_noprefix(5);
+ stdcall_fn_decorated(6);
+
+ fastcall_fn_undecorated(7);
+ fastcall_fn_undecorated_renamed(17);
+ fastcall_fn_noprefix(8);
+ fastcall_fn_decorated(9);
+
+ extern_variable_undecorated = 42;
+ print_extern_variable_undecorated();
+ extern_variable_noprefix = 43;
+ print_extern_variable_noprefix();
+ extern_variable_decorated = 44;
+ print_extern_variable_decorated();
+
+ // GCC doesn't support vectorcall: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
+ #[cfg(target_env = "msvc")]
+ {
+ vectorcall_fn_undecorated(10);
+ vectorcall_fn_undecorated_renamed(20);
+ vectorcall_fn_noprefix(11);
+ vectorcall_fn_decorated(12);
+ }
+ #[cfg(not(target_env = "msvc"))]
+ {
+ println!("vectorcall_fn_undecorated(10)");
+ println!("vectorcall_fn_undecorated2(20)");
+ println!("vectorcall_fn_noprefix(11)");
+ println!("vectorcall_fn_decorated(12)");
+ }
+ }
+}
diff --git a/src/test/run-make/raw-dylib-import-name-type/extern.c b/src/test/run-make/raw-dylib-import-name-type/extern.c
new file mode 100644
index 000000000..195126d51
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/extern.c
@@ -0,0 +1,103 @@
+#include <stdio.h>
+#include <stdint.h>
+
+void _cdecl cdecl_fn_undecorated(int i) {
+ printf("cdecl_fn_undecorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void _cdecl cdecl_fn_undecorated2(int i) {
+ printf("cdecl_fn_undecorated2(%d)\n", i);
+ fflush(stdout);
+}
+
+void _cdecl cdecl_fn_noprefix(int i) {
+ printf("cdecl_fn_noprefix(%d)\n", i);
+ fflush(stdout);
+}
+
+void _cdecl cdecl_fn_decorated(int i) {
+ printf("cdecl_fn_decorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void __stdcall stdcall_fn_undecorated(int i) {
+ printf("stdcall_fn_undecorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void __stdcall stdcall_fn_undecorated2(int i) {
+ printf("stdcall_fn_undecorated2(%d)\n", i);
+ fflush(stdout);
+}
+
+void __stdcall stdcall_fn_noprefix(int i) {
+ printf("stdcall_fn_noprefix(%d)\n", i);
+ fflush(stdout);
+}
+
+void __stdcall stdcall_fn_decorated(int i) {
+ printf("stdcall_fn_decorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void __fastcall fastcall_fn_undecorated(int i) {
+ printf("fastcall_fn_undecorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void __fastcall fastcall_fn_undecorated2(int i) {
+ printf("fastcall_fn_undecorated2(%d)\n", i);
+ fflush(stdout);
+}
+
+void __fastcall fastcall_fn_noprefix(int i) {
+ printf("fastcall_fn_noprefix(%d)\n", i);
+ fflush(stdout);
+}
+
+void __fastcall fastcall_fn_decorated(int i) {
+ printf("fastcall_fn_decorated(%d)\n", i);
+ fflush(stdout);
+}
+
+int extern_variable_undecorated = 0;
+__declspec(dllexport) void print_extern_variable_undecorated() {
+ printf("extern_variable_undecorated value: %d\n", extern_variable_undecorated);
+ fflush(stdout);
+}
+
+int extern_variable_noprefix = 0;
+__declspec(dllexport) void print_extern_variable_noprefix() {
+ printf("extern_variable_noprefix value: %d\n", extern_variable_noprefix);
+ fflush(stdout);
+}
+
+int extern_variable_decorated = 0;
+__declspec(dllexport) void print_extern_variable_decorated() {
+ printf("extern_variable_decorated value: %d\n", extern_variable_decorated);
+ fflush(stdout);
+}
+
+// GCC doesn't support vectorcall: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
+#ifdef _MSC_VER
+void __vectorcall vectorcall_fn_undecorated(int i) {
+ printf("vectorcall_fn_undecorated(%d)\n", i);
+ fflush(stdout);
+}
+
+void __vectorcall vectorcall_fn_undecorated2(int i) {
+ printf("vectorcall_fn_undecorated2(%d)\n", i);
+ fflush(stdout);
+}
+
+void __vectorcall vectorcall_fn_noprefix(int i) {
+ printf("vectorcall_fn_noprefix(%d)\n", i);
+ fflush(stdout);
+}
+
+void __vectorcall vectorcall_fn_decorated(int i) {
+ printf("vectorcall_fn_decorated(%d)\n", i);
+ fflush(stdout);
+}
+#endif
diff --git a/src/test/run-make/raw-dylib-import-name-type/extern.gnu.def b/src/test/run-make/raw-dylib-import-name-type/extern.gnu.def
new file mode 100644
index 000000000..a523c959a
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/extern.gnu.def
@@ -0,0 +1,21 @@
+LIBRARY extern
+EXPORTS
+ cdecl_fn_undecorated
+ cdecl_fn_undecorated2
+ cdecl_fn_noprefix
+ cdecl_fn_decorated
+ stdcall_fn_undecorated
+ stdcall_fn_undecorated2
+ stdcall_fn_noprefix@4
+ fastcall_fn_undecorated
+ fastcall_fn_undecorated2
+ @fastcall_fn_decorated@4
+
+ ;ld doesn't handle fully-decorated stdcall, or no-prefix fastcall
+ _stdcall_fn_decorated@4=stdcall_fn_decorated@4
+ fastcall_fn_noprefix@4=@fastcall_fn_noprefix@4
+
+ ;Variables are never decorated
+ extern_variable_undecorated
+ extern_variable_noprefix
+ extern_variable_decorated
diff --git a/src/test/run-make/raw-dylib-import-name-type/extern.msvc.def b/src/test/run-make/raw-dylib-import-name-type/extern.msvc.def
new file mode 100644
index 000000000..dbff32d4c
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/extern.msvc.def
@@ -0,0 +1,25 @@
+LIBRARY extern
+EXPORTS
+ cdecl_fn_undecorated
+ cdecl_fn_undecorated2
+ cdecl_fn_noprefix
+ cdecl_fn_decorated
+ stdcall_fn_undecorated
+ stdcall_fn_undecorated2
+ _stdcall_fn_decorated@4
+ fastcall_fn_undecorated
+ fastcall_fn_undecorated2
+ @fastcall_fn_decorated@4
+ vectorcall_fn_undecorated
+ vectorcall_fn_undecorated2
+ vectorcall_fn_decorated@@4
+ vectorcall_fn_noprefix@@4
+
+ ;MSVC doesn't seem to recognize the "no prefix" syntax.
+ stdcall_fn_noprefix@4=_stdcall_fn_noprefix@4
+ fastcall_fn_noprefix@4=@fastcall_fn_noprefix@4
+
+ ;Variables are never decorated
+ extern_variable_undecorated
+ extern_variable_noprefix
+ extern_variable_decorated
diff --git a/src/test/run-make/raw-dylib-import-name-type/output.txt b/src/test/run-make/raw-dylib-import-name-type/output.txt
new file mode 100644
index 000000000..707faf403
--- /dev/null
+++ b/src/test/run-make/raw-dylib-import-name-type/output.txt
@@ -0,0 +1,19 @@
+cdecl_fn_undecorated(1)
+cdecl_fn_undecorated2(10)
+cdecl_fn_noprefix(2)
+cdecl_fn_decorated(3)
+stdcall_fn_undecorated(4)
+stdcall_fn_undecorated2(14)
+stdcall_fn_noprefix(5)
+stdcall_fn_decorated(6)
+fastcall_fn_undecorated(7)
+fastcall_fn_undecorated2(17)
+fastcall_fn_noprefix(8)
+fastcall_fn_decorated(9)
+extern_variable_undecorated value: 42
+extern_variable_noprefix value: 43
+extern_variable_decorated value: 44
+vectorcall_fn_undecorated(10)
+vectorcall_fn_undecorated2(20)
+vectorcall_fn_noprefix(11)
+vectorcall_fn_decorated(12)