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 62fb491

Browse files
committedJul 26, 2024
rewrite sanitizer-staticlib-link to rmake
1 parent d224256 commit 62fb491

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed
 

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

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ run-make/reproducible-build-2/Makefile
7070
run-make/reproducible-build/Makefile
7171
run-make/rlib-format-packed-bundled-libs-2/Makefile
7272
run-make/rlib-format-packed-bundled-libs/Makefile
73-
run-make/sanitizer-staticlib-link/Makefile
7473
run-make/share-generics-dylib/Makefile
7574
run-make/simd-ffi/Makefile
7675
run-make/split-debuginfo/Makefile

‎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/rmake.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@
77

88
//@ ignore-cross-compile
99
// Reason: the compiled binary is executed
10-
//FIXME(Oneirical): try on msvc, not because of an ignore but because i did wonky things
1110

1211
use run_make_support::{
13-
cc, cwd, dynamic_lib_name, extra_c_flags, has_extension, rfs, run, rustc, shallow_find_files,
12+
cc, cwd, dynamic_lib_name, extra_c_flags, has_extension, is_msvc, rfs, run, rustc,
13+
shallow_find_files,
1414
};
1515

1616
fn main() {
1717
rustc().input("foo.rs").run();
1818
rustc().input("bar.rs").run();
19-
cc().input("main.c").out_exe("main").arg(dynamic_lib_name("bar")).args(extra_c_flags()).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();
2027
for rlib in shallow_find_files(cwd(), |path| has_extension(path, "rlib")) {
2128
rfs::remove_file(rlib);
2229
}
2330
rfs::remove_file(dynamic_lib_name("foo"));
31+
if is_msvc() {
32+
rfs::remove_file("foo.dll.lib");
33+
}
2434
run("main");
2535
}

0 commit comments

Comments
 (0)
Failed to load comments.