@@ -662,51 +662,56 @@ fn link_rlib<'a>(sess: &'a Session,
662
662
ab. add_file ( & metadata) . unwrap ( ) ;
663
663
remove ( sess, & metadata) ;
664
664
665
- // For LTO purposes, the bytecode of this library is also inserted
666
- // into the archive.
667
- //
668
- // Note that we make sure that the bytecode filename in the archive
669
- // is never exactly 16 bytes long by adding a 16 byte extension to
670
- // it. This is to work around a bug in LLDB that would cause it to
671
- // crash if the name of a file in an archive was exactly 16 bytes.
672
- let bc_filename = obj_filename. with_extension ( "bc" ) ;
673
- let bc_deflated_filename = obj_filename. with_extension ( "bytecode.deflate" ) ;
674
-
675
- let bc_data = match fs:: File :: open ( & bc_filename) . read_to_end ( ) {
676
- Ok ( buffer) => buffer,
677
- Err ( e) => sess. fatal ( format ! ( "failed to read bytecode: {}" ,
678
- e) . as_slice ( ) )
679
- } ;
665
+ if sess. opts . cg . codegen_units == 1 {
666
+ // For LTO purposes, the bytecode of this library is also
667
+ // inserted into the archive. We currently do this only when
668
+ // codegen_units == 1, so we don't have to deal with multiple
669
+ // bitcode files per crate.
670
+ //
671
+ // Note that we make sure that the bytecode filename in the
672
+ // archive is never exactly 16 bytes long by adding a 16 byte
673
+ // extension to it. This is to work around a bug in LLDB that
674
+ // would cause it to crash if the name of a file in an archive
675
+ // was exactly 16 bytes.
676
+ let bc_filename = obj_filename. with_extension ( "bc" ) ;
677
+ let bc_deflated_filename = obj_filename. with_extension ( "bytecode.deflate" ) ;
678
+
679
+ let bc_data = match fs:: File :: open ( & bc_filename) . read_to_end ( ) {
680
+ Ok ( buffer) => buffer,
681
+ Err ( e) => sess. fatal ( format ! ( "failed to read bytecode: {}" ,
682
+ e) . as_slice ( ) )
683
+ } ;
680
684
681
- let bc_data_deflated = match flate:: deflate_bytes ( bc_data. as_slice ( ) ) {
682
- Some ( compressed) => compressed,
683
- None => sess. fatal ( format ! ( "failed to compress bytecode from {}" ,
684
- bc_filename. display( ) ) . as_slice ( ) )
685
- } ;
685
+ let bc_data_deflated = match flate:: deflate_bytes ( bc_data. as_slice ( ) ) {
686
+ Some ( compressed) => compressed,
687
+ None => sess. fatal ( format ! ( "failed to compress bytecode from {}" ,
688
+ bc_filename. display( ) ) . as_slice ( ) )
689
+ } ;
686
690
687
- let mut bc_file_deflated = match fs:: File :: create ( & bc_deflated_filename) {
688
- Ok ( file) => file,
689
- Err ( e) => {
690
- sess. fatal ( format ! ( "failed to create compressed bytecode \
691
- file: {}", e) . as_slice ( ) )
692
- }
693
- } ;
691
+ let mut bc_file_deflated = match fs:: File :: create ( & bc_deflated_filename) {
692
+ Ok ( file) => file,
693
+ Err ( e) => {
694
+ sess. fatal ( format ! ( "failed to create compressed bytecode \
695
+ file: {}", e) . as_slice ( ) )
696
+ }
697
+ } ;
694
698
695
- match write_rlib_bytecode_object_v1 ( & mut bc_file_deflated,
696
- bc_data_deflated. as_slice ( ) ) {
697
- Ok ( ( ) ) => { }
698
- Err ( e) => {
699
- sess. err ( format ! ( "failed to write compressed bytecode: \
700
- {}", e) . as_slice ( ) ) ;
701
- sess. abort_if_errors ( )
702
- }
703
- } ;
699
+ match write_rlib_bytecode_object_v1 ( & mut bc_file_deflated,
700
+ bc_data_deflated. as_slice ( ) ) {
701
+ Ok ( ( ) ) => { }
702
+ Err ( e) => {
703
+ sess. err ( format ! ( "failed to write compressed bytecode: \
704
+ {}", e) . as_slice ( ) ) ;
705
+ sess. abort_if_errors ( )
706
+ }
707
+ } ;
704
708
705
- ab. add_file ( & bc_deflated_filename) . unwrap ( ) ;
706
- remove ( sess, & bc_deflated_filename) ;
707
- if !sess. opts . cg . save_temps &&
708
- !sess. opts . output_types . contains ( & OutputTypeBitcode ) {
709
- remove ( sess, & bc_filename) ;
709
+ ab. add_file ( & bc_deflated_filename) . unwrap ( ) ;
710
+ remove ( sess, & bc_deflated_filename) ;
711
+ if !sess. opts . cg . save_temps &&
712
+ !sess. opts . output_types . contains ( & OutputTypeBitcode ) {
713
+ remove ( sess, & bc_filename) ;
714
+ }
710
715
}
711
716
}
712
717
0 commit comments