Skip to content

Commit c4840ca

Browse files
dcsommerMark-Simulacrum
authored andcommitted
Fix backwards-compatibility check for tests with +whole-archive
Fixes rust-lang#100066
1 parent f1174bd commit c4840ca

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ fn add_local_native_libraries(
22222222
// be added explicitly if necessary, see the error in `fn link_rlib`) compiled
22232223
// as an executable due to `--test`. Use whole-archive implicitly, like before
22242224
// the introduction of native lib modifiers.
2225-
|| (bundle != Some(false) && sess.opts.test)
2225+
|| (whole_archive == None && bundle != Some(false) && sess.opts.test)
22262226
{
22272227
cmd.link_whole_staticlib(
22282228
name,

src/test/run-make/native-link-modifier-whole-archive/Makefile

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ignore-cross-compile -- compiling C++ code does not work well when cross-compiling
22

3-
# This test case makes sure that native libraries are linked with --whole-archive semantics
4-
# when the `-bundle,+whole-archive` modifiers are applied to them.
3+
# This test case makes sure that native libraries are linked with appropriate semantics
4+
# when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
55
#
66
# The test works by checking that the resulting executables produce the expected output,
77
# part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
@@ -10,15 +10,28 @@
1010

1111
-include ../../run-make-fulldeps/tools.mk
1212

13-
all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linked) $(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
13+
all: $(TMPDIR)/$(call BIN,directly_linked) \
14+
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive) \
15+
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive) \
16+
$(TMPDIR)/$(call BIN,indirectly_linked) \
17+
$(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
1418
$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.'
19+
$(call RUN,directly_linked_test_plus_whole_archive) --nocapture | $(CGREP) 'static-initializer.'
20+
$(call RUN,directly_linked_test_minus_whole_archive) --nocapture | $(CGREP) -v 'static-initializer.'
1521
$(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.'
1622
$(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.'
1723

1824
# Native lib linked directly into executable
1925
$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
2026
$(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor
2127

28+
# Native lib linked into test executable, +whole-archive
29+
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
30+
$(RUSTC) directly_linked_test_plus_whole_archive.rs --test -l static:+whole-archive=c_static_lib_with_constructor
31+
# Native lib linked into test executable, -whole-archive
32+
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
33+
$(RUSTC) directly_linked_test_minus_whole_archive.rs --test -l static:-whole-archive=c_static_lib_with_constructor
34+
2235
# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
2336
$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
2437
$(RUSTC) indirectly_linked.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::io::Write;
2+
3+
#[test]
4+
fn test_thing() {
5+
print!("ran the test");
6+
std::io::stdout().flush().unwrap();
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::io::Write;
2+
3+
#[test]
4+
fn test_thing() {
5+
print!("ran the test");
6+
std::io::stdout().flush().unwrap();
7+
}

0 commit comments

Comments
 (0)