Skip to content

Commit c215eea

Browse files
committed
[LLVM][DWARF] Create debug names entry for non-tu top level DIE
LLVM tries to create TU optimistically. If that fails it discards the TU state and creates TU wihin the CU. When this happens the entry in debug names table for top level DIE is not created. This causes llvm-dwarfdumjp --debug-names --verify to fail because an entry is missing. This patch adds a call to updateAcceleratorTables, when TU creation fails.
1 parent 1855333 commit c215eea

File tree

4 files changed

+92
-6
lines changed

4 files changed

+92
-6
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,19 +3704,19 @@ uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) {
37043704
return Result.high();
37053705
}
37063706

3707-
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
3707+
bool DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
37083708
StringRef Identifier, DIE &RefDie,
37093709
const DICompositeType *CTy) {
37103710
// Fast path if we're building some type units and one has already used the
37113711
// address pool we know we're going to throw away all this work anyway, so
37123712
// don't bother building dependent types.
37133713
if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
3714-
return;
3714+
return false;
37153715

37163716
auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0));
37173717
if (!Ins.second) {
37183718
CU.addDIETypeSignature(RefDie, Ins.first->second);
3719-
return;
3719+
return false;
37203720
}
37213721

37223722
setCurrentDWARF5AccelTable(DWARF5AccelTableKind::TU);
@@ -3789,7 +3789,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
37893789
// they depend on addresses, throwing them out and rebuilding them.
37903790
setCurrentDWARF5AccelTable(DWARF5AccelTableKind::CU);
37913791
CU.constructTypeDIE(RefDie, cast<DICompositeType>(CTy));
3792-
return;
3792+
return true;
37933793
}
37943794

37953795
// If the type wasn't dependent on fission addresses, finish adding the type
@@ -3811,6 +3811,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
38113811
setCurrentDWARF5AccelTable(DWARF5AccelTableKind::CU);
38123812
}
38133813
CU.addDIETypeSignature(RefDie, Signature);
3814+
return false;
38143815
}
38153816

38163817
// Add the Name along with its companion DIE to the appropriate accelerator

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,8 @@ class DwarfDebug : public DebugHandlerBase {
744744

745745
/// Add a DIE to the set of types that we're going to pull into
746746
/// type units.
747-
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
747+
/// Returns true if TU creation fails, and type was emitted in the CU.
748+
bool addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
748749
DIE &Die, const DICompositeType *CTy);
749750

750751
/// Add a label so that arange data can be generated for it.

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
589589
// Skip updating the accelerator tables since this is not the full type.
590590
if (MDString *TypeId = CTy->getRawIdentifier()) {
591591
addGlobalType(Ty, TyDIE, Context);
592-
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
592+
if (DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy))
593+
updateAcceleratorTables(Context, Ty, TyDIE);
593594
} else {
594595
updateAcceleratorTables(Context, Ty, TyDIE);
595596
finishNonUnitTypeDIE(TyDIE, CTy);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
; RUN: llc -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu < %s \
2+
; RUN: | llvm-dwarfdump -debug-info -debug-names - \
3+
; RUN: | FileCheck %s
4+
5+
;; Test that an entry in the debug names table gets created for a top level DIE when the creation of TU is aborted.
6+
7+
; CHECK: [[OFFSET:0x[0-9a-f]*]]: DW_TAG_structure_type
8+
; CHECK: [[OFFSET1:0x[0-9a-f]*]]: DW_TAG_structure_type
9+
10+
; CHECK: Bucket 0 [
11+
; CHECK-NEXT: Name 1 {
12+
; CHECK-NEXT: Hash: {{.+}}
13+
; CHECK-NEXT: String: {{.+}} "t3"
14+
; CHECK-NEXT: Entry @ {{.+}} {
15+
; CHECK-NEXT: Abbrev: 0x1
16+
; CHECK-NEXT: Tag: DW_TAG_structure_type
17+
; CHECK-NEXT: DW_IDX_die_offset: [[OFFSET]]
18+
; CHECK-NEXT: DW_IDX_parent: <parent not indexed>
19+
20+
; CHECK: Name 5 {
21+
; CHECK-NEXT: Hash: {{.+}}
22+
; CHECK-NEXT: String: {{.+}} "t2<&foo>"
23+
; CHECK-NEXT: Entry @ 0xe1 {
24+
; CHECK-NEXT: Abbrev: 0x1
25+
; CHECK-NEXT: Tag: DW_TAG_structure_type
26+
; CHECK-NEXT: DW_IDX_die_offset: [[OFFSET1]]
27+
; CHECK-NEXT: DW_IDX_parent: <parent not indexed>
28+
29+
;; clang++ -O0 main.cpp -gdwarf-5 -fdebug-types-section -gpubnames -S -emit-llvm -glldb -o main.ll
30+
;; int foo;
31+
;; namespace {
32+
;; struct t1 {};
33+
;; } // namespace
34+
;; template <int *> struct t2 {
35+
;; t1 v1;
36+
;; };
37+
;; struct t3 {
38+
;; t2<&foo> v1;
39+
;; };
40+
;; t3 v1;
41+
42+
; ModuleID = 'main.cpp'
43+
source_filename = "main.cpp"
44+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
45+
target triple = "x86_64-unknown-linux-gnu"
46+
47+
%struct.t3 = type { i8 }
48+
49+
@foo = dso_local global i32 0, align 4, !dbg !0
50+
@v1 = dso_local global %struct.t3 zeroinitializer, align 1, !dbg !5
51+
52+
!llvm.dbg.cu = !{!2}
53+
!llvm.module.flags = !{!20, !21, !22, !23, !24, !25, !26}
54+
!llvm.ident = !{!27}
55+
56+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
57+
!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !19, isLocal: false, isDefinition: true)
58+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 20.0.0git ([email protected]:llvm/llvm-project.git ba373096e8ac83a7136fc44bc4e71a7bc53417a6)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, sysroot: "/")
59+
!3 = !DIFile(filename: "main.cpp", directory: "/StructuredType", checksumkind: CSK_MD5, checksum: "f91f8d905197b1c0309da9526bc4776e")
60+
!4 = !{!0, !5}
61+
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
62+
!6 = distinct !DIGlobalVariable(name: "v1", scope: !2, file: !3, line: 11, type: !7, isLocal: false, isDefinition: true)
63+
!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t3", file: !3, line: 8, size: 8, flags: DIFlagTypePassByValue, elements: !8, identifier: "_ZTS2t3")
64+
!8 = !{!9}
65+
!9 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !7, file: !3, line: 9, baseType: !10, size: 8)
66+
!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t2<&foo>", file: !3, line: 5, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !16, identifier: "_ZTS2t2IXadL_Z3fooEEE")
67+
!11 = !{!12}
68+
!12 = !DIDerivedType(tag: DW_TAG_member, name: "v1", scope: !10, file: !3, line: 6, baseType: !13, size: 8)
69+
!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", scope: !14, file: !3, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !15)
70+
!14 = !DINamespace(scope: null)
71+
!15 = !{}
72+
!16 = !{!17}
73+
!17 = !DITemplateValueParameter(type: !18, value: ptr @foo)
74+
!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
75+
!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
76+
!20 = !{i32 7, !"Dwarf Version", i32 5}
77+
!21 = !{i32 2, !"Debug Info Version", i32 3}
78+
!22 = !{i32 1, !"wchar_size", i32 4}
79+
!23 = !{i32 8, !"PIC Level", i32 2}
80+
!24 = !{i32 7, !"PIE Level", i32 2}
81+
!25 = !{i32 7, !"uwtable", i32 2}
82+
!26 = !{i32 7, !"frame-pointer", i32 2}
83+
!27 = !{!"clang version 20.0.0git ([email protected]:llvm/llvm-project.git ba373096e8ac83a7136fc44bc4e71a7bc53417a6)"}

0 commit comments

Comments
 (0)