Skip to content

Commit ee073b5

Browse files
committed
cg_llvm: split dwarf filename and comp dir
llvm-dwp concatenates `DW_AT_comp_dir` with `DW_AT_GNU_dwo_name` (only when `DW_AT_comp_dir` exists), which can result in it failing to find the DWARF object files. In earlier testing, `DW_AT_comp_dir` wasn't present in the final object and the current directory was the output directory. When running tests through compiletest, the working directory of the compilation is different from output directory and that resulted in `DW_AT_comp_dir` being in the object file (and set to the current working directory, rather than the output directory), and `DW_AT_GNU_dwo_name` being set to the full path (rather than just the filename), so llvm-dwp was failing. This commit changes the compilation directory provided to LLVM to match the output directory, where DWARF objects are output; and ensures that only the filename is used for `DW_AT_GNU_dwo_name`. Signed-off-by: David Wood <[email protected]>
1 parent 99ad915 commit ee073b5

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ pub unsafe fn optimize_thin_module(
734734
let module_name = &thin_module.shared.module_names[thin_module.idx];
735735
let split_dwarf_file = cgcx
736736
.output_filenames
737-
.split_dwarf_file(cgcx.split_dwarf_kind, Some(module_name.to_str().unwrap()));
737+
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(module_name.to_str().unwrap()));
738738
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };
739739
let tm =
740740
(cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, &e))?;

compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
9595
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
9696
let split_dwarf_file = tcx
9797
.output_filenames(LOCAL_CRATE)
98-
.split_dwarf_file(tcx.sess.opts.debugging_opts.split_dwarf, Some(mod_name));
98+
.split_dwarf_filename(tcx.sess.opts.debugging_opts.split_dwarf, Some(mod_name));
9999
let config = TargetMachineFactoryConfig { split_dwarf_file };
100100
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE))(config)
101101
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -993,12 +993,14 @@ pub fn compile_unit_metadata(
993993
let producer = format!("clang LLVM ({})", rustc_producer);
994994

995995
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
996-
let work_dir = tcx.sess.working_dir.0.to_string_lossy();
997996
let flags = "\0";
997+
998+
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
998999
let split_name = tcx
9991000
.output_filenames(LOCAL_CRATE)
1000-
.split_dwarf_file(tcx.sess.opts.debugging_opts.split_dwarf, Some(codegen_unit_name))
1001+
.split_dwarf_filename(tcx.sess.opts.debugging_opts.split_dwarf, Some(codegen_unit_name))
10011002
.unwrap_or_default();
1003+
let out_dir = out_dir.to_str().unwrap();
10021004
let split_name = split_name.to_str().unwrap();
10031005

10041006
// FIXME(#60020):
@@ -1024,8 +1026,8 @@ pub fn compile_unit_metadata(
10241026
debug_context.builder,
10251027
name_in_debuginfo.as_ptr().cast(),
10261028
name_in_debuginfo.len(),
1027-
work_dir.as_ptr().cast(),
1028-
work_dir.len(),
1029+
out_dir.as_ptr().cast(),
1030+
out_dir.len(),
10291031
llvm::ChecksumKind::None,
10301032
ptr::null(),
10311033
0,

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl ModuleLlvm {
356356

357357
let split_dwarf_file = cgcx
358358
.output_filenames
359-
.split_dwarf_file(cgcx.split_dwarf_kind, Some(name.to_str().unwrap()));
359+
.split_dwarf_filename(cgcx.split_dwarf_kind, Some(name.to_str().unwrap()));
360360
let tm_factory_config = TargetMachineFactoryConfig { split_dwarf_file };
361361

362362
let tm = match (cgcx.tm_factory)(tm_factory_config) {

compiler/rustc_session/src/config.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,20 @@ impl OutputFilenames {
617617
path
618618
}
619619

620+
/// Returns the name of the Split DWARF file - this can differ depending on which Split DWARF
621+
/// mode is being used, which is the logic that this function is intended to encapsulate.
622+
pub fn split_dwarf_filename(
623+
&self,
624+
split_dwarf_kind: SplitDwarfKind,
625+
cgu_name: Option<&str>,
626+
) -> Option<PathBuf> {
627+
self.split_dwarf_path(split_dwarf_kind, cgu_name)
628+
.map(|path| path.strip_prefix(&self.out_directory).unwrap_or(&path).to_path_buf())
629+
}
630+
620631
/// Returns the path for the Split DWARF file - this can differ depending on which Split DWARF
621632
/// mode is being used, which is the logic that this function is intended to encapsulate.
622-
pub fn split_dwarf_file(
633+
pub fn split_dwarf_path(
623634
&self,
624635
split_dwarf_kind: SplitDwarfKind,
625636
cgu_name: Option<&str>,

0 commit comments

Comments
 (0)