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