Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
8b6091e
commit e6072fa
Showing
7 changed files
with
92 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
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,3 @@ | ||
void foo(); | ||
|
||
void bar() { foo(); } |
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,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(); } | ||
} | ||
|
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 @@ | ||
void foo() {} |
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,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(); } | ||
} |
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,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(); | ||
} |
e6072fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from brson
at alexcrichton@e6072fa
e6072fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging alexcrichton/rust/c-linkage-oh-my = e6072fa into auto
e6072fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alexcrichton/rust/c-linkage-oh-my = e6072fa merged ok, testing candidate = 2f79054
e6072fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5212
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5209
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4302
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4315
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5311
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4398
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4406
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5313
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4398
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4403
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/4468
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2198
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/5309
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/4405
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/4418
e6072fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 2f79054