@@ -660,14 +660,19 @@ impl Step for Rustdoc {
660
660
) ;
661
661
662
662
// rustdoc is performance sensitive, so apply LTO to it.
663
- let lto = match builder. config . rust_lto {
664
- RustcLto :: Off => Some ( "off" ) ,
665
- RustcLto :: Thin => Some ( "thin" ) ,
666
- RustcLto :: Fat => Some ( "fat" ) ,
667
- RustcLto :: ThinLocal => None ,
668
- } ;
669
- if let Some ( lto) = lto {
670
- cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
663
+ // The compiler shared libraries (librustc_driver.so) don't use LTO on stages
664
+ // lower than stage 1, as it's not worth it.
665
+ // So we also need to only do this at stage 2+, to avoid missing LTO bitcode errors.
666
+ if build_compiler. stage != 0 {
667
+ let lto = match builder. config . rust_lto {
668
+ RustcLto :: Off => Some ( "off" ) ,
669
+ RustcLto :: Thin => Some ( "thin" ) ,
670
+ RustcLto :: Fat => Some ( "fat" ) ,
671
+ RustcLto :: ThinLocal => None ,
672
+ } ;
673
+ if let Some ( lto) = lto {
674
+ cargo. env ( cargo_profile_var ( "LTO" , & builder. config ) , lto) ;
675
+ }
671
676
}
672
677
673
678
let _guard = builder. msg_tool (
0 commit comments