diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-11 12:20:33 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-11 12:20:33 -0700 |
| commit | e6072fa0c4c22d62acf3dcb78c8ee260a1368bd7 (patch) | |
| tree | d315f98d14a09983abbd05f8ffdc22beb3666dbf /src/test/run-make/interdependent-c-libraries | |
| parent | 8b6091e8f1f5531fe907f84b6a2b27af04a95e8f (diff) | |
| download | rust-e6072fa0c4c22d62acf3dcb78c8ee260a1368bd7.tar.gz rust-e6072fa0c4c22d62acf3dcb78c8ee260a1368bd7.zip | |
rustc: Deterministically link upstream C libraries
Previously, upstream C libraries were linked in a nondeterministic fashion because they were collected through iter_crate_data() which is a nodeterministic traversal of a hash map. When upstream rlibs had interdependencies among their native libraries (such as libfoo depending on libc), then the ordering would occasionally be wrong, causing linkage to fail. This uses the topologically sorted list of libraries to collect native libraries, so if a native library depends on libc it just needs to make sure that the rust crate depends on liblibc.
Diffstat (limited to 'src/test/run-make/interdependent-c-libraries')
6 files changed, 78 insertions, 0 deletions
diff --git a/src/test/run-make/interdependent-c-libraries/Makefile b/src/test/run-make/interdependent-c-libraries/Makefile new file mode 100644 index 00000000000..7654917b462 --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/Makefile @@ -0,0 +1,15 @@ +-include ../tools.mk + +# The rust crate foo will link to the native library foo, while the rust crate +# bar will link to the native library bar. There is also a dependency between +# the native library bar to the natibe library foo. +# +# This test ensures that the ordering of -lfoo and -lbar on the command line is +# correct to complete the linkage. If passed as "-lfoo -lbar", then the 'foo' +# library will be stripped out, and the linkage will fail. + +all: $(call STATICLIB,foo) $(call STATICLIB,bar) + $(RUSTC) foo.rs + $(RUSTC) bar.rs + $(RUSTC) main.rs -Z print-link-args + diff --git a/src/test/run-make/interdependent-c-libraries/bar.c b/src/test/run-make/interdependent-c-libraries/bar.c new file mode 100644 index 00000000000..812c9753528 --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/bar.c @@ -0,0 +1,3 @@ +void foo(); + +void bar() { foo(); } diff --git a/src/test/run-make/interdependent-c-libraries/bar.rs b/src/test/run-make/interdependent-c-libraries/bar.rs new file mode 100644 index 00000000000..5311af2959b --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/bar.rs @@ -0,0 +1,23 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +extern crate foo; + +#[link(name = "bar")] +extern { + fn bar(); +} + +pub fn doit() { + unsafe { bar(); } +} + diff --git a/src/test/run-make/interdependent-c-libraries/foo.c b/src/test/run-make/interdependent-c-libraries/foo.c new file mode 100644 index 00000000000..85e6cd8c390 --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/foo.c @@ -0,0 +1 @@ +void foo() {} diff --git a/src/test/run-make/interdependent-c-libraries/foo.rs b/src/test/run-make/interdependent-c-libraries/foo.rs new file mode 100644 index 00000000000..f94c6edb97d --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/foo.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +#[link(name = "foo")] +extern { + fn foo(); +} + +pub fn doit() { + unsafe { foo(); } +} diff --git a/src/test/run-make/interdependent-c-libraries/main.rs b/src/test/run-make/interdependent-c-libraries/main.rs new file mode 100644 index 00000000000..f42e3dd44a9 --- /dev/null +++ b/src/test/run-make/interdependent-c-libraries/main.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate foo; +extern crate bar; + +fn main() { + bar::doit(); +} |
