Skip to content

Commit bd5c636

Browse files
committed
DWARF: debug_names: Don't emit entries for skeleton type units
When a type unit is emitted, the CU referencing the type unit ends up with a little DW_TAG_*_type with the DW_AT_signature and DW_AT_declaration sometimes referred to (by me? maybe other people?) as a skeleton type. We shouldn't produce .debug_names reference to these - only to the actual type definition in the type unit. So this patch does that. But, inversely, the .debug_gnu_pubtypes /does/ need to reference the skeleton type (& gcc does this too, when it produces a skeleton type (gcc doesn't always produce these - if the type is only referenced once via DW_AT_type, gcc uses a direct DW_FORM_ref_sig8 on the DW_AT_type without the intermediate skeleton type)) - so there's a little special case added in to preserve that behavior which is covered by existing tests.
1 parent ab29203 commit bd5c636

File tree

5 files changed

+38
-48
lines changed

5 files changed

+38
-48
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,8 @@ void DwarfCompileUnit::addGlobalNameForTypeUnit(StringRef Name,
15391539
}
15401540

15411541
/// Add a new global type to the unit.
1542-
void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die,
1543-
const DIScope *Context) {
1542+
void DwarfCompileUnit::addGlobalTypeImpl(const DIType *Ty, const DIE &Die,
1543+
const DIScope *Context) {
15441544
if (!hasDwarfPubSections())
15451545
return;
15461546
std::string FullName = getParentContextString(Context) + Ty->getName().str();

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ class DwarfCompileUnit final : public DwarfUnit {
335335
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context);
336336

337337
/// Add a new global type to the compile unit.
338-
void addGlobalType(const DIType *Ty, const DIE &Die,
339-
const DIScope *Context) override;
338+
void addGlobalTypeImpl(const DIType *Ty, const DIE &Die,
339+
const DIScope *Context) override;
340340

341341
/// Add a new global type present in a type unit to this compile unit.
342342
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context);

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

+27-17
Original file line numberDiff line numberDiff line change
@@ -578,28 +578,33 @@ DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
578578
// Create new type.
579579
DIE &TyDIE = createAndAddDIE(Ty->getTag(), ContextDIE, Ty);
580580

581-
updateAcceleratorTables(Context, Ty, TyDIE);
581+
auto construct = [&](const auto *Ty) {
582+
updateAcceleratorTables(Context, Ty, TyDIE);
583+
constructTypeDIE(TyDIE, Ty);
584+
};
582585

583-
if (auto *BT = dyn_cast<DIBasicType>(Ty))
584-
constructTypeDIE(TyDIE, BT);
585-
else if (auto *ST = dyn_cast<DIStringType>(Ty))
586-
constructTypeDIE(TyDIE, ST);
587-
else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
588-
constructTypeDIE(TyDIE, STy);
589-
else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
586+
if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
590587
if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&
591588
(Ty->getRawName() || CTy->getRawIdentifier())) {
592589
// Skip updating the accelerator tables since this is not the full type.
593-
if (MDString *TypeId = CTy->getRawIdentifier())
590+
if (MDString *TypeId = CTy->getRawIdentifier()) {
591+
addGlobalType(Ty, TyDIE, Context);
594592
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
595-
else
593+
} else {
594+
updateAcceleratorTables(Context, Ty, TyDIE);
596595
finishNonUnitTypeDIE(TyDIE, CTy);
596+
}
597597
return &TyDIE;
598598
}
599-
constructTypeDIE(TyDIE, CTy);
600-
} else {
601-
constructTypeDIE(TyDIE, cast<DIDerivedType>(Ty));
602-
}
599+
construct(CTy);
600+
} else if (auto *BT = dyn_cast<DIBasicType>(Ty))
601+
construct(BT);
602+
else if (auto *ST = dyn_cast<DIStringType>(Ty))
603+
construct(ST);
604+
else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
605+
construct(STy);
606+
else
607+
construct(cast<DIDerivedType>(Ty));
603608

604609
return &TyDIE;
605610
}
@@ -650,9 +655,14 @@ void DwarfUnit::updateAcceleratorTables(const DIScope *Context,
650655
DD->addAccelType(*this, CUNode->getNameTableKind(), Ty->getName(), TyDIE,
651656
Flags);
652657

658+
addGlobalType(Ty, TyDIE, Context);
659+
}
660+
661+
void DwarfUnit::addGlobalType(const DIType *Ty, const DIE &TyDIE,
662+
const DIScope *Context) {
653663
if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
654664
isa<DINamespace>(Context) || isa<DICommonBlock>(Context))
655-
addGlobalType(Ty, TyDIE, Context);
665+
addGlobalTypeImpl(Ty, TyDIE, Context);
656666
}
657667

658668
void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
@@ -1849,8 +1859,8 @@ void DwarfTypeUnit::addGlobalName(StringRef Name, const DIE &Die,
18491859
getCU().addGlobalNameForTypeUnit(Name, Context);
18501860
}
18511861

1852-
void DwarfTypeUnit::addGlobalType(const DIType *Ty, const DIE &Die,
1853-
const DIScope *Context) {
1862+
void DwarfTypeUnit::addGlobalTypeImpl(const DIType *Ty, const DIE &Die,
1863+
const DIScope *Context) {
18541864
getCU().addGlobalTypeUnitType(Ty, Context);
18551865
}
18561866

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ class DwarfUnit : public DIEUnit {
128128
const DIScope *Context) = 0;
129129

130130
/// Add a new global type to the compile unit.
131-
virtual void addGlobalType(const DIType *Ty, const DIE &Die,
132-
const DIScope *Context) = 0;
131+
virtual void addGlobalTypeImpl(const DIType *Ty, const DIE &Die,
132+
const DIScope *Context) = 0;
133+
134+
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context);
133135

134136
/// Returns the DIE map slot for the specified debug variable.
135137
///
@@ -397,8 +399,8 @@ class DwarfTypeUnit final : public DwarfUnit {
397399
}
398400
void addGlobalName(StringRef Name, const DIE &Die,
399401
const DIScope *Context) override;
400-
void addGlobalType(const DIType *Ty, const DIE &Die,
401-
const DIScope *Context) override;
402+
void addGlobalTypeImpl(const DIType *Ty, const DIE &Die,
403+
const DIScope *Context) override;
402404
DwarfCompileUnit &getCU() override { return CU; }
403405
};
404406
} // end llvm namespace

llvm/test/DebugInfo/X86/debug-names-types.ll

+1-23
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
4949
; CHECK-NEXT: DW_IDX_parent: DW_FORM_flag_present
5050
; CHECK-NEXT: }
51-
; CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] {
52-
; CHECK-NEXT: Tag: DW_TAG_structure_type
53-
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
54-
; CHECK-NEXT: DW_IDX_parent: DW_FORM_flag_present
55-
; CHECK-NEXT: }
5651
; CHECK-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] {
5752
; CHECK-NEXT: Tag: DW_TAG_subprogram
5853
; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4
@@ -88,12 +83,6 @@
8883
; CHECK-NEXT: DW_IDX_die_offset: 0x00000023
8984
; CHECK-NEXT: DW_IDX_parent: <parent not indexed>
9085
; CHECK-NEXT: }
91-
; CHECK-NEXT: Entry @ {{.+}} {
92-
; CHECK-NEXT: Abbrev: [[ABBREV1]]
93-
; CHECK-NEXT: Tag: DW_TAG_structure_type
94-
; CHECK-NEXT: DW_IDX_die_offset: 0x00000042
95-
; CHECK-NEXT: DW_IDX_parent: <parent not indexed>
96-
; CHECK-NEXT: }
9786
; CHECK-NEXT: }
9887
; CHECK-NEXT: ]
9988
; CHECK-NEXT: Bucket 2 [
@@ -130,7 +119,7 @@
130119
; CHECK-SPLIT: Foreign TU count: 1
131120
; CHECK-SPLIT-NEXT: Bucket count: 4
132121
; CHECK-SPLIT-NEXT: Name count: 4
133-
; CHECK-SPLIT-NEXT: Abbreviations table size: 0x2D
122+
; CHECK-SPLIT-NEXT: Abbreviations table size: 0x25
134123
; CHECK-SPLIT-NEXT: Augmentation: 'LLVM0700'
135124
; CHECK-SPLIT-NEXT: }
136125
; CHECK-SPLIT-NEXT: Compilation Unit offsets [
@@ -151,11 +140,6 @@
151140
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4
152141
; CHECK-SPLIT-NEXT: DW_IDX_parent: DW_FORM_flag_present
153142
; CHECK-SPLIT-NEXT: }
154-
; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] {
155-
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
156-
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4
157-
; CHECK-SPLIT-NEXT: DW_IDX_parent: DW_FORM_flag_present
158-
; CHECK-SPLIT-NEXT: }
159143
; CHECK-SPLIT-NEXT: Abbreviation [[ABBREV3:0x[0-9a-f]*]] {
160144
; CHECK-SPLIT-NEXT: Tag: DW_TAG_subprogram
161145
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: DW_FORM_ref4
@@ -191,12 +175,6 @@
191175
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000021
192176
; CHECK-SPLIT-NEXT: DW_IDX_parent: <parent not indexed>
193177
; CHECK-SPLIT-NEXT: }
194-
; CHECK-SPLIT-NEXT: Entry @ {{.*}} {
195-
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]]
196-
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
197-
; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000039
198-
; CHECK-SPLIT-NEXT: DW_IDX_parent: <parent not indexed>
199-
; CHECK-SPLIT-NEXT: }
200178
; CHECK-SPLIT-NEXT: }
201179
; CHECK-SPLIT-NEXT: ]
202180
; CHECK-SPLIT-NEXT: Bucket 2 [

0 commit comments

Comments
 (0)