Skip to content

Commit

Permalink
rustc: Always link compiler-builtins last
Browse files Browse the repository at this point in the history
All crates depend on compiler-builtins, so we need to always include the crate
last.
  • Loading branch information
alexcrichton committed Sep 13, 2016
1 parent 521ffe9 commit 2140c4b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,17 +926,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
// crates.
let deps = sess.cstore.used_crates(LinkagePreference::RequireDynamic);

let mut compiler_builtins = None;

for &(cnum, _) in &deps {
// We may not pass all crates through to the linker. Some crates may
// appear statically in an existing dylib, meaning we'll pick up all the
// symbols from the dylib.
let src = sess.cstore.used_crate_source(cnum);
match data[cnum as usize - 1] {
// We must always link the `compiler_builtins` crate statically. Even if it was already
// "included" in a dylib (e.g. `libstd` when `-C prefer-dynamic` is used)
// compiler-builtins are always placed last to ensure that they're
// linked correctly.
_ if sess.cstore.is_compiler_builtins(cnum) => {
add_static_crate(cmd, sess, tmpdir, crate_type,
&src.rlib.unwrap().0, sess.cstore.is_no_builtins(cnum))
assert!(compiler_builtins.is_none());
compiler_builtins = Some(cnum);
}
Linkage::NotLinked |
Linkage::IncludedFromDylib => {}
Expand All @@ -950,6 +952,15 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
}
}

// We must always link the `compiler_builtins` crate statically. Even if it
// was already "included" in a dylib (e.g. `libstd` when `-C prefer-dynamic`
// is used)
if let Some(cnum) = compiler_builtins {
let src = sess.cstore.used_crate_source(cnum);
add_static_crate(cmd, sess, tmpdir, crate_type,
&src.rlib.unwrap().0, sess.cstore.is_no_builtins(cnum));
}

// Converts a library file-stem into a cc -l argument
fn unlib<'a>(config: &config::Config, stem: &'a str) -> &'a str {
if stem.starts_with("lib") && !config.target.options.is_like_windows {
Expand Down

0 comments on commit 2140c4b

Please sign in to comment.