From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../run-make/raw-dylib-inline-cross-dylib/Makefile | 31 ++++++++++++++++++++++ .../raw-dylib-inline-cross-dylib/driver.rs | 21 +++++++++++++++ .../raw-dylib-inline-cross-dylib/extern_1.c | 11 ++++++++ .../raw-dylib-inline-cross-dylib/extern_2.c | 6 +++++ tests/run-make/raw-dylib-inline-cross-dylib/lib.rs | 21 +++++++++++++++ .../raw-dylib-inline-cross-dylib/lib_wrapper.rs | 6 +++++ .../raw-dylib-inline-cross-dylib/output.txt | 6 +++++ 7 files changed, 102 insertions(+) create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/Makefile create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/driver.rs create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/extern_1.c create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/extern_2.c create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/lib.rs create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/lib_wrapper.rs create mode 100644 tests/run-make/raw-dylib-inline-cross-dylib/output.txt (limited to 'tests/run-make/raw-dylib-inline-cross-dylib') diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/Makefile b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile new file mode 100644 index 000000000..9e603f958 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/Makefile @@ -0,0 +1,31 @@ +# Regression test for calling an inline function that uses a raw-dylib function. + +# only-windows + +include ../../run-make-fulldeps/tools.mk + +all: + $(RUSTC) --crate-type dylib --crate-name raw_dylib_test lib.rs -C prefer-dynamic + $(RUSTC) --crate-type dylib --crate-name raw_dylib_test_wrapper lib_wrapper.rs -C prefer-dynamic + $(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)" -C prefer-dynamic + # Make sure we don't find an import to the functions we expect to be inlined. + "$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function" + "$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -v -e "inline_library_function_calls_inline" + # Make sure we do find an import to the functions we expect to be imported. + "$(LLVM_BIN_DIR)"/llvm-objdump -p $(TMPDIR)/driver.exe | $(CGREP) -e "library_function" + $(call COMPILE_OBJ,"$(TMPDIR)"/extern_1.obj,extern_1.c) + $(call COMPILE_OBJ,"$(TMPDIR)"/extern_2.obj,extern_2.c) +ifdef IS_MSVC + $(CC) "$(TMPDIR)"/extern_1.obj -link -dll -out:"$(TMPDIR)"/extern_1.dll -noimplib + $(CC) "$(TMPDIR)"/extern_2.obj -link -dll -out:"$(TMPDIR)"/extern_2.dll -noimplib +else + $(CC) "$(TMPDIR)"/extern_1.obj -shared -o "$(TMPDIR)"/extern_1.dll + $(CC) "$(TMPDIR)"/extern_2.obj -shared -o "$(TMPDIR)"/extern_2.dll +endif + $(call RUN,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/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs b/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs new file mode 100644 index 000000000..f72ded7d9 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs @@ -0,0 +1,21 @@ +#![feature(raw_dylib)] + +extern crate raw_dylib_test; +extern crate raw_dylib_test_wrapper; + +#[link(name = "extern_2", kind = "raw-dylib")] +extern { + fn extern_fn_2(); +} + +fn main() { + // NOTE: The inlined call to `extern_fn_2` links against the function in extern_2.dll instead + // of extern_1.dll since raw-dylib symbols from the current crate are passed to the linker + // first, so any ambiguous names will prefer the current crate's definition. + raw_dylib_test::inline_library_function(); + raw_dylib_test::library_function(); + raw_dylib_test_wrapper::inline_library_function_calls_inline(); + unsafe { + extern_fn_2(); + } +} diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/extern_1.c b/tests/run-make/raw-dylib-inline-cross-dylib/extern_1.c new file mode 100644 index 000000000..e5baaf5f0 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/extern_1.c @@ -0,0 +1,11 @@ +#include + +__declspec(dllexport) void extern_fn_1() { + printf("extern_fn_1\n"); + fflush(stdout); +} + +__declspec(dllexport) void extern_fn_2() { + printf("extern_fn_2 in extern_1\n"); + fflush(stdout); +} diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/extern_2.c b/tests/run-make/raw-dylib-inline-cross-dylib/extern_2.c new file mode 100644 index 000000000..30aa46922 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/extern_2.c @@ -0,0 +1,6 @@ +#include + +__declspec(dllexport) void extern_fn_2() { + printf("extern_fn_2 in extern_2\n"); + fflush(stdout); +} diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs b/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs new file mode 100644 index 000000000..00c2c1c42 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs @@ -0,0 +1,21 @@ +#![feature(raw_dylib)] + +#[link(name = "extern_1", kind = "raw-dylib")] +extern { + fn extern_fn_1(); + fn extern_fn_2(); +} + +#[inline] +pub fn inline_library_function() { + unsafe { + extern_fn_1(); + extern_fn_2(); + } +} + +pub fn library_function() { + unsafe { + extern_fn_2(); + } +} diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/lib_wrapper.rs b/tests/run-make/raw-dylib-inline-cross-dylib/lib_wrapper.rs new file mode 100644 index 000000000..47191b8de --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/lib_wrapper.rs @@ -0,0 +1,6 @@ +extern crate raw_dylib_test; + +#[inline] +pub fn inline_library_function_calls_inline() { + raw_dylib_test::inline_library_function(); +} diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/output.txt b/tests/run-make/raw-dylib-inline-cross-dylib/output.txt new file mode 100644 index 000000000..e7009baa0 --- /dev/null +++ b/tests/run-make/raw-dylib-inline-cross-dylib/output.txt @@ -0,0 +1,6 @@ +extern_fn_1 +extern_fn_2 in extern_2 +extern_fn_2 in extern_1 +extern_fn_1 +extern_fn_2 in extern_2 +extern_fn_2 in extern_2 -- cgit v1.2.3