Skip to content

Commit 16c7188

Browse files
committed
Set path of the compile unit to the source directory
As part of the effort to implement split dwarf debug info, we ended up setting the compile unit location to the output directory rather than the source directory. Furthermore, it seems like we failed to remap the prefixes for this as well! The desired behaviour is to instead set the `DW_AT_GNU_dwo_name` to a path relative to compiler's working directory. This still allows debuggers to find the split dwarf files, while not changing the behaviour of the code that is compiling with regular debug info, and not changing the compiler's behaviour with regards to reproducibility. Fixes #82074
1 parent 3158857 commit 16c7188

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
9393
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
9494
let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() {
9595
tcx.output_filenames(LOCAL_CRATE)
96-
.split_dwarf_filename(tcx.sess.split_debuginfo(), Some(mod_name))
96+
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name))
9797
} else {
9898
None
9999
};

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ pub fn compile_unit_metadata(
979979
// The OSX linker has an idiosyncrasy where it will ignore some debuginfo
980980
// if multiple object files with the same `DW_AT_name` are linked together.
981981
// As a workaround we generate unique names for each object file. Those do
982-
// not correspond to an actual source file but that should be harmless.
982+
// not correspond to an actual source file but that is harmless.
983983
if tcx.sess.target.is_like_osx {
984984
name_in_debuginfo.push("@");
985985
name_in_debuginfo.push(codegen_unit_name);
@@ -992,17 +992,17 @@ pub fn compile_unit_metadata(
992992
let producer = format!("clang LLVM ({})", rustc_producer);
993993

994994
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
995+
let work_dir = tcx.sess.working_dir.0.to_string_lossy();
995996
let flags = "\0";
996-
997997
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
998998
let split_name = if tcx.sess.target_can_use_split_dwarf() {
999999
tcx.output_filenames(LOCAL_CRATE)
1000-
.split_dwarf_filename(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
1000+
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
1001+
.map(|f| out_dir.join(f))
10011002
} else {
10021003
None
10031004
}
10041005
.unwrap_or_default();
1005-
let out_dir = out_dir.to_str().unwrap();
10061006
let split_name = split_name.to_str().unwrap();
10071007

10081008
// FIXME(#60020):
@@ -1024,12 +1024,12 @@ pub fn compile_unit_metadata(
10241024
assert!(tcx.sess.opts.debuginfo != DebugInfo::None);
10251025

10261026
unsafe {
1027-
let file_metadata = llvm::LLVMRustDIBuilderCreateFile(
1027+
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
10281028
debug_context.builder,
10291029
name_in_debuginfo.as_ptr().cast(),
10301030
name_in_debuginfo.len(),
1031-
out_dir.as_ptr().cast(),
1032-
out_dir.len(),
1031+
work_dir.as_ptr().cast(),
1032+
work_dir.len(),
10331033
llvm::ChecksumKind::None,
10341034
ptr::null(),
10351035
0,
@@ -1038,12 +1038,15 @@ pub fn compile_unit_metadata(
10381038
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
10391039
debug_context.builder,
10401040
DW_LANG_RUST,
1041-
file_metadata,
1041+
compile_unit_file,
10421042
producer.as_ptr().cast(),
10431043
producer.len(),
10441044
tcx.sess.opts.optimize != config::OptLevel::No,
10451045
flags.as_ptr().cast(),
10461046
0,
1047+
// NB: this doesn't actually have any perceptible effect, it seems. LLVM will instead
1048+
// put the path supplied to `MCSplitDwarfFile` into the debug info of the final
1049+
// output(s).
10471050
split_name.as_ptr().cast(),
10481051
split_name.len(),
10491052
kind,

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl TargetMachineFactoryConfig {
288288
module_name: &str,
289289
) -> TargetMachineFactoryConfig {
290290
let split_dwarf_file = if cgcx.target_can_use_split_dwarf {
291-
cgcx.output_filenames.split_dwarf_filename(cgcx.split_debuginfo, Some(module_name))
291+
cgcx.output_filenames.split_dwarf_path(cgcx.split_debuginfo, Some(module_name))
292292
} else {
293293
None
294294
};

Diff for: compiler/rustc_session/src/config.rs

-11
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,6 @@ impl OutputFilenames {
667667
path
668668
}
669669

670-
/// Returns the name of the Split DWARF file - this can differ depending on which Split DWARF
671-
/// mode is being used, which is the logic that this function is intended to encapsulate.
672-
pub fn split_dwarf_filename(
673-
&self,
674-
split_debuginfo_kind: SplitDebuginfo,
675-
cgu_name: Option<&str>,
676-
) -> Option<PathBuf> {
677-
self.split_dwarf_path(split_debuginfo_kind, cgu_name)
678-
.map(|path| path.strip_prefix(&self.out_directory).unwrap_or(&path).to_path_buf())
679-
}
680-
681670
/// Returns the path for the Split DWARF file - this can differ depending on which Split DWARF
682671
/// mode is being used, which is the logic that this function is intended to encapsulate.
683672
pub fn split_dwarf_path(

0 commit comments

Comments
 (0)