diff options
| author | DianQK <dianqk@dianqk.net> | 2025-02-06 22:00:19 +0800 |
|---|---|---|
| committer | DianQK <dianqk@dianqk.net> | 2025-02-23 21:23:38 +0800 |
| commit | da50297a6ea8454b0e36ef110370bec914c408d1 (patch) | |
| tree | 8bfd05b52741cfdb6548deac7522b1d484108a68 /compiler/rustc_codegen_llvm/src/back/write.rs | |
| parent | 9431427cc363d0a1c36401cb98f15a7426f2220f (diff) | |
| download | rust-da50297a6ea8454b0e36ef110370bec914c408d1.tar.gz rust-da50297a6ea8454b0e36ef110370bec914c408d1.zip | |
Save pre-link bitcode to `ModuleCodegen`
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/back/write.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/back/write.rs | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 1ad256d3b75..c5208f7c538 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -689,7 +689,7 @@ pub(crate) unsafe fn llvm_optimize( pub(crate) unsafe fn optimize( cgcx: &CodegenContext<LlvmCodegenBackend>, dcx: DiagCtxtHandle<'_>, - module: &ModuleCodegen<ModuleLlvm>, + module: &mut ModuleCodegen<ModuleLlvm>, config: &ModuleConfig, ) -> Result<(), FatalError> { let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &*module.name); @@ -745,10 +745,7 @@ pub(crate) unsafe fn optimize( }?; if let Some(thin_lto_buffer) = thin_lto_buffer { let thin_lto_buffer = unsafe { ThinBuffer::from_raw_ptr(thin_lto_buffer) }; - let thin_bc_out = cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name); - if let Err(err) = fs::write(&thin_bc_out, thin_lto_buffer.data()) { - dcx.emit_err(WriteBytecode { path: &thin_bc_out, err }); - } + module.thin_lto_buffer = Some(thin_lto_buffer.data().to_vec()); let bc_summary_out = cgcx.output_filenames.temp_path(OutputType::ThinLinkBitcode, module_name); if config.emit_thin_lto_summary @@ -848,20 +845,14 @@ pub(crate) unsafe fn codegen( } } - if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) - && module.kind == ModuleKind::Regular - { + if config.embed_bitcode() && module.kind == ModuleKind::Regular { let _timer = cgcx .prof .generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name); - let thin_bc_out = - cgcx.output_filenames.temp_path(OutputType::ThinBitcode, module_name); - assert!(thin_bc_out.exists(), "cannot find {:?} as embedded bitcode", thin_bc_out); - let data = fs::read(&thin_bc_out).unwrap(); - debug!("removing embed bitcode file {:?}", thin_bc_out); - ensure_removed(dcx, &thin_bc_out); + let thin_bc = + module.thin_lto_buffer.as_deref().expect("cannot find embedded bitcode"); unsafe { - embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, &data); + embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, &thin_bc); } } } |
