@@ -926,17 +926,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
926926 // crates.
927927 let deps = sess. cstore . used_crates ( LinkagePreference :: RequireDynamic ) ;
928928
929+ let mut compiler_builtins = None ;
930+
929931 for & ( cnum, _) in & deps {
930932 // We may not pass all crates through to the linker. Some crates may
931933 // appear statically in an existing dylib, meaning we'll pick up all the
932934 // symbols from the dylib.
933935 let src = sess. cstore . used_crate_source ( cnum) ;
934936 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.
937939 _ 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) ;
940942 }
941943 Linkage :: NotLinked |
942944 Linkage :: IncludedFromDylib => { }
@@ -950,6 +952,15 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
950952 }
951953 }
952954
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+
953964 // Converts a library file-stem into a cc -l argument
954965 fn unlib < ' a > ( config : & config:: Config , stem : & ' a str ) -> & ' a str {
955966 if stem. starts_with ( "lib" ) && !config. target . options . is_like_windows {
0 commit comments