Skip to content

Commit dc2c356

Browse files
committed
Auto merge of rust-lang#146376 - durin42:dwo-specify-path, r=davidtwco
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. r? `@davidtwco`
2 parents 21a13b8 + eb3fb45 commit dc2c356

File tree

6 files changed

+167
-13
lines changed

6 files changed

+167
-13
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
@@ -1195,6 +1195,7 @@ pub struct OutputFilenames {
11951195
filestem: String,
11961196
pub single_output_file: Option<OutFileName>,
11971197
temps_directory: Option<PathBuf>,
1198+
explicit_dwo_out_directory: Option<PathBuf>,
11981199
pub outputs: OutputTypes,
11991200
}
12001201

@@ -1227,13 +1228,15 @@ impl OutputFilenames {
12271228
out_filestem: String,
12281229
single_output_file: Option<OutFileName>,
12291230
temps_directory: Option<PathBuf>,
1231+
explicit_dwo_out_directory: Option<PathBuf>,
12301232
extra: String,
12311233
outputs: OutputTypes,
12321234
) -> Self {
12331235
OutputFilenames {
12341236
out_directory,
12351237
single_output_file,
12361238
temps_directory,
1239+
explicit_dwo_out_directory,
12371240
outputs,
12381241
crate_stem: format!("{out_crate_name}{extra}"),
12391242
filestem: format!("{out_filestem}{extra}"),
@@ -1283,7 +1286,14 @@ impl OutputFilenames {
12831286
codegen_unit_name: &str,
12841287
invocation_temp: Option<&str>,
12851288
) -> PathBuf {
1286-
self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp)
1289+
let p = self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp);
1290+
if let Some(dwo_out) = &self.explicit_dwo_out_directory {
1291+
let mut o = dwo_out.clone();
1292+
o.push(p.file_name().unwrap());
1293+
o
1294+
} else {
1295+
p
1296+
}
12871297
}
12881298

12891299
/// 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
@@ -2634,6 +2634,8 @@ written to standard error output)"),
26342634
file which is ignored by the linker
26352635
`single`: sections which do not require relocation are written into object file but ignored
26362636
by the linker"),
2637+
split_dwarf_out_dir : Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2638+
"location for writing split DWARF objects (`.dwo`) if enabled"),
26372639
split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
26382640
"enable LTO unit splitting (default: no)"),
26392641
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `split-dwarf-out-dir`
2+
3+
On systems which use DWARF debug info this flag causes `.dwo` files produced
4+
by `-C split-debuginfo` to be written to the specified directory rather than
5+
placed next to the object files. This is mostly useful if you have a build
6+
system which needs to control where to find compile outputs without running the
7+
compiler and have to put your `.dwo` files in a separate directory.

src/tools/run-make-support/src/external_deps/rustc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ impl Rustc {
366366
self
367367
}
368368

369+
pub fn split_dwarf_out_dir(&mut self, out_dir: Option<&str>) -> &mut Self {
370+
if let Some(out_dir) = out_dir {
371+
self.cmd.arg(format!("-Zsplit-dwarf-out-dir={out_dir}"));
372+
}
373+
self
374+
}
375+
369376
/// Pass the `--verbose` flag.
370377
pub fn verbose(&mut self) -> &mut Self {
371378
self.cmd.arg("--verbose");

0 commit comments

Comments
 (0)