forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#89025 - ricobbe:raw-dylib-link-ordinal, r=m…
…ichaelwoerister 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 rust-lang#58713.
- Loading branch information
Showing
20 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate raw_dylib_test; | ||
|
||
fn main() { | ||
raw_dylib_test::library_function(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stdio.h> | ||
|
||
void exported_function() { | ||
printf("exported_function\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
LIBRARY exporter | ||
EXPORTS | ||
exported_function @13 NONAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exported_function |
11 changes: 11 additions & 0 deletions
11
src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/rfc-2627-raw-dylib/link-ordinal-missing-argument.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/rfc-2627-raw-dylib/link-ordinal-multiple.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-many-arguments.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|