@@ -685,7 +685,7 @@ pub(crate) unsafe fn llvm_optimize(
685685pub ( crate ) unsafe fn optimize (
686686 cgcx : & CodegenContext < LlvmCodegenBackend > ,
687687 dcx : DiagCtxtHandle < ' _ > ,
688- module : & ModuleCodegen < ModuleLlvm > ,
688+ module : & mut ModuleCodegen < ModuleLlvm > ,
689689 config : & ModuleConfig ,
690690) -> Result < ( ) , FatalError > {
691691 let _timer = cgcx. prof . generic_activity_with_arg ( "LLVM_module_optimize" , & * module. name ) ;
@@ -745,10 +745,7 @@ pub(crate) unsafe fn optimize(
745745 } ?;
746746 if let Some ( thin_lto_buffer) = thin_lto_buffer {
747747 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 ( ) ) ;
752749 let bc_summary_out =
753750 cgcx. output_filenames . temp_path ( OutputType :: ThinLinkBitcode , module_name) ;
754751 if config. emit_thin_lto_summary
@@ -873,20 +870,14 @@ pub(crate) unsafe fn codegen(
873870 }
874871 }
875872
876- if config. emit_obj == EmitObj :: ObjectCode ( BitcodeSection :: Full )
877- && module. kind == ModuleKind :: Regular
878- {
873+ if config. embed_bitcode ( ) && module. kind == ModuleKind :: Regular {
879874 let _timer = cgcx
880875 . prof
881876 . generic_activity_with_arg ( "LLVM_module_codegen_embed_bitcode" , & * module. name ) ;
882- let thin_bc_out =
883- cgcx. output_filenames . temp_path ( OutputType :: ThinBitcode , module_name) ;
884- assert ! ( thin_bc_out. exists( ) , "cannot find {:?} as embedded bitcode" , thin_bc_out) ;
885- let data = fs:: read ( & thin_bc_out) . unwrap ( ) ;
886- debug ! ( "removing embed bitcode file {:?}" , thin_bc_out) ;
887- ensure_removed ( dcx, & thin_bc_out) ;
877+ let thin_bc =
878+ module. thin_lto_buffer . as_deref ( ) . expect ( "cannot find embedded bitcode" ) ;
888879 unsafe {
889- embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & data ) ;
880+ embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & thin_bc ) ;
890881 }
891882 }
892883 }
0 commit comments