Skip to content

Commit 0e4c7fa

Browse files
authored
[DebugInfo] (Always) include the dwo name in the hash (#100375)
Since ce0c205, we are doing that if a single (LTO) compilation contains more than one compile unit, but the same thing can happen if the non-lto and single-cu lto compilations, typically when the CU ends up (nearly) empty. In my case, this happened when LTO emptied two compile units. Note that the source file name is already a part of the hash, so this can only happen when a single file is compiled and linked twice into the same application (most likely with different preprocessor defintiions). While not exactly common, this pattern is used by some C code to implement "templates". The 2017 patch already hinted at the possibility of doing this unconditionally, and this patch implements that. While the DWARF spec hints at the option of using the type signature hashing algorithm for the DWO_id purposes, AFAICT it does not actually require it, so I believe this change is still conforming. The relevant section of the spec is in Section 3.1.2 "Skeleton Compilation Unit Entries" (in non-normative text): ``` The means of determining a compilation unit ID does not need to be similar or related to the means of determining a type unit signature. However, it should be suitable for detecting file version skew or other kinds of mismatched files and for looking up a full split unit in a DWARF package file (see Section 7.3.5 on page 190). ```
1 parent 9884fd3 commit 0e4c7fa

File tree

15 files changed

+74
-91
lines changed

15 files changed

+74
-91
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,13 +1260,6 @@ void DwarfDebug::finalizeModuleInfo() {
12601260

12611261
finishEntityDefinitions();
12621262

1263-
// Include the DWO file name in the hash if there's more than one CU.
1264-
// This handles ThinLTO's situation where imported CUs may very easily be
1265-
// duplicate with the same CU partially imported into another ThinLTO unit.
1266-
StringRef DWOName;
1267-
if (CUMap.size() > 1)
1268-
DWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
1269-
12701263
bool HasEmittedSplitCU = false;
12711264

12721265
// Handle anything that needs to be done on a per-unit basis after
@@ -1295,11 +1288,13 @@ void DwarfDebug::finalizeModuleInfo() {
12951288
? dwarf::DW_AT_dwo_name
12961289
: dwarf::DW_AT_GNU_dwo_name;
12971290
finishUnitAttributes(TheCU.getCUNode(), TheCU);
1298-
TheCU.addString(TheCU.getUnitDie(), attrDWOName,
1299-
Asm->TM.Options.MCOptions.SplitDwarfFile);
1300-
SkCU->addString(SkCU->getUnitDie(), attrDWOName,
1301-
Asm->TM.Options.MCOptions.SplitDwarfFile);
1302-
// Emit a unique identifier for this CU.
1291+
StringRef DWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
1292+
TheCU.addString(TheCU.getUnitDie(), attrDWOName, DWOName);
1293+
SkCU->addString(SkCU->getUnitDie(), attrDWOName, DWOName);
1294+
// Emit a unique identifier for this CU. Include the DWO file name in the
1295+
// hash to avoid the case where two (almost) empty compile units have the
1296+
// same contents. This can happen if link-time optimization removes nearly
1297+
// all (unused) code from a CU.
13031298
uint64_t ID =
13041299
DIEHash(Asm, &TheCU).computeCUSignature(DWOName, TheCU.getUnitDie());
13051300
if (getDwarfVersion() >= 5) {

llvm/test/CodeGen/X86/dwarf-headers.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
; RUN: -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
1313
; RUN: | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SINGLE-5
1414

15-
; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
15+
; RUN: llc -split-dwarf-file=foo.dwo \
1616
; RUN: -dwarf-version=5 -generate-type-units \
1717
; RUN: -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
1818
; RUN: | llvm-dwarfdump -v - | FileCheck %s --check-prefix=O-5
19-
; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s --check-prefix=DWO-5
2019

2120
; Looking for DWARF headers to be generated correctly.
2221
; There are 8 variants with 5 formats: v4 CU, v4 TU, v5 normal/partial CU,
@@ -74,15 +73,15 @@
7473
;
7574
; O-5: .debug_info contents:
7675
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
77-
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
76+
; O-5-SAME: DWO_id = [[HASH:0x[0-9a-f]*]]
7877
; O-5: 0x00000014: DW_TAG_skeleton_unit
7978
;
80-
; DWO-5: .debug_info.dwo contents:
81-
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
82-
; DWO-5: 0x00000018: DW_TAG_type_unit
83-
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
84-
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
85-
; DWO-5: 0x00000049: DW_TAG_compile_unit
79+
; O-5: .debug_info.dwo contents:
80+
; O-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
81+
; O-5: 0x00000018: DW_TAG_type_unit
82+
; O-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
83+
; O-5-SAME: DWO_id = [[HASH]]
84+
; O-5: 0x00000049: DW_TAG_compile_unit
8685

8786

8887
; ModuleID = 't.cpp'

llvm/test/DebugInfo/COFF/fission-cu.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
6262
; CHECK-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
6363
; CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000000] = "e:\\llvm-project\\tmp")
6464
; CHECK-NEXT: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000014] = "baz.dwo")
65-
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
65+
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH:0x[0-9a-f]*]])
6666

6767
; Check that the rest of the compile units have information.
6868
; CHECK: .debug_info.dwo contents:
@@ -74,7 +74,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
7474
; CHECK-NOT: DW_AT_low_pc
7575
; CHECK-NOT: DW_AT_stmt_list
7676
; CHECK-NOT: DW_AT_comp_dir
77-
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
77+
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH]])
7878
; CHECK: DW_TAG_variable
7979
; CHECK: DW_AT_name [DW_FORM_GNU_str_index] (indexed (00000000) string = "a")
8080
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]}

llvm/test/DebugInfo/COFF/fission-sections.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
5151
; DWO-NEXT: [ 2](sec 2)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .debug_str_offsets.dwo
5252
; DWO-NEXT: AUX scnlen 0x14 nreloc 0 nlnno 0 checksum 0x9392f0f0 assoc 2 comdat 0
5353
; DWO-NEXT: [ 4](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .debug_info.dwo
54-
; DWO-NEXT: AUX scnlen 0x29 nreloc 0 nlnno 0 checksum 0xc8e5b275 assoc 3 comdat 0
54+
; DWO-NEXT: AUX scnlen 0x29 nreloc 0 nlnno 0 checksum 0x{{[0-9a-f]*}} assoc 3 comdat 0
5555
; DWO-NEXT: [ 6](sec 4)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .debug_abbrev.dwo
5656
; DWO-NEXT: AUX scnlen 0x33 nreloc 0 nlnno 0 checksum 0x8056e5e4 assoc 4 comdat 0
5757
; DWO-EMPTY:

llvm/test/DebugInfo/WebAssembly/dwarf-headers.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
; RUN: -filetype=obj -O0 -mtriple= < %s \
1313
; RUN: | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SINGLE-5
1414

15-
; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
15+
; RUN: llc -split-dwarf-file=foo.dwo \
1616
; RUN: -dwarf-version=5 -generate-type-units \
1717
; RUN: -filetype=obj -O0 -mtriple= < %s \
1818
; RUN: | llvm-dwarfdump -v - | FileCheck %s --check-prefix=O-5
19-
; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s --check-prefix=DWO-5
2019

2120
; This test is derived from test/CodeGen/X86/dwarf-headers.ll
2221

@@ -76,15 +75,15 @@
7675
;
7776
; O-5: .debug_info contents:
7877
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
79-
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
78+
; O-5-SAME: DWO_id = [[HASH:0x[0-9a-f]*]]
8079
; O-5: 0x00000014: DW_TAG_skeleton_unit
8180
;
82-
; DWO-5: .debug_info.dwo contents:
83-
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
84-
; DWO-5: 0x00000018: DW_TAG_type_unit
85-
; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
86-
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
87-
; DWO-5: 0x00000049: DW_TAG_compile_unit
81+
; O-5: .debug_info.dwo contents:
82+
; O-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
83+
; O-5: 0x00000018: DW_TAG_type_unit
84+
; O-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
85+
; O-5-SAME: DWO_id = [[HASH]]
86+
; O-5: 0x00000049: DW_TAG_compile_unit
8887

8988

9089
; ModuleID = 't.cpp'

llvm/test/DebugInfo/WebAssembly/fission-cu.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ source_filename = "test/DebugInfo/WebAssembly/fission-cu.ll"
6262
; CHECK-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
6363
; CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000000] = "/usr/local/google/home/echristo/tmp")
6464
; CHECK-NEXT: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000024] = "baz.dwo")
65-
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
65+
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH:0x[0-9a-f]*]])
6666

6767
; Check that the rest of the compile units have information.
6868
; CHECK: .debug_info.dwo contents:
@@ -74,7 +74,7 @@ source_filename = "test/DebugInfo/WebAssembly/fission-cu.ll"
7474
; CHECK-NOT: DW_AT_low_pc
7575
; CHECK-NOT: DW_AT_stmt_list
7676
; CHECK-NOT: DW_AT_comp_dir
77-
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
77+
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH]])
7878
; CHECK: DW_TAG_variable
7979
; CHECK: DW_AT_name [DW_FORM_GNU_str_index] (indexed (00000000) string = "a")
8080
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]}

llvm/test/DebugInfo/X86/convert-debugloc.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
; RUN: | FileCheck %s --check-prefix=VERBOSE --check-prefix=CONV "--implicit-check-not={{DW_TAG|NULL}}"
2828

2929

30-
; SPLITCONV: Compile Unit:{{.*}} DWO_id = 0x06580df9fdd5b54b
30+
;; NB: This checks that the type reference in DW_OP_convert participates in the
31+
;; DWO hash.
32+
; SPLITCONV: Compile Unit:{{.*}} DWO_id = 0xbf4ac610d9ea282c
3133
; SPLIT: DW_TAG_skeleton_unit
3234

3335
; CONV: DW_TAG_compile_unit

llvm/test/DebugInfo/X86/convert-loclist.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
; often - add another IR file with a different DW_OP_convert that's otherwise
1414
; identical and demonstrate that they have different DWO IDs.
1515

16-
; SPLIT: 0x00000000: Compile Unit: {{.*}} DWO_id = 0x4dbee91db55385db
16+
; SPLIT: 0x00000000: Compile Unit: {{.*}} DWO_id = 0x6f8c6730fe6cbff0
1717

1818
; Regression testing a fairly quirky bug where instead of hashing (see above),
1919
; extra bytes would be emitted into the output assembly in no

llvm/test/DebugInfo/X86/fission-cu.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
6060
; CHECK-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
6161
; CHECK-NEXT: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000000] = "/usr/local/google/home/echristo/tmp")
6262
; CHECK-NEXT: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000024] = "baz.dwo")
63-
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
63+
; CHECK-NEXT: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH:0x[0-9a-f]*]])
6464

6565
; Check that the rest of the compile units have information.
6666
; CHECK: .debug_info.dwo contents:
@@ -72,7 +72,7 @@ source_filename = "test/DebugInfo/X86/fission-cu.ll"
7272
; CHECK-NOT: DW_AT_low_pc
7373
; CHECK-NOT: DW_AT_stmt_list
7474
; CHECK-NOT: DW_AT_comp_dir
75-
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
75+
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] ([[HASH]])
7676
; CHECK: DW_TAG_variable
7777
; CHECK: DW_AT_name [DW_FORM_GNU_str_index] (indexed (00000000) string = "a")
7878
; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]}

llvm/test/DebugInfo/X86/fission-hash-local.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
; int i = 7; // or 9
1414
; }
1515

16-
; H1: DW_AT_GNU_dwo_id (0xc1220cf66b1190ad)
17-
; H2: DW_AT_GNU_dwo_id (0xf66067a0cf366f0e)
16+
; H1: DW_AT_GNU_dwo_id (0xb06b36aa6004befe)
17+
; H2: DW_AT_GNU_dwo_id (0xc3e980cf3dfa79a2)
1818

1919
; Function Attrs: norecurse nounwind readnone uwtable
2020
define dso_local void @_Z2f1v() local_unnamed_addr !dbg !7 {

llvm/test/DebugInfo/X86/fission-hash.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
; The source is an empty file, modified to include/retain an 'int' type, since empty CUs are omitted.
55

6-
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x50d985146a74bb00)
7-
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x50d985146a74bb00)
6+
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0xb1b50e9a23896bc1)
7+
; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0xb1b50e9a23896bc1)
88

99
!llvm.dbg.cu = !{!0}
1010
!llvm.module.flags = !{!3, !4}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: rm -rf %t && mkdir -p %t
2+
; RUN: llc -split-dwarf-file=foo.dwo %s -filetype=obj -o %t/a.o
3+
; RUN: llc -split-dwarf-file=bar.dwo %s -filetype=obj -o %t/b.o
4+
; RUN: llvm-dwarfdump -debug-info %t/a.o %t/b.o | FileCheck %s
5+
6+
; CHECK: {{.*}}a.o: file format elf64-x86-64
7+
; CHECK: 0x00000000: Compile Unit: {{.*}}, DWO_id = [[HASH:0x[0-9a-f]*]]
8+
; CHECK: {{.*}}b.o: file format elf64-x86-64
9+
; CHECK-NOT: DWO_id = [[HASH]]
10+
11+
target triple = "x86_64-pc-linux"
12+
13+
; Function Attrs: noinline nounwind uwtable
14+
define void @_Z1av() !dbg !9 {
15+
entry:
16+
ret void, !dbg !12
17+
}
18+
19+
!llvm.dbg.cu = !{!0}
20+
!llvm.ident = !{!5}
21+
!llvm.module.flags = !{!6, !7, !8}
22+
23+
!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)
24+
!1 = !DIFile(filename: "a.cpp", directory: "/tmp")
25+
!2 = !{}
26+
!5 = !{!"clang version 5.0.0 (trunk 304107) (llvm/trunk 304109)"}
27+
!6 = !{i32 2, !"Dwarf Version", i32 5}
28+
!7 = !{i32 2, !"Debug Info Version", i32 3}
29+
!8 = !{i32 1, !"wchar_size", i32 4}
30+
!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, retainedNodes: !2)
31+
!10 = !DISubroutineType(types: !11)
32+
!11 = !{null}
33+
!12 = !DILocation(line: 2, column: 1, scope: !9)

llvm/test/DebugInfo/X86/split-dwarf-multiple-cu-hash.ll

Lines changed: 0 additions & 45 deletions
This file was deleted.

llvm/test/DebugInfo/X86/sret.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
; Based on the debuginfo-tests/sret.cpp code.
77

8-
; CHECK-DWO: DW_AT_GNU_dwo_id (0x7db1cc8453a47c44)
9-
; CHECK-DWO: DW_AT_GNU_dwo_id (0x7db1cc8453a47c44)
8+
; CHECK-DWO: DW_AT_GNU_dwo_id (0x044dcdf3d75b11a1)
9+
; CHECK-DWO: DW_AT_GNU_dwo_id (0x044dcdf3d75b11a1)
1010

1111
; RUN: llc -O0 -fast-isel=true -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | llvm-dwarfdump -debug-info - | FileCheck -check-prefixes=CHECK,FASTISEL %s
1212
; RUN: llc -O0 -fast-isel=false -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | llvm-dwarfdump -debug-info - | FileCheck -check-prefixes=CHECK,SDAG %s

llvm/test/MC/WebAssembly/dwarfdump.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
; SPLIT-NEXT: DW_AT_language (DW_LANG_C99)
6767
; SPLIT-NEXT: DW_AT_name ("test.c")
6868
; SPLIT-NEXT: DW_AT_GNU_dwo_name ("{{.*}}dwarfdump.ll.tmp.dwo")
69-
; SPLIT-NEXT: DW_AT_GNU_dwo_id (0xad3151f12153fa17)
69+
; SPLIT-NEXT: DW_AT_GNU_dwo_id ({{.*}})
7070

7171
; SPLIT: 0x00000019: DW_TAG_variable
7272
; SPLIT-NEXT: DW_AT_name ("foo")

0 commit comments

Comments
 (0)