@@ -270,8 +270,14 @@ pub fn each_linked_rlib(
270
270
271
271
for & cnum in crates {
272
272
match fmts. get ( cnum. as_usize ( ) - 1 ) {
273
- Some ( & Linkage :: NotLinked | & Linkage :: Dynamic | & Linkage :: IncludedFromDylib ) => continue ,
274
- Some ( _) => { }
273
+ Some ( & Linkage :: NotLinked | & Linkage :: Dynamic ) => continue ,
274
+ Some ( & Linkage :: IncludedFromDylib ) => {
275
+ // We always link crate `compiler_builtins` statically. When enabling LTO, we include it as well.
276
+ if info. compiler_builtins != Some ( cnum) {
277
+ continue ;
278
+ }
279
+ }
280
+ Some ( & Linkage :: Static ) => { }
275
281
None => return Err ( errors:: LinkRlibError :: MissingFormat ) ,
276
282
}
277
283
let crate_name = info. crate_name [ & cnum] ;
@@ -520,8 +526,7 @@ fn link_staticlib<'a>(
520
526
& codegen_results. crate_info ,
521
527
Some ( CrateType :: Staticlib ) ,
522
528
& mut |cnum, path| {
523
- let lto = are_upstream_rust_objects_already_included ( sess)
524
- && !ignored_for_lto ( sess, & codegen_results. crate_info , cnum) ;
529
+ let lto = are_upstream_rust_objects_already_included ( sess) ;
525
530
526
531
let native_libs = codegen_results. crate_info . native_libraries [ & cnum] . iter ( ) ;
527
532
let relevant = native_libs. clone ( ) . filter ( |lib| relevant_lib ( sess, lib) ) ;
@@ -1256,24 +1261,6 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
1256
1261
}
1257
1262
}
1258
1263
1259
- /// Returns a boolean indicating whether the specified crate should be ignored
1260
- /// during LTO.
1261
- ///
1262
- /// Crates ignored during LTO are not lumped together in the "massive object
1263
- /// file" that we create and are linked in their normal rlib states. See
1264
- /// comments below for what crates do not participate in LTO.
1265
- ///
1266
- /// It's unusual for a crate to not participate in LTO. Typically only
1267
- /// compiler-specific and unstable crates have a reason to not participate in
1268
- /// LTO.
1269
- pub fn ignored_for_lto ( sess : & Session , info : & CrateInfo , cnum : CrateNum ) -> bool {
1270
- // If our target enables builtin function lowering in LLVM then the
1271
- // crates providing these functions don't participate in LTO (e.g.
1272
- // no_builtins or compiler builtins crates).
1273
- !sess. target . no_builtins
1274
- && ( info. compiler_builtins == Some ( cnum) || info. is_no_builtins . contains ( & cnum) )
1275
- }
1276
-
1277
1264
/// This functions tries to determine the appropriate linker (and corresponding LinkerFlavor) to use
1278
1265
pub fn linker_and_flavor ( sess : & Session ) -> ( PathBuf , LinkerFlavor ) {
1279
1266
fn infer_from (
@@ -2739,10 +2726,6 @@ fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf {
2739
2726
// symbols). We must continue to include the rest of the rlib, however, as
2740
2727
// it may contain static native libraries which must be linked in.
2741
2728
//
2742
- // (*) Crates marked with `#![no_builtins]` don't participate in LTO and
2743
- // their bytecode wasn't included. The object files in those libraries must
2744
- // still be passed to the linker.
2745
- //
2746
2729
// Note, however, that if we're not doing LTO we can just pass the rlib
2747
2730
// blindly to the linker (fast) because it's fine if it's not actually
2748
2731
// included as we're at the end of the dependency chain.
@@ -2768,9 +2751,7 @@ fn add_static_crate<'a>(
2768
2751
cmd. link_rlib ( & rlib_path) ;
2769
2752
} ;
2770
2753
2771
- if !are_upstream_rust_objects_already_included ( sess)
2772
- || ignored_for_lto ( sess, & codegen_results. crate_info , cnum)
2773
- {
2754
+ if !are_upstream_rust_objects_already_included ( sess) {
2774
2755
link_upstream ( cratepath) ;
2775
2756
return ;
2776
2757
}
@@ -2784,8 +2765,6 @@ fn add_static_crate<'a>(
2784
2765
let canonical_name = name. replace ( '-' , "_" ) ;
2785
2766
let upstream_rust_objects_already_included =
2786
2767
are_upstream_rust_objects_already_included ( sess) ;
2787
- let is_builtins =
2788
- sess. target . no_builtins || !codegen_results. crate_info . is_no_builtins . contains ( & cnum) ;
2789
2768
2790
2769
let mut archive = archive_builder_builder. new_archive_builder ( sess) ;
2791
2770
if let Err ( error) = archive. add_archive (
@@ -2802,9 +2781,8 @@ fn add_static_crate<'a>(
2802
2781
2803
2782
// If we're performing LTO and this is a rust-generated object
2804
2783
// file, then we don't need the object file as it's part of the
2805
- // LTO module. Note that `#![no_builtins]` is excluded from LTO,
2806
- // though, so we let that object file slide.
2807
- if upstream_rust_objects_already_included && is_rust_object && is_builtins {
2784
+ // LTO module.
2785
+ if upstream_rust_objects_already_included && is_rust_object {
2808
2786
return true ;
2809
2787
}
2810
2788
0 commit comments