Skip to content

Commit c41fd76

Browse files
committed
rustc_codegen_llvm: Give each codegen unit a unique DWARF name on all
platforms, not just Apple ones. To avoid breaking split DWARF, we need to ensure that each codegen unit has a unique `DW_AT_name`. This is because there's a remote chance that different codegen units for the same module will have entirely identical DWARF entries for the purpose of the DWO ID, which would violate Appendix F ("Split Dwarf Object Files") of the DWARF 5 specification. LLVM uses the algorithm specified in section 7.32 "Type Signature Computation" to compute the DWO ID, which does not include any fields that would distinguish compilation units. So we must embed the codegen unit name into the `DW_AT_name`. Closes #88521.
1 parent c5ecc15 commit c41fd76

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -1036,14 +1036,25 @@ pub fn compile_unit_metadata(
10361036
None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()),
10371037
};
10381038

1039-
// The OSX linker has an idiosyncrasy where it will ignore some debuginfo
1040-
// if multiple object files with the same `DW_AT_name` are linked together.
1041-
// As a workaround we generate unique names for each object file. Those do
1042-
// not correspond to an actual source file but that is harmless.
1043-
if tcx.sess.target.is_like_osx {
1044-
name_in_debuginfo.push("@");
1045-
name_in_debuginfo.push(codegen_unit_name);
1046-
}
1039+
// To avoid breaking split DWARF, we need to ensure that each codegen unit
1040+
// has a unique `DW_AT_name`. This is because there's a remote chance that
1041+
// different codegen units for the same module will have entirely
1042+
// identical DWARF entries for the purpose of the DWO ID, which would
1043+
// violate Appendix F ("Split Dwarf Object Files") of the DWARF 5
1044+
// specification. LLVM uses the algorithm specified in section 7.32 "Type
1045+
// Signature Computation" to compute the DWO ID, which does not include
1046+
// any fields that would distinguish compilation units. So we must embed
1047+
// the codegen unit name into the `DW_AT_name`. (Issue #88521.)
1048+
//
1049+
// Additionally, the OSX linker has an idiosyncrasy where it will ignore
1050+
// some debuginfo if multiple object files with the same `DW_AT_name` are
1051+
// linked together.
1052+
//
1053+
// As a workaround for these two issues, we generate unique names for each
1054+
// object file. Those do not correspond to an actual source file but that
1055+
// is harmless.
1056+
name_in_debuginfo.push("@");
1057+
name_in_debuginfo.push(codegen_unit_name);
10471058

10481059
debug!("compile_unit_metadata: {:?}", name_in_debuginfo);
10491060
let rustc_producer =

0 commit comments

Comments
 (0)