Skip to content

Commit 53a95ea

Browse files
authored
Rollup merge of #92024 - pcwalton:per-codegen-unit-names, r=davidtwco
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.
2 parents ca3d129 + c41fd76 commit 53a95ea

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
@@ -1040,14 +1040,25 @@ pub fn compile_unit_metadata<'ll, 'tcx>(
10401040
None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()),
10411041
};
10421042

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

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

0 commit comments

Comments
 (0)