@@ -689,7 +689,7 @@ pub(crate) unsafe fn llvm_optimize(
689
689
pub ( crate ) unsafe fn optimize (
690
690
cgcx : & CodegenContext < LlvmCodegenBackend > ,
691
691
dcx : DiagCtxtHandle < ' _ > ,
692
- module : & ModuleCodegen < ModuleLlvm > ,
692
+ module : & mut ModuleCodegen < ModuleLlvm > ,
693
693
config : & ModuleConfig ,
694
694
) -> Result < ( ) , FatalError > {
695
695
let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
@@ -745,10 +745,7 @@ pub(crate) unsafe fn optimize(
745
745
} ?;
746
746
if let Some ( thin_lto_buffer) = thin_lto_buffer {
747
747
let thin_lto_buffer = unsafe { ThinBuffer :: from_raw_ptr ( thin_lto_buffer) } ;
748
- let thin_bc_out = cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name) ;
749
- if let Err ( err) = fs:: write ( & thin_bc_out, thin_lto_buffer. data ( ) ) {
750
- dcx. emit_err ( WriteBytecode { path : & thin_bc_out, err } ) ;
751
- }
748
+ module. thin_lto_buffer = Some ( thin_lto_buffer. data ( ) . to_vec ( ) ) ;
752
749
let bc_summary_out =
753
750
cgcx. output_filenames . temp_path ( OutputType :: ThinLinkBitcode , module_name) ;
754
751
if config. emit_thin_lto_summary
@@ -848,20 +845,14 @@ pub(crate) unsafe fn codegen(
848
845
}
849
846
}
850
847
851
- if config. emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full )
852
- && module. kind == ModuleKind :: Regular
853
- {
848
+ if config. embed_bitcode ( ) && module. kind == ModuleKind :: Regular {
854
849
let _timer = cgcx
855
850
. prof
856
851
. generic_activity_with_arg ( "LLVM_module_codegen_embed_bitcode" , & * module. name ) ;
857
- let thin_bc_out =
858
- cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name) ;
859
- assert ! ( thin_bc_out. exists( ) , "cannot find {:?} as embedded bitcode" , thin_bc_out) ;
860
- let data = fs:: read ( & thin_bc_out) . unwrap ( ) ;
861
- debug ! ( "removing embed bitcode file {:?}" , thin_bc_out) ;
862
- ensure_removed ( dcx, & thin_bc_out) ;
852
+ let thin_bc =
853
+ module. thin_lto_buffer . as_deref ( ) . expect ( "cannot find embedded bitcode" ) ;
863
854
unsafe {
864
- embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & data ) ;
855
+ embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & thin_bc ) ;
865
856
}
866
857
}
867
858
}
0 commit comments