@@ -926,17 +926,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
926
926
// crates.
927
927
let deps = sess. cstore . used_crates ( LinkagePreference :: RequireDynamic ) ;
928
928
929
+ let mut compiler_builtins = None ;
930
+
929
931
for & ( cnum, _) in & deps {
930
932
// We may not pass all crates through to the linker. Some crates may
931
933
// appear statically in an existing dylib, meaning we'll pick up all the
932
934
// symbols from the dylib.
933
935
let src = sess. cstore . used_crate_source ( cnum) ;
934
936
match data[ cnum as usize - 1 ] {
935
- // We must always link the `compiler_builtins` crate statically. Even if it was already
936
- // "included" in a dylib (e.g. `libstd` when `-C prefer-dynamic` is used)
937
+ // compiler-builtins are always placed last to ensure that they're
938
+ // linked correctly.
937
939
_ if sess. cstore . is_compiler_builtins ( cnum) => {
938
- add_static_crate ( cmd , sess , tmpdir , crate_type ,
939
- & src . rlib . unwrap ( ) . 0 , sess . cstore . is_no_builtins ( cnum) )
940
+ assert ! ( compiler_builtins . is_none ( ) ) ;
941
+ compiler_builtins = Some ( cnum) ;
940
942
}
941
943
Linkage :: NotLinked |
942
944
Linkage :: IncludedFromDylib => { }
@@ -950,6 +952,15 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
950
952
}
951
953
}
952
954
955
+ // We must always link the `compiler_builtins` crate statically. Even if it
956
+ // was already "included" in a dylib (e.g. `libstd` when `-C prefer-dynamic`
957
+ // is used)
958
+ if let Some ( cnum) = compiler_builtins {
959
+ let src = sess. cstore . used_crate_source ( cnum) ;
960
+ add_static_crate ( cmd, sess, tmpdir, crate_type,
961
+ & src. rlib . unwrap ( ) . 0 , sess. cstore . is_no_builtins ( cnum) ) ;
962
+ }
963
+
953
964
// Converts a library file-stem into a cc -l argument
954
965
fn unlib < ' a > ( config : & config:: Config , stem : & ' a str ) -> & ' a str {
955
966
if stem. starts_with ( "lib" ) && !config. target . options . is_like_windows {
0 commit comments