Skip to content

Commit 77c6acc

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 a885811 commit 77c6acc

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
@@ -1193,6 +1193,7 @@ pub struct OutputFilenames {
11931193
filestem: String,
11941194
pub single_output_file: Option<OutFileName>,
11951195
temps_directory: Option<PathBuf>,
1196+
explicit_dwo_out_directory: Option<PathBuf>,
11961197
pub outputs: OutputTypes,
11971198
}
11981199

@@ -1225,13 +1226,15 @@ impl OutputFilenames {
12251226
out_filestem: String,
12261227
single_output_file: Option<OutFileName>,
12271228
temps_directory: Option<PathBuf>,
1229+
explicit_dwo_out_directory: Option<PathBuf>,
12281230
extra: String,
12291231
outputs: OutputTypes,
12301232
) -> Self {
12311233
OutputFilenames {
12321234
out_directory,
12331235
single_output_file,
12341236
temps_directory,
1237+
explicit_dwo_out_directory,
12351238
outputs,
12361239
crate_stem: format!("{out_crate_name}{extra}"),
12371240
filestem: format!("{out_filestem}{extra}"),
@@ -1281,7 +1284,14 @@ impl OutputFilenames {
12811284
codegen_unit_name: &str,
12821285
invocation_temp: Option<&str>,
12831286
) -> PathBuf {
1284-
self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp)
1287+
let p = self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp);
1288+
if let Some(dwo_out) = &self.explicit_dwo_out_directory {
1289+
let mut o = dwo_out.clone();
1290+
o.push(p.file_name().unwrap());
1291+
o
1292+
} else {
1293+
p
1294+
}
12851295
}
12861296

12871297
/// 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
@@ -2633,6 +2633,8 @@ written to standard error output)"),
26332633
file which is ignored by the linker
26342634
`single`: sections which do not require relocation are written into object file but ignored
26352635
by the linker"),
2636+
split_dwarf_out_dir : Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2637+
"location for writing split DWARF objects (`.dwo`) if enabled"),
26362638
split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
26372639
"enable LTO unit splitting (default: no)"),
26382640
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],

0 commit comments

Comments
 (0)