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.
This commit is contained in:
Augie Fackler 2025-03-06 22:10:42 -05:00
parent a885811104
commit 77c6acc74e
3 changed files with 15 additions and 1 deletions

View file

@ -542,6 +542,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
stem,
None,
sess.io.temps_dir.clone(),
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
sess.opts.cg.extra_filename.clone(),
sess.opts.output_types.clone(),
)
@ -571,6 +572,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
out_filestem,
ofile,
sess.io.temps_dir.clone(),
sess.opts.unstable_opts.split_dwarf_out_dir.clone(),
sess.opts.cg.extra_filename.clone(),
sess.opts.output_types.clone(),
)

View file

@ -1193,6 +1193,7 @@ pub struct OutputFilenames {
filestem: String,
pub single_output_file: Option<OutFileName>,
temps_directory: Option<PathBuf>,
explicit_dwo_out_directory: Option<PathBuf>,
pub outputs: OutputTypes,
}
@ -1225,6 +1226,7 @@ impl OutputFilenames {
out_filestem: String,
single_output_file: Option<OutFileName>,
temps_directory: Option<PathBuf>,
explicit_dwo_out_directory: Option<PathBuf>,
extra: String,
outputs: OutputTypes,
) -> Self {
@ -1232,6 +1234,7 @@ impl OutputFilenames {
out_directory,
single_output_file,
temps_directory,
explicit_dwo_out_directory,
outputs,
crate_stem: format!("{out_crate_name}{extra}"),
filestem: format!("{out_filestem}{extra}"),
@ -1281,7 +1284,14 @@ impl OutputFilenames {
codegen_unit_name: &str,
invocation_temp: Option<&str>,
) -> PathBuf {
self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp)
let p = self.temp_path_ext_for_cgu(DWARF_OBJECT_EXT, codegen_unit_name, invocation_temp);
if let Some(dwo_out) = &self.explicit_dwo_out_directory {
let mut o = dwo_out.clone();
o.push(p.file_name().unwrap());
o
} else {
p
}
}
/// Like `temp_path`, but also supports things where there is no corresponding

View file

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