Skip to content

Commit

Permalink
Rollup merge of rust-lang#100068 - dcsommer:master, r=petrochenkov
Browse files Browse the repository at this point in the history
Fix backwards-compatibility check for tests with `+whole-archive`

Fixes rust-lang#100066
  • Loading branch information
matthiaskrgr committed Aug 3, 2022
2 parents 6a987f5 + 9cf556d commit 5a5f499
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ fn add_local_native_libraries(
// be added explicitly if necessary, see the error in `fn link_rlib`) compiled
// as an executable due to `--test`. Use whole-archive implicitly, like before
// the introduction of native lib modifiers.
|| (bundle != Some(false) && sess.opts.test)
|| (whole_archive == None && bundle != Some(false) && sess.opts.test)
{
cmd.link_whole_staticlib(
name,
Expand Down
19 changes: 16 additions & 3 deletions src/test/run-make/native-link-modifier-whole-archive/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ignore-cross-compile -- compiling C++ code does not work well when cross-compiling

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

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

all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linked) $(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
all: $(TMPDIR)/$(call BIN,directly_linked) \
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive) \
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive) \
$(TMPDIR)/$(call BIN,indirectly_linked) \
$(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.'
$(call RUN,directly_linked_test_plus_whole_archive) --nocapture | $(CGREP) 'static-initializer.'
$(call RUN,directly_linked_test_minus_whole_archive) --nocapture | $(CGREP) -v 'static-initializer.'
$(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.'
$(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.'

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

# Native lib linked into test executable, +whole-archive
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
$(RUSTC) directly_linked_test_plus_whole_archive.rs --test -l static:+whole-archive=c_static_lib_with_constructor
# Native lib linked into test executable, -whole-archive
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
$(RUSTC) directly_linked_test_minus_whole_archive.rs --test -l static:-whole-archive=c_static_lib_with_constructor

# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
$(RUSTC) indirectly_linked.rs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::io::Write;

#[test]
fn test_thing() {
print!("ran the test");
std::io::stdout().flush().unwrap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::io::Write;

#[test]
fn test_thing() {
print!("ran the test");
std::io::stdout().flush().unwrap();
}

0 comments on commit 5a5f499

Please sign in to comment.