diff --git a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp @@ -319,8 +319,10 @@ { Die.Owner = this; assert((UnitTag == dwarf::DW_TAG_compile_unit || + UnitTag == dwarf::DW_TAG_skeleton_unit || UnitTag == dwarf::DW_TAG_type_unit || - UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG"); + UnitTag == dwarf::DW_TAG_partial_unit) && + "expected a unit TAG"); } void DIEValue::EmitValue(const AsmPrinter *AP) const { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -40,6 +40,8 @@ class MCSymbol; class MDNode; +enum class UnitKind { Skeleton, Full }; + class DwarfCompileUnit final : public DwarfUnit { /// A numeric ID unique among all CUs in the module unsigned UniqueID; @@ -104,7 +106,8 @@ public: DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, - DwarfDebug *DW, DwarfFile *DWU); + DwarfDebug *DW, DwarfFile *DWU, + UnitKind Kind = UnitKind::Full); bool hasRangeLists() const { return HasRangeLists; } unsigned getUniqueID() const { return UniqueID; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -52,10 +52,23 @@ using namespace llvm; +static dwarf::Tag GetCompileUnitType(UnitKind Kind, DwarfDebug *DW) { + + // According to DWARF Debugging Information Format Version 5, + // 3.1.2 Skeleton Compilation Unit Entries: + // "When generating a split DWARF object file (see Section 7.3.2 + // on page 187), the compilation unit in the .debug_info section + // is a "skeleton" compilation unit with the tag DW_TAG_skeleton_unit" + if (DW->getDwarfVersion() >= 5 && Kind == UnitKind::Skeleton) + return dwarf::DW_TAG_skeleton_unit; + + return dwarf::DW_TAG_compile_unit; +} + DwarfCompileUnit::DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, - DwarfFile *DWU) - : DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID) { + DwarfFile *DWU, UnitKind Kind) + : DwarfUnit(GetCompileUnitType(Kind, DW), Node, A, DW, DWU), UniqueID(UID) { insertDIE(Node, &getUnitDie()); MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin"); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2821,7 +2821,8 @@ DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) { auto OwnedUnit = std::make_unique( - CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder); + CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder, + UnitKind::Skeleton); DwarfCompileUnit &NewCU = *OwnedUnit; NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection()); diff --git a/llvm/test/CodeGen/X86/dwarf-headers.ll b/llvm/test/CodeGen/X86/dwarf-headers.ll --- a/llvm/test/CodeGen/X86/dwarf-headers.ll +++ b/llvm/test/CodeGen/X86/dwarf-headers.ll @@ -75,7 +75,7 @@ ; O-5: .debug_info contents: ; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005 unit_type = DW_UT_skeleton abbr_offset ; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6 -; O-5: 0x00000014: DW_TAG_compile_unit +; O-5: 0x00000014: DW_TAG_skeleton_unit ; ; DWO-5: .debug_info.dwo contents: ; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005 unit_type = DW_UT_split_type abbr_offset diff --git a/llvm/test/DebugInfo/X86/debug_addr.ll b/llvm/test/DebugInfo/X86/debug_addr.ll --- a/llvm/test/DebugInfo/X86/debug_addr.ll +++ b/llvm/test/DebugInfo/X86/debug_addr.ll @@ -28,7 +28,7 @@ ; DWARF5: .debug_info contents: ; DWARF5: Compile Unit:{{.*}}version = 0x0005 ; DWARF5-NOT: Compile Unit -; DWARF5: DW_TAG_compile_unit +; DWARF5: DW_TAG_skeleton_unit ; DWARF5-NOT: DW_TAG_{{.*}} ; DWARF5: DW_AT_GNU_dwo_name{{.*}}test.dwo ; DWARF5: DW_AT_addr_base{{.*}}0x00000008 diff --git a/llvm/test/DebugInfo/X86/string-offsets-table-order.ll b/llvm/test/DebugInfo/X86/string-offsets-table-order.ll --- a/llvm/test/DebugInfo/X86/string-offsets-table-order.ll +++ b/llvm/test/DebugInfo/X86/string-offsets-table-order.ll @@ -12,11 +12,11 @@ ; in different order. ; CHECK: .debug_info contents: -; CHECK: DW_TAG_compile_unit +; CHECK: DW_TAG_skeleton_unit ; CHECK: DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000000) string = "X3") -; CHECK: DW_TAG_compile_unit +; CHECK: DW_TAG_skeleton_unit ; CHECK: DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000001) string = "X2") -; CHECK: DW_TAG_compile_unit +; CHECK: DW_TAG_skeleton_unit ; CHECK: DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000002) string = "X1") ; CHECK: .debug_info.dwo contents: diff --git a/llvm/test/DebugInfo/X86/string-offsets-table.ll b/llvm/test/DebugInfo/X86/string-offsets-table.ll --- a/llvm/test/DebugInfo/X86/string-offsets-table.ll +++ b/llvm/test/DebugInfo/X86/string-offsets-table.ll @@ -56,7 +56,7 @@ ; SPLIT: .debug_info contents: ; SPLIT-NEXT: 0x00000000: Compile Unit:{{.*}}DW_UT_skeleton ; SPLIT-NOT: contents: -; SPLIT: DW_TAG_compile_unit +; SPLIT: DW_TAG_skeleton_unit ; SPLIT-NOT: {{DW_TAG|contents:}} ; SPLIT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008) ; SPLIT: DW_AT_comp_dir [DW_FORM_strx1] (indexed (00000000) string = "/home/test")