Skip to content

Commit c8f049c

Browse files
committed
rewrite native-link-modifier-whole-archive to rmake
1 parent 4f7f60b commit c8f049c

File tree

3 files changed

+85
-53
lines changed

3 files changed

+85
-53
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ run-make/long-linker-command-lines/Makefile
3434
run-make/macos-deployment-target/Makefile
3535
run-make/min-global-align/Makefile
3636
run-make/native-link-modifier-bundle/Makefile
37-
run-make/native-link-modifier-whole-archive/Makefile
3837
run-make/no-alloc-shim/Makefile
3938
run-make/no-builtins-attribute/Makefile
4039
run-make/pdb-buildinfo-cl-cmd/Makefile

tests/run-make/native-link-modifier-whole-archive/Makefile

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// This test case makes sure that native libraries are linked with appropriate semantics
2+
// when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
3+
// The test works by checking that the resulting executables produce the expected output,
4+
// part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
5+
// that code would never make it into the final executable and we'd thus be missing some
6+
// of the output.
7+
// See https://github.com/rust-lang/rust/issues/88085
8+
9+
//@ ignore-cross-compile
10+
// Reason: compiling C++ code does not work well when cross-compiling
11+
// plus, the compiled binary is executed
12+
13+
use run_make_support::{cxx, is_msvc, llvm_ar, run, run_with_args, rustc, static_lib_name};
14+
15+
fn main() {
16+
let mut cxx = cxx();
17+
if is_msvc() {
18+
cxx.arg("-EHs");
19+
}
20+
cxx.input("c_static_lib_with_constructor.cpp")
21+
.arg("-c")
22+
.out_exe("libc_static_lib_with_constructor")
23+
.run();
24+
25+
let mut llvm_ar = llvm_ar();
26+
llvm_ar.obj_to_ar();
27+
if is_msvc() {
28+
llvm_ar
29+
.output_input(
30+
static_lib_name("c_static_lib_with_constructor"),
31+
"libc_static_lib_with_constructor.obj",
32+
)
33+
.run();
34+
} else {
35+
llvm_ar
36+
.output_input(
37+
static_lib_name("c_static_lib_with_constructor"),
38+
"libc_static_lib_with_constructor",
39+
)
40+
.run();
41+
}
42+
43+
// Native lib linked directly into executable
44+
rustc()
45+
.input("directly_linked.rs")
46+
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
47+
.run();
48+
49+
// Native lib linked into test executable, +whole-archive
50+
rustc()
51+
.input("directly_linked_test_plus_whole_archive.rs")
52+
.arg("--test")
53+
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
54+
.run();
55+
56+
// Native lib linked into test executable, -whole-archive
57+
rustc()
58+
.input("directly_linked_test_minus_whole_archive.rs")
59+
.arg("--test")
60+
.arg("-lstatic:-whole-archive=c_static_lib_with_constructor")
61+
.run();
62+
63+
// Native lib linked into rlib with via commandline
64+
rustc()
65+
.input("rlib_with_cmdline_native_lib.rs")
66+
.crate_type("rlib")
67+
.arg("-lstatic:-bundle,+whole-archive=c_static_lib_with_constructor")
68+
.run();
69+
// Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
70+
rustc().input("indirectly_linked.rs").run();
71+
72+
// Native lib linked into rlib via `#[link()]` attribute on extern block.
73+
rustc().input("native_lib_in_src.rs").crate_type("rlib").run();
74+
// Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
75+
rustc().input("indirectly_linked_via_attr.rs").run();
76+
77+
run("directly_linked").assert_stdout_contains("static-initializer.directly_linked.");
78+
run_with_args("directly_linked_test_plus_whole_archive", &["--nocapture"])
79+
.assert_stdout_contains("static-initializer.");
80+
run_with_args("directly_linked_test_minus_whole_archive", &["--nocapture"])
81+
.assert_stdout_not_contains("static-initializer.");
82+
run("indirectly_linked").assert_stdout_contains("static-initializer.indirectly_linked.");
83+
run("indirectly_linked_via_attr")
84+
.assert_stdout_contains("static-initializer.native_lib_in_src.");
85+
}

0 commit comments

Comments
 (0)