Index: llvm/include/llvm/CodeGen/AsmPrinter.h =================================================================== --- llvm/include/llvm/CodeGen/AsmPrinter.h +++ llvm/include/llvm/CodeGen/AsmPrinter.h @@ -574,16 +574,17 @@ void emitCFIInstruction(const MCCFIInstruction &Inst) const; /// Emit Dwarf abbreviation table. - template void emitDwarfAbbrevs(const T &Abbrevs) const { + template + void emitDwarfAbbrevs(const T &Abbrevs, bool EmitForSkeleton) const { // For each abbreviation. for (const auto &Abbrev : Abbrevs) - emitDwarfAbbrev(*Abbrev); + emitDwarfAbbrev(*Abbrev, EmitForSkeleton); // Mark end of abbreviations. EmitULEB128(0, "EOM(3)"); } - void emitDwarfAbbrev(const DIEAbbrev &Abbrev) const; + void emitDwarfAbbrev(const DIEAbbrev &Abbrev, bool EmitForSkeleton) const; /// Recursively emit Dwarf DIE tree. void emitDwarfDIE(const DIE &Die) const; Index: llvm/include/llvm/CodeGen/DIE.h =================================================================== --- llvm/include/llvm/CodeGen/DIE.h +++ llvm/include/llvm/CodeGen/DIE.h @@ -119,7 +119,7 @@ void Profile(FoldingSetNodeID &ID) const; /// Print the abbreviation using the specified asm printer. - void Emit(const AsmPrinter *AP) const; + void Emit(const AsmPrinter *AP, bool EmitForSkeleton) const; void print(raw_ostream &O) const; void dump() const; @@ -154,7 +154,8 @@ DIEAbbrev &uniqueAbbreviation(DIE &Die); /// Print all abbreviations using the specified asm printer. - void Emit(const AsmPrinter *AP, MCSection *Section) const; + void Emit(const AsmPrinter *AP, MCSection *Section, + bool EmitForSkeleton) const; }; //===--------------------------------------------------------------------===// Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp @@ -284,10 +284,11 @@ } } -void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev) const { +void AsmPrinter::emitDwarfAbbrev(const DIEAbbrev &Abbrev, + bool EmitForSkeleton) const { // Emit the abbreviations code (base 1 index.) EmitULEB128(Abbrev.getNumber(), "Abbreviation Code"); // Emit the abbreviations data. - Abbrev.Emit(this); + Abbrev.Emit(this, EmitForSkeleton); } Index: llvm/lib/CodeGen/AsmPrinter/DIE.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ llvm/lib/CodeGen/AsmPrinter/DIE.cpp @@ -65,9 +65,21 @@ /// Emit - Print the abbreviation using the specified asm printer. /// -void DIEAbbrev::Emit(const AsmPrinter *AP) const { +void DIEAbbrev::Emit(const AsmPrinter *AP, bool EmitForSkeleton) const { // Emit its Dwarf tag type. - AP->EmitULEB128(Tag, dwarf::TagString(Tag).data()); + if (EmitForSkeleton && + (AP->getDwarfDebug() && AP->getDwarfDebug()->getDwarfVersion() >= 5) && + Tag == dwarf::DW_TAG_compile_unit) + /* 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" + */ + AP->EmitULEB128(dwarf::DW_TAG_skeleton_unit, + dwarf::TagString(dwarf::DW_TAG_skeleton_unit).data()); + else + AP->EmitULEB128(Tag, dwarf::TagString(Tag).data()); // Emit whether it has children DIEs. AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data()); @@ -167,11 +179,12 @@ return *New; } -void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const { +void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section, + bool EmitForSkeleton) const { if (!Abbreviations.empty()) { // Start the debug abbrev section. AP->OutStreamer->SwitchSection(Section); - AP->emitDwarfAbbrevs(Abbreviations); + AP->emitDwarfAbbrevs(Abbreviations, EmitForSkeleton); } } 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; 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)); @@ -93,7 +95,9 @@ return Die.computeOffsetsAndAbbrevs(Asm, Abbrevs, Offset); } -void DwarfFile::emitAbbrevs(MCSection *Section) { Abbrevs.Emit(Asm, Section); } +void DwarfFile::emitAbbrevs(MCSection *Section) { + Abbrevs.Emit(Asm, Section, IsSkeleton); +} // Emit strings into a string section. void DwarfFile::emitStrings(MCSection *StrSection, MCSection *OffsetSection, 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") Index: llvm/tools/dsymutil/DwarfStreamer.cpp =================================================================== --- llvm/tools/dsymutil/DwarfStreamer.cpp +++ llvm/tools/dsymutil/DwarfStreamer.cpp @@ -181,7 +181,7 @@ unsigned DwarfVersion) { MS->SwitchSection(MOFI->getDwarfAbbrevSection()); MC->setDwarfVersion(DwarfVersion); - Asm->emitDwarfAbbrevs(Abbrevs); + Asm->emitDwarfAbbrevs(Abbrevs, false); } /// Recursively emit the DIE tree rooted at \p Die. Index: llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp =================================================================== --- llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -492,7 +492,7 @@ SecOffset += CUOffset; CU->setLength(CUOffset - 4); } - Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection()); + Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection(), false); StringPool->emitStringOffsetsTableHeader(*Asm, TLOF->getDwarfStrOffSection(), StringOffsetsStartSym);