-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of +whole-archive native link modifier.
- Loading branch information
1 parent
896f058
commit fc53fff
Showing
9 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/run-make/native-link-modifier-whole-archive/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This test case makes sure that native libraries are linked with --whole-archive 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 | ||
# that code would never make it into the final executable and we'd thus be missing some | ||
# of the output. | ||
|
||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linked) $(TMPDIR)/$(call BIN,indirectly_linked_via_attr) | ||
$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.' | ||
$(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 -Z unstable-options -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 | ||
|
||
# Native lib linked into RLIB via #[link] attribute, RLIB linked into executable | ||
$(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src.rlib | ||
$(RUSTC) indirectly_linked_via_attr.rs | ||
|
||
# Native lib linked into rlib with via commandline | ||
$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) | ||
$(RUSTC) rlib_with_cmdline_native_lib.rs -Z unstable-options --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor | ||
|
||
# Native lib linked into rlib via `#[link()]` attribute on extern block. | ||
$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) | ||
$(RUSTC) native_lib_in_src.rs --crate-type=rlib | ||
|
||
$(TMPDIR)/libc_static_lib_with_constructor.o: c_static_lib_with_constructor.cpp | ||
$(call COMPILE_OBJ_CXX,$@,$<) |
11 changes: 11 additions & 0 deletions
11
src/test/run-make/native-link-modifier-whole-archive/c_static_lib_with_constructor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <cstdio> | ||
|
||
// Since this is a global variable, its constructor will be called before | ||
// main() is executed. But only if the object file containing it actually | ||
// gets linked into the executable. | ||
struct Foo { | ||
Foo() { | ||
printf("static-initializer."); | ||
fflush(stdout); | ||
} | ||
} FOO; |
6 changes: 6 additions & 0 deletions
6
src/test/run-make/native-link-modifier-whole-archive/directly_linked.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::io::Write; | ||
|
||
fn main() { | ||
print!("directly_linked."); | ||
std::io::stdout().flush().unwrap(); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/run-make/native-link-modifier-whole-archive/indirectly_linked.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate rlib_with_cmdline_native_lib; | ||
|
||
fn main() { | ||
rlib_with_cmdline_native_lib::hello(); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/run-make/native-link-modifier-whole-archive/indirectly_linked_via_attr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate native_lib_in_src; | ||
|
||
fn main() { | ||
native_lib_in_src::hello(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![feature(native_link_modifiers_bundle)] | ||
#![feature(native_link_modifiers_whole_archive)] | ||
#![feature(native_link_modifiers)] | ||
|
||
use std::io::Write; | ||
|
||
#[link(name = "c_static_lib_with_constructor", | ||
kind = "static", | ||
modifiers = "-bundle,+whole-archive")] | ||
extern {} | ||
|
||
pub fn hello() { | ||
print!("native_lib_in_src."); | ||
std::io::stdout().flush().unwrap(); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/run-make/native-link-modifier-whole-archive/rlib_with_cmdline_native_lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::io::Write; | ||
|
||
pub fn hello() { | ||
print!("indirectly_linked."); | ||
std::io::stdout().flush().unwrap(); | ||
} |