Skip to content

Commit ce0c205

Browse files
committed
DebugInfo: Include .dwo file name when hashing multiple CUs in a single file
This is really a workaround for ThinLTO in particular - since it can import partial CUs that may end up looking very similar/the same as the same partial import in another ThinLTO compile. An alternative fix would be to change the DICompileUnit metadata to include a "primary file" or the like - and when importing for ThinLTO set the primary file to the name of the DICompileUnit that is being imported into. This involves changing the schema and would reduce the excessive uniqueness in the hash that this change creates - allowing diagnosing of more duplicate CUs than will be caught with this change. But duplicate CUs can still be caught in non-ThinLTO builds & are mostly a nuisance rather than a particularly deliberate/effective tool for finding broken code. (arguably the hash could always include the dwo file and nothing in fission would break, I think..) llvm-svn: 304119
1 parent 02f8a07 commit ce0c205

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,12 @@ void DIEHash::computeHash(const DIE &Die) {
380380
/// DWARF4 standard. It is an md5 hash of the flattened description of the DIE
381381
/// with the inclusion of the full CU and all top level CU entities.
382382
// TODO: Initialize the type chain at 0 instead of 1 for CU signatures.
383-
uint64_t DIEHash::computeCUSignature(const DIE &Die) {
383+
uint64_t DIEHash::computeCUSignature(StringRef DWOName, const DIE &Die) {
384384
Numbering.clear();
385385
Numbering[&Die] = 1;
386386

387+
if (!DWOName.empty())
388+
Hash.update(DWOName);
387389
// Hash the DIE.
388390
computeHash(Die);
389391

llvm/lib/CodeGen/AsmPrinter/DIEHash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DIEHash {
3636
DIEHash(AsmPrinter *A = nullptr) : AP(A) {}
3737

3838
/// \brief Computes the CU signature.
39-
uint64_t computeCUSignature(const DIE &Die);
39+
uint64_t computeCUSignature(StringRef DWOName, const DIE &Die);
4040

4141
/// \brief Computes the type signature.
4242
uint64_t computeTypeSignature(const DIE &Die);

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ void DwarfDebug::finalizeModuleInfo() {
613613

614614
finishVariableDefinitions();
615615

616+
// Include the DWO file name in the hash if there's more than one CU.
617+
// This handles ThinLTO's situation where imported CUs may very easily be
618+
// duplicate with the same CU partially imported into another ThinLTO unit.
619+
StringRef DWOName;
620+
if (CUMap.size() > 1)
621+
DWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
622+
616623
// Handle anything that needs to be done on a per-unit basis after
617624
// all other generation.
618625
for (const auto &P : CUMap) {
@@ -627,7 +634,8 @@ void DwarfDebug::finalizeModuleInfo() {
627634
auto *SkCU = TheCU.getSkeleton();
628635
if (useSplitDwarf()) {
629636
// Emit a unique identifier for this CU.
630-
uint64_t ID = DIEHash(Asm).computeCUSignature(TheCU.getUnitDie());
637+
uint64_t ID =
638+
DIEHash(Asm).computeCUSignature(DWOName, TheCU.getUnitDie());
631639
TheCU.addUInt(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
632640
dwarf::DW_FORM_data8, ID);
633641
SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: %llc_dwarf -split-dwarf-file=foo.dwo %s -filetype=obj -o %T/a.o
2+
; RUN: %llc_dwarf -split-dwarf-file=bar.dwo %s -filetype=obj -o %T/b.o
3+
; RUN: llvm-dwarfdump -debug-dump=info %T/a.o %T/b.o | FileCheck %s
4+
5+
; CHECK: dwo_id {{.*}}([[HASH:.*]])
6+
; CHECK-NOT: dwo_id {{.*}}([[HASH]])
7+
8+
; Function Attrs: noinline nounwind uwtable
9+
define void @_Z1av() #0 !dbg !9 {
10+
entry:
11+
ret void, !dbg !12
12+
}
13+
14+
; Function Attrs: noinline nounwind uwtable
15+
define void @_Z1bv() #0 !dbg !13 {
16+
entry:
17+
ret void, !dbg !14
18+
}
19+
20+
attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
21+
22+
!llvm.dbg.cu = !{!0, !3}
23+
!llvm.ident = !{!5, !5}
24+
!llvm.module.flags = !{!6, !7, !8}
25+
26+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 304107) (llvm/trunk 304109)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
27+
!1 = !DIFile(filename: "a.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
28+
!2 = !{}
29+
!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 5.0.0 (trunk 304107) (llvm/trunk 304109)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
30+
!4 = !DIFile(filename: "b.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
31+
!5 = !{!"clang version 5.0.0 (trunk 304107) (llvm/trunk 304109)"}
32+
!6 = !{i32 2, !"Dwarf Version", i32 4}
33+
!7 = !{i32 2, !"Debug Info Version", i32 3}
34+
!8 = !{i32 1, !"wchar_size", i32 4}
35+
!9 = distinct !DISubprogram(name: "a", linkageName: "_Z1av", scope: !1, file: !1, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
36+
!10 = !DISubroutineType(types: !11)
37+
!11 = !{null}
38+
!12 = !DILocation(line: 2, column: 1, scope: !9)
39+
!13 = distinct !DISubprogram(name: "b", linkageName: "_Z1bv", scope: !4, file: !4, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, variables: !2)
40+
!14 = !DILocation(line: 2, column: 1, scope: !13)

0 commit comments

Comments
 (0)