Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3148b35

Browse files
committedJul 28, 2024
Auto merge of #128079 - Oneirical:testiges-of-civilization, r=jieyouxu
Migrate `static-dylib-by-default`, `sanitizer-dylib-link`, `sanitizer-cdylib-link` and `sanitizer-staticlib-link` `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Please try: try-job: x86_64-msvc try-job: armhf-gnu try-job: test-various try-job: i686-msvc try-job: x86_64-mingw try-job: x86_64-gnu-llvm-18
2 parents 385a74f + 62fb491 commit 3148b35

File tree

9 files changed

+94
-73
lines changed

9 files changed

+94
-73
lines changed
 

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-4
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@ run-make/reproducible-build-2/Makefile
5050
run-make/reproducible-build/Makefile
5151
run-make/rlib-format-packed-bundled-libs-2/Makefile
5252
run-make/rlib-format-packed-bundled-libs/Makefile
53-
run-make/sanitizer-cdylib-link/Makefile
54-
run-make/sanitizer-dylib-link/Makefile
55-
run-make/sanitizer-staticlib-link/Makefile
5653
run-make/share-generics-dylib/Makefile
5754
run-make/simd-ffi/Makefile
5855
run-make/split-debuginfo/Makefile
5956
run-make/stable-symbol-names/Makefile
60-
run-make/static-dylib-by-default/Makefile
6157
run-make/staticlib-dylib-linkage/Makefile
6258
run-make/symbol-mangling-hashed/Makefile
6359
run-make/symbol-visibility/Makefile

‎tests/run-make/sanitizer-cdylib-link/Makefile

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Identical to sanitizer-dylib-link, but with a cdylib.
2+
// This test builds a shared object, then an executable that links it as a native
3+
// rust library (contrast to an rlib). The shared library and executable both
4+
// are compiled with address sanitizer, and we assert that a fault in the cdylib
5+
// is correctly detected.
6+
// See https://github.com/rust-lang/rust/pull/38699
7+
8+
//@ needs-sanitizer-support
9+
//@ needs-sanitizer-address
10+
11+
use run_make_support::{run_fail, rustc};
12+
13+
fn main() {
14+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("cdylib").input("library.rs").run();
15+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("bin").input("program.rs").run();
16+
run_fail("program").assert_stderr_contains("stack-buffer-overflow");
17+
}

‎tests/run-make/sanitizer-dylib-link/Makefile

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This test builds a shared object, then an executable that links it as a native
2+
// rust library (contrast to an rlib). The shared library and executable both
3+
// are compiled with address sanitizer, and we assert that a fault in the dylib
4+
// is correctly detected.
5+
// See https://github.com/rust-lang/rust/pull/38699
6+
7+
//@ needs-sanitizer-support
8+
//@ needs-sanitizer-address
9+
10+
use run_make_support::{run_fail, rustc};
11+
12+
fn main() {
13+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("dylib").input("library.rs").run();
14+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("bin").input("program.rs").run();
15+
run_fail("program").assert_stderr_contains("stack-buffer-overflow");
16+
}

‎tests/run-make/sanitizer-staticlib-link/Makefile

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test first builds a staticlib with AddressSanitizer and checks that
2+
// linking it to an executable fails due to the missing sanitizer runtime.
3+
// It then builds an executable linking to the staticlib and checks that
4+
// the fault in the staticlib is detected correctly.
5+
6+
// Note that checking for the link failure actually checks two things at once:
7+
// 1) That the library has the sanitizer intrumentation
8+
// 2) and that library does not have the sanitizer runtime
9+
// See https://github.com/rust-lang/rust/pull/38699
10+
11+
//@ needs-sanitizer-support
12+
//@ needs-sanitizer-address
13+
14+
use run_make_support::{cc, extra_c_flags, extra_cxx_flags, run_fail, rustc, static_lib_name};
15+
16+
fn main() {
17+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("staticlib").input("library.rs").run();
18+
cc().input("program.c")
19+
.arg(static_lib_name("library"))
20+
.out_exe("program")
21+
.args(extra_c_flags())
22+
.args(extra_cxx_flags())
23+
.run_fail();
24+
rustc().arg("-g").arg("-Zsanitizer=address").crate_type("bin").input("program.rs").run();
25+
run_fail("program").assert_stderr_contains("stack-buffer-overflow");
26+
}

‎tests/run-make/static-dylib-by-default/Makefile

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// If a dylib is being produced, the compiler will first check to see if it can
2+
// be created entirely statically before falling back to dynamic dependencies. This
3+
// behavior can be overridden with `-C prefer-dynamic`.
4+
// In this test, bar depends on foo and is compiled fully statically despite the available
5+
// `foo` dynamic library. This allows the main binary to be executed in the final step.
6+
// See https://github.com/rust-lang/rust/commit/3036b001276a6e43409b08b7f2334ce72aeeb036
7+
8+
//@ ignore-cross-compile
9+
// Reason: the compiled binary is executed
10+
11+
use run_make_support::{
12+
cc, cwd, dynamic_lib_name, extra_c_flags, has_extension, is_msvc, rfs, run, rustc,
13+
shallow_find_files,
14+
};
15+
16+
fn main() {
17+
rustc().input("foo.rs").run();
18+
rustc().input("bar.rs").run();
19+
// On msvc, dynamic libraries are compiled by rustc to:
20+
// bar.dll // dylib
21+
// bar.dll.lib // import library for the dylib
22+
// bar.dll.exp // export library for the dylib
23+
// msvc's underlying link.exe requires the import library for the dynamic library as input.
24+
// That is why the library is bar.dll.lib, not bar.dll.
25+
let library = if is_msvc() { "bar.dll.lib" } else { &dynamic_lib_name("bar") };
26+
cc().input("main.c").out_exe("main").arg(library).args(extra_c_flags()).run();
27+
for rlib in shallow_find_files(cwd(), |path| has_extension(path, "rlib")) {
28+
rfs::remove_file(rlib);
29+
}
30+
rfs::remove_file(dynamic_lib_name("foo"));
31+
if is_msvc() {
32+
rfs::remove_file("foo.dll.lib");
33+
}
34+
run("main");
35+
}

0 commit comments

Comments
 (0)
Failed to load comments.