@@ -940,7 +940,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
940
940
Linkage :: IncludedFromDylib => { }
941
941
Linkage :: Static => {
942
942
add_static_crate ( cmd, sess, tmpdir, crate_type,
943
- & src. rlib . unwrap ( ) . 0 )
943
+ & src. rlib . unwrap ( ) . 0 , sess . cstore . is_no_builtins ( cnum ) )
944
944
}
945
945
Linkage :: Dynamic => {
946
946
add_dynamic_crate ( cmd, sess, & src. dylib . unwrap ( ) . 0 )
@@ -964,12 +964,16 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
964
964
// * For LTO, we remove upstream object files.
965
965
// * For dylibs we remove metadata and bytecode from upstream rlibs
966
966
//
967
- // When performing LTO, all of the bytecode from the upstream libraries has
968
- // already been included in our object file output. As a result we need to
969
- // remove the object files in the upstream libraries so the linker doesn't
970
- // try to include them twice (or whine about duplicate symbols). We must
971
- // continue to include the rest of the rlib, however, as it may contain
972
- // static native libraries which must be linked in.
967
+ // When performing LTO, almost(*) all of the bytecode from the upstream
968
+ // libraries has already been included in our object file output. As a
969
+ // result we need to remove the object files in the upstream libraries so
970
+ // the linker doesn't try to include them twice (or whine about duplicate
971
+ // symbols). We must continue to include the rest of the rlib, however, as
972
+ // it may contain static native libraries which must be linked in.
973
+ //
974
+ // (*) Crates marked with `#![no_builtins]` don't participate in LTO and
975
+ // their bytecode wasn't included. The object files in those libraries must
976
+ // still be passed to the linker.
973
977
//
974
978
// When making a dynamic library, linkers by default don't include any
975
979
// object files in an archive if they're not necessary to resolve the link.
@@ -989,7 +993,8 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
989
993
sess : & Session ,
990
994
tmpdir : & Path ,
991
995
crate_type : config:: CrateType ,
992
- cratepath : & Path ) {
996
+ cratepath : & Path ,
997
+ is_a_no_builtins_crate : bool ) {
993
998
if !sess. lto ( ) && crate_type != config:: CrateTypeDylib {
994
999
cmd. link_rlib ( & fix_windows_verbatim_for_gcc ( cratepath) ) ;
995
1000
return
@@ -1013,7 +1018,8 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
1013
1018
}
1014
1019
let canonical = f. replace ( "-" , "_" ) ;
1015
1020
let canonical_name = name. replace ( "-" , "_" ) ;
1016
- if sess. lto ( ) && canonical. starts_with ( & canonical_name) &&
1021
+ if sess. lto ( ) && !is_a_no_builtins_crate &&
1022
+ canonical. starts_with ( & canonical_name) &&
1017
1023
canonical. ends_with ( ".o" ) {
1018
1024
let num = & f[ name. len ( ) ..f. len ( ) - 2 ] ;
1019
1025
if num. len ( ) > 0 && num[ 1 ..] . parse :: < u32 > ( ) . is_ok ( ) {
0 commit comments