Index: llvm/lib/CodeGen/AsmPrinter/DIE.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ 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 { Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -52,10 +52,25 @@ using namespace llvm; +static dwarf::Tag GetCompileUnitType(DwarfDebug *DW, DwarfFile *DWU) { + + /* 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 && DWU->IsSkeletonFile()) + 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) { + : DwarfUnit(GetCompileUnitType(DW, DWU), Node, A, DW, DWU), + UniqueID(UID) { insertDIE(Node, &getUnitDie()); MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin"); } Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -342,8 +342,8 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M) : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()), - InfoHolder(A, "info_string", DIEValueAllocator), - SkeletonHolder(A, "skel_string", DIEValueAllocator), + InfoHolder(A, "info_string", DIEValueAllocator, false), + SkeletonHolder(A, "skel_string", DIEValueAllocator, true), IsDarwin(A->TM.getTargetTriple().isOSDarwin()) { const Triple &TT = Asm->TM.getTargetTriple(); Index: llvm/lib/CodeGen/AsmPrinter/DwarfFile.h =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfFile.h +++ llvm/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -103,8 +103,13 @@ /// of in DwarfCompileUnit. DenseMap DITypeNodeToDieMap; + /// That value indicates whether we are generating file + /// containing skeleton compilation units. + bool IsSkeleton = false; + public: - DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); + DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA, + bool isSkeleton); const SmallVectorImpl> &getUnits() { return CUs; @@ -113,6 +118,8 @@ std::pair addRange(const DwarfCompileUnit &CU, SmallVector R); + bool IsSkeletonFile() const { return IsSkeleton; } + /// getRangeLists - Get the vector of range lists. const SmallVectorImpl &getRangeLists() const { return CURangeLists; Index: llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp @@ -20,8 +20,10 @@ using namespace llvm; -DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA) - : Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref) {} +DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA, + bool isSkeleton) + : Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref), + IsSkeleton(isSkeleton) {} void DwarfFile::addUnit(std::unique_ptr U) { CUs.push_back(std::move(U)); Index: llvm/test/CodeGen/X86/dwarf-headers.ll =================================================================== --- llvm/test/CodeGen/X86/dwarf-headers.ll +++ 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 Index: llvm/test/DebugInfo/X86/debug_addr.ll =================================================================== --- llvm/test/DebugInfo/X86/debug_addr.ll +++ 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 Index: llvm/test/DebugInfo/X86/string-offsets-table-order.ll =================================================================== --- llvm/test/DebugInfo/X86/string-offsets-table-order.ll +++ 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: Index: llvm/test/DebugInfo/X86/string-offsets-table.ll =================================================================== --- llvm/test/DebugInfo/X86/string-offsets-table.ll +++ 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")