Skip to content

Commit f93ab64

Browse files
committed
Auto merge of #28567 - sanxiyn:save-lto, r=alexcrichton
This is useful for debugging LTO issues, #28066 for example.
2 parents 7e8d19b + 9ba5db6 commit f93ab64

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/librustc_trans/back/lto.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use llvm;
1515
use llvm::archive_ro::ArchiveRO;
1616
use llvm::{ModuleRef, TargetMachineRef, True, False};
1717
use rustc::util::common::time;
18+
use rustc::util::common::path2cstr;
1819
use back::write::{ModuleConfig, with_llvm_pmb};
1920

2021
use libc;
@@ -24,7 +25,9 @@ use std::ffi::CString;
2425

2526
pub fn run(sess: &session::Session, llmod: ModuleRef,
2627
tm: TargetMachineRef, reachable: &[String],
27-
config: &ModuleConfig) {
28+
config: &ModuleConfig,
29+
name_extra: &str,
30+
output_names: &config::OutputFilenames) {
2831
if sess.opts.cg.prefer_dynamic {
2932
sess.err("cannot prefer dynamic linking when performing LTO");
3033
sess.note("only 'staticlib' and 'bin' outputs are supported with LTO");
@@ -124,6 +127,14 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
124127
}
125128
}
126129

130+
if sess.opts.cg.save_temps {
131+
let path = output_names.with_extension(&format!("{}.no-opt.lto.bc", name_extra));
132+
let cstr = path2cstr(&path);
133+
unsafe {
134+
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
135+
}
136+
}
137+
127138
// Now we have one massive module inside of llmod. Time to run the
128139
// LTO-specific optimization passes that LLVM provides.
129140
//

src/librustc_trans/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
496496
match cgcx.lto_ctxt {
497497
Some((sess, reachable)) if sess.lto() => {
498498
time(sess.time_passes(), "all lto passes", ||
499-
lto::run(sess, llmod, tm, reachable, &config));
499+
lto::run(sess, llmod, tm, reachable, &config,
500+
&name_extra, &output_names));
500501

501502
if config.emit_lto_bc {
502503
let name = format!("{}.lto.bc", name_extra);

0 commit comments

Comments
 (0)