-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support raw-dylib functions being used inside inlined functions
- Loading branch information
1 parent
758f196
commit 3a1ef50
Showing
12 changed files
with
146 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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,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(); | ||
} | ||
} |
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 @@ | ||
#include <stdio.h> | ||
|
||
__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); | ||
} |
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,6 @@ | ||
#include <stdio.h> | ||
|
||
__declspec(dllexport) void extern_fn_2() { | ||
printf("extern_fn_2 in extern_2\n"); | ||
fflush(stdout); | ||
} |
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,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(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/run-make/raw-dylib-inline-cross-dylib/lib_wrapper.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,6 @@ | ||
extern crate raw_dylib_test; | ||
|
||
#[inline] | ||
pub fn inline_library_function_calls_inline() { | ||
raw_dylib_test::inline_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,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 |