about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2021-10-07 20:26:11 -0700
committerGitHub <noreply@github.com>2021-10-07 20:26:11 -0700
commit6c17601a2e6fa55e5d2ec7284359bee931c0c61a (patch)
treecb4a16d19fd744ee5bf6bd608b59b5b1c822044b /src/test
parent2b6d7f75f7f5ac0bce2265b0e33256356441ccba (diff)
parent142f6c0b078ceef1dc817c418f628d350551f6e4 (diff)
downloadrust-6c17601a2e6fa55e5d2ec7284359bee931c0c61a.tar.gz
rust-6c17601a2e6fa55e5d2ec7284359bee931c0c61a.zip
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoerister
Implement `#[link_ordinal(n)]`

Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name.  As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL.

Part of #58713.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/Makefile18
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/driver.rs5
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/exporter.c5
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/exporter.def3
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/lib.rs13
-rw-r--r--src/test/run-make/raw-dylib-link-ordinal/output.txt1
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs11
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr19
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.rs13
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.stderr17
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs4
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr8
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs11
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr19
14 files changed, 141 insertions, 6 deletions
diff --git a/src/test/run-make/raw-dylib-link-ordinal/Makefile b/src/test/run-make/raw-dylib-link-ordinal/Makefile
new file mode 100644
index 00000000000..04b257d0632
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/Makefile
@@ -0,0 +1,18 @@
+# Test the behavior of #[link(.., kind = "raw-dylib")] and #[link_ordinal] on windows-msvc
+
+# only-windows-msvc
+
+-include ../../run-make-fulldeps/tools.mk
+
+all:
+	$(call COMPILE_OBJ,"$(TMPDIR)"/exporter.obj,exporter.c)
+	$(CC) "$(TMPDIR)"/exporter.obj exporter.def -link -dll -out:"$(TMPDIR)"/exporter.dll
+	$(RUSTC) --crate-type lib --crate-name raw_dylib_test lib.rs
+	$(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)"
+	"$(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-link-ordinal/driver.rs b/src/test/run-make/raw-dylib-link-ordinal/driver.rs
new file mode 100644
index 00000000000..4059ede11fc
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/driver.rs
@@ -0,0 +1,5 @@
+extern crate raw_dylib_test;
+
+fn main() {
+    raw_dylib_test::library_function();
+}
diff --git a/src/test/run-make/raw-dylib-link-ordinal/exporter.c b/src/test/run-make/raw-dylib-link-ordinal/exporter.c
new file mode 100644
index 00000000000..a9dd6da6616
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/exporter.c
@@ -0,0 +1,5 @@
+#include <stdio.h>
+
+void exported_function() {
+    printf("exported_function\n");
+}
diff --git a/src/test/run-make/raw-dylib-link-ordinal/exporter.def b/src/test/run-make/raw-dylib-link-ordinal/exporter.def
new file mode 100644
index 00000000000..1a4b4c941b6
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/exporter.def
@@ -0,0 +1,3 @@
+LIBRARY exporter
+EXPORTS
+    exported_function @13 NONAME
diff --git a/src/test/run-make/raw-dylib-link-ordinal/lib.rs b/src/test/run-make/raw-dylib-link-ordinal/lib.rs
new file mode 100644
index 00000000000..20609caa5be
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/lib.rs
@@ -0,0 +1,13 @@
+#![feature(raw_dylib)]
+
+#[link(name = "exporter", kind = "raw-dylib")]
+extern {
+    #[link_ordinal(13)]
+    fn imported_function();
+}
+
+pub fn library_function() {
+    unsafe {
+        imported_function();
+    }
+}
diff --git a/src/test/run-make/raw-dylib-link-ordinal/output.txt b/src/test/run-make/raw-dylib-link-ordinal/output.txt
new file mode 100644
index 00000000000..2d0ed60f216
--- /dev/null
+++ b/src/test/run-make/raw-dylib-link-ordinal/output.txt
@@ -0,0 +1 @@
+exported_function
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs
new file mode 100644
index 00000000000..c391ccd1c82
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs
@@ -0,0 +1,11 @@
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete
+
+#[link(name = "foo")]
+extern "C" {
+    #[link_ordinal()]
+    //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr
new file mode 100644
index 00000000000..8e9edfb9d20
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr
@@ -0,0 +1,19 @@
+warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/link-ordinal-missing-argument.rs:1:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+   = note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
+
+error: incorrect number of arguments to `#[link_ordinal]`
+  --> $DIR/link-ordinal-missing-argument.rs:6:5
+   |
+LL |     #[link_ordinal()]
+   |     ^^^^^^^^^^^^^^^^^
+   |
+   = note: the attribute requires exactly one argument
+
+error: aborting due to previous error; 1 warning emitted
+
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.rs
new file mode 100644
index 00000000000..98741212677
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.rs
@@ -0,0 +1,13 @@
+// only-windows-msvc
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete
+
+#[link(name = "foo", kind = "raw-dylib")]
+extern "C" {
+    #[link_ordinal(1)]
+    #[link_ordinal(2)]
+    //~^ ERROR multiple `link_ordinal` attributes on a single definition
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.stderr
new file mode 100644
index 00000000000..a79fb2de944
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.stderr
@@ -0,0 +1,17 @@
+warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/link-ordinal-multiple.rs:2:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+   = note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
+
+error: multiple `link_ordinal` attributes on a single definition
+  --> $DIR/link-ordinal-multiple.rs:8:5
+   |
+LL |     #[link_ordinal(2)]
+   |     ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
index 10db4972970..b6089d27e7a 100644
--- a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
@@ -3,8 +3,8 @@
 
 #[link(name = "foo")]
 extern "C" {
-    #[link_ordinal(18446744073709551616)]
-    //~^ ERROR ordinal value in `link_ordinal` is too large: `18446744073709551616`
+    #[link_ordinal(72436)]
+    //~^ ERROR ordinal value in `link_ordinal` is too large: `72436`
     fn foo();
 }
 
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
index 35f9b53fdf7..bbe985fa10a 100644
--- a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
@@ -7,13 +7,13 @@ LL | #![feature(raw_dylib)]
    = note: `#[warn(incomplete_features)]` on by default
    = note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
 
-error: ordinal value in `link_ordinal` is too large: `18446744073709551616`
+error: ordinal value in `link_ordinal` is too large: `72436`
   --> $DIR/link-ordinal-too-large.rs:6:5
    |
-LL |     #[link_ordinal(18446744073709551616)]
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     #[link_ordinal(72436)]
+   |     ^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: the value may not exceed `usize::MAX`
+   = note: the value may not exceed `u16::MAX`
 
 error: aborting due to previous error; 1 warning emitted
 
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs
new file mode 100644
index 00000000000..93286c616c5
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs
@@ -0,0 +1,11 @@
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete
+
+#[link(name = "foo")]
+extern "C" {
+    #[link_ordinal(3, 4)]
+    //~^ ERROR incorrect number of arguments to `#[link_ordinal]`
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr
new file mode 100644
index 00000000000..484c85a0f42
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr
@@ -0,0 +1,19 @@
+warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/link-ordinal-too-many-arguments.rs:1:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+   = note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
+
+error: incorrect number of arguments to `#[link_ordinal]`
+  --> $DIR/link-ordinal-too-many-arguments.rs:6:5
+   |
+LL |     #[link_ordinal(3, 4)]
+   |     ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the attribute requires exactly one argument
+
+error: aborting due to previous error; 1 warning emitted
+