@@ -86,7 +86,7 @@ impl Step for Std {
8686        target_deps. extend ( copy_third_party_objects ( builder,  & compiler,  target) . into_iter ( ) ) ; 
8787
8888        let  mut  cargo = builder. cargo ( compiler,  Mode :: Std ,  target,  "build" ) ; 
89-         std_cargo ( builder,  target,  & mut  cargo) ; 
89+         std_cargo ( builder,  target,  compiler . stage ,   & mut  cargo) ; 
9090
9191        builder. info ( & format ! ( 
9292            "Building stage{} std artifacts ({} -> {})" , 
@@ -164,7 +164,7 @@ fn copy_third_party_objects(
164164
165165/// Configure cargo to compile the standard library, adding appropriate env vars 
166166/// and such. 
167- pub  fn  std_cargo ( builder :  & Builder < ' _ > ,  target :  Interned < String > ,  cargo :  & mut  Cargo )  { 
167+ pub  fn  std_cargo ( builder :  & Builder < ' _ > ,  target :  Interned < String > ,  stage :   u32 ,   cargo :  & mut  Cargo )  { 
168168    if  let  Some ( target)  = env:: var_os ( "MACOSX_STD_DEPLOYMENT_TARGET" )  { 
169169        cargo. env ( "MACOSX_DEPLOYMENT_TARGET" ,  target) ; 
170170    } 
@@ -231,6 +231,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
231231            } 
232232        } 
233233    } 
234+ 
235+     // By default, rustc uses `-Cbitcode-in-rlib=yes`, and Cargo overrides that 
236+     // with `-Cbitcode-in-rlib=no` for non-LTO builds. However, libstd must be 
237+     // built with bitcode so that the produced rlibs can be used for both LTO 
238+     // builds (which use bitcode) and non-LTO builds (which use object code). 
239+     // So we override the override here! 
240+     // 
241+     // But we don't bother for the stage 0 compiler because it's never used 
242+     // with LTO. 
243+     if  stage >= 1  { 
244+         cargo. rustflag ( "-Cbitcode-in-rlib=yes" ) ; 
245+     } 
234246} 
235247
236248#[ derive( Debug ,  Copy ,  Clone ,  PartialEq ,  Eq ,  Hash ) ]  
0 commit comments