Skip to content

Commit b57142d

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 40dacd5 commit b57142d

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
@@ -529,6 +529,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
529529
stem,
530530
None,
531531
sess.io.temps_dir.clone(),
532+
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
532533
sess.opts.cg.extra_filename.clone(),
533534
sess.opts.output_types.clone(),
534535
)
@@ -558,6 +559,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
558559
out_filestem,
559560
ofile,
560561
sess.io.temps_dir.clone(),
562+
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
561563
sess.opts.cg.extra_filename.clone(),
562564
sess.opts.output_types.clone(),
563565
)

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ pub struct OutputFilenames {
10471047
filestem: String,
10481048
pub single_output_file: Option<OutFileName>,
10491049
temps_directory: Option<PathBuf>,
1050+
explicit_dwo_out_directory: Option<PathBuf>,
10501051
pub outputs: OutputTypes,
10511052
}
10521053

@@ -1061,13 +1062,15 @@ impl OutputFilenames {
10611062
out_filestem: String,
10621063
single_output_file: Option<OutFileName>,
10631064
temps_directory: Option<PathBuf>,
1065+
explicit_dwo_out_directory: Option<PathBuf>,
10641066
extra: String,
10651067
outputs: OutputTypes,
10661068
) -> Self {
10671069
OutputFilenames {
10681070
out_directory,
10691071
single_output_file,
10701072
temps_directory,
1073+
explicit_dwo_out_directory,
10711074
outputs,
10721075
crate_stem: format!("{out_crate_name}{extra}"),
10731076
filestem: format!("{out_filestem}{extra}"),
@@ -1113,7 +1116,14 @@ impl OutputFilenames {
11131116
codegen_unit_name: &str,
11141117
invocation_temp: Option<&str>,
11151118
) -> PathBuf {
1116-
self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp)
1119+
let p = self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp);
1120+
if let Some(dwo_out) = &self.explicit_dwo_out_directory {
1121+
let mut o = dwo_out.clone();
1122+
o.push(p.file_name().unwrap());
1123+
o
1124+
} else {
1125+
p
1126+
}
11171127
}
11181128

11191129
/// 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
@@ -2494,6 +2494,8 @@ written to standard error output)"),
24942494
file which is ignored by the linker
24952495
`single`: sections which do not require relocation are written into object file but ignored
24962496
by the linker"),
2497+
split_dwarf_out_dir : Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2498+
"location for writing split DWARF objects (`.dwo`) if enabled"),
24972499
split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
24982500
"enable LTO unit splitting (default: no)"),
24992501
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],

0 commit comments

Comments
 (0)