Skip to content

Commit 0115969

Browse files
committed
debuginfo: add an unstable flag to write split DWARF to an explicit directory
Bazel requires knowledge of outputs from actions at analysis time, including file or directory name. In order to work around the lack of predictable output name for dwo files, we group the dwo files in a subdirectory of --out-dir as a post-processing step before returning control to bazel. Unfortunately some debugging workflows rely on directly opening the dwo file rather than loading the merged dwp file, and our trick of moving the files breaks those users. We can't just hardlink the file or copy it, because with remote build execution we wouldn't end up with the un-moved file copied back to the developer's workstation. As a fix, we add this unstable flag that causes dwo files to be written to a build-system-controllable location, which then lets bazel hoover up the dwo files, but the objects also have the correct path for the dwo files.
1 parent be8de5d commit 0115969

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
542542
stem,
543543
None,
544544
sess.io.temps_dir.clone(),
545+
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
545546
sess.opts.cg.extra_filename.clone(),
546547
sess.opts.output_types.clone(),
547548
)
@@ -571,6 +572,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
571572
out_filestem,
572573
ofile,
573574
sess.io.temps_dir.clone(),
575+
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
574576
sess.opts.cg.extra_filename.clone(),
575577
sess.opts.output_types.clone(),
576578
)

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ pub struct OutputFilenames {
11901190
filestem: String,
11911191
pub single_output_file: Option<OutFileName>,
11921192
temps_directory: Option<PathBuf>,
1193+
explicit_dwo_out_directory: Option<PathBuf>,
11931194
pub outputs: OutputTypes,
11941195
}
11951196

@@ -1222,13 +1223,15 @@ impl OutputFilenames {
12221223
out_filestem: String,
12231224
single_output_file: Option<OutFileName>,
12241225
temps_directory: Option<PathBuf>,
1226+
explicit_dwo_out_directory: Option<PathBuf>,
12251227
extra: String,
12261228
outputs: OutputTypes,
12271229
) -> Self {
12281230
OutputFilenames {
12291231
out_directory,
12301232
single_output_file,
12311233
temps_directory,
1234+
explicit_dwo_out_directory,
12321235
outputs,
12331236
crate_stem: format!("{out_crate_name}{extra}"),
12341237
filestem: format!("{out_filestem}{extra}"),
@@ -1278,7 +1281,14 @@ impl OutputFilenames {
12781281
codegen_unit_name: &str,
12791282
invocation_temp: Option<&str>,
12801283
) -> PathBuf {
1281-
self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp)
1284+
let p = self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp);
1285+
if let Some(dwo_out) = &self.explicit_dwo_out_directory {
1286+
let mut o = dwo_out.clone();
1287+
o.push(p.file_name().unwrap());
1288+
o
1289+
} else {
1290+
p
1291+
}
12821292
}
12831293

12841294
/// Like `temp_path`, but also supports things where there is no corresponding

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,6 +2630,8 @@ written to standard error output)"),
26302630
file which is ignored by the linker
26312631
`single`: sections which do not require relocation are written into object file but ignored
26322632
by the linker"),
2633+
split_dwarf_out_dir : Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2634+
"location for writing split DWARF objects (`.dwo`) if enabled"),
26332635
split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
26342636
"enable LTO unit splitting (default: no)"),
26352637
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],

0 commit comments

Comments
 (0)