diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 535b594649c39..586bcaa80e34f 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -268,8 +268,14 @@ pub fn each_linked_rlib( for &cnum in crates { match fmts.get(cnum.as_usize() - 1) { - Some(&Linkage::NotLinked | &Linkage::Dynamic | &Linkage::IncludedFromDylib) => continue, - Some(_) => {} + Some(&Linkage::NotLinked | &Linkage::Dynamic) => continue, + Some(&Linkage::IncludedFromDylib) => { + // We always link crate `compiler_builtins` statically. When enabling LTO, we include it as well. + if info.compiler_builtins != Some(cnum) { + continue; + } + } + Some(&Linkage::Static) => {} None => return Err(errors::LinkRlibError::MissingFormat), } let crate_name = info.crate_name[&cnum];