diff --git a/llvm/include/llvm/CodeGen/AccelTable.h b/llvm/include/llvm/CodeGen/AccelTable.h index d521b31e3d16a..537f6a4d42bef 100644 --- a/llvm/include/llvm/CodeGen/AccelTable.h +++ b/llvm/include/llvm/CodeGen/AccelTable.h @@ -106,6 +106,7 @@ namespace llvm { class AsmPrinter; class DwarfCompileUnit; class DwarfDebug; +class DwarfTypeUnit; class MCSymbol; class raw_ostream; @@ -197,6 +198,9 @@ template class AccelTable : public AccelTableBase { template void addName(DwarfStringPoolEntryRef Name, Types &&... Args); + void clear() { Entries.clear(); } + void addEntries(AccelTable &Table); + const StringEntries getEntries() const { return Entries; } }; template @@ -215,6 +219,16 @@ void AccelTable::addName(DwarfStringPoolEntryRef Name, AccelTableDataT(std::forward(Args)...)); } +template +void AccelTable::addEntries( + AccelTable &Table) { + for (auto &Entry : Table.getEntries()) { + for (AccelTableData *Value : Entry.second.Values) + addName(Entry.second.Name, + static_cast(Value)->getDie()); + } +} + /// A base class for different implementations of Data classes for Apple /// Accelerator Tables. The columns in the table are defined by the static Atoms /// variable defined on the subclasses. @@ -250,6 +264,10 @@ class AppleAccelTableData : public AccelTableData { /// emitDWARF5AccelTable function. class DWARF5AccelTableData : public AccelTableData { public: + struct AttributeEncoding { + dwarf::Index Index; + dwarf::Form Form; + }; static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); } DWARF5AccelTableData(const DIE &Die) : Die(Die) {} @@ -309,17 +327,20 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable &Contents, void emitDWARF5AccelTable(AsmPrinter *Asm, AccelTable &Contents, const DwarfDebug &DD, - ArrayRef> CUs); - + ArrayRef> CUs, + ArrayRef> TUs); +using GetIndexForEntryReturnType = + std::optional>; /// Emit a DWARFv5 Accelerator Table consisting of entries in the specified /// AccelTable. The \p CUs contains either symbols keeping offsets to the /// start of compilation unit, either offsets to the start of compilation /// unit themselves. -void emitDWARF5AccelTable( - AsmPrinter *Asm, AccelTable &Contents, - ArrayRef> CUs, - llvm::function_ref - getCUIndexForEntry); +void emitDWARF5AccelTable(AsmPrinter *Asm, + AccelTable &Contents, + ArrayRef> CUs, + llvm::function_ref + getIndexForEntry); /// Accelerator table data implementation for simple Apple accelerator tables /// with just a DIE reference. diff --git a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp index 8f936037d1325..5510932e96d25 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp @@ -13,7 +13,6 @@ #include "llvm/CodeGen/AccelTable.h" #include "DwarfCompileUnit.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringMap.h" #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/CodeGen/AsmPrinter.h" @@ -200,32 +199,30 @@ class Dwarf5AccelTableWriter : public AccelTableWriter { uint32_t AugmentationStringSize = sizeof(AugmentationString); char AugmentationString[8] = {'L', 'L', 'V', 'M', '0', '7', '0', '0'}; - Header(uint32_t CompUnitCount, uint32_t BucketCount, uint32_t NameCount) - : CompUnitCount(CompUnitCount), BucketCount(BucketCount), - NameCount(NameCount) {} + Header(uint32_t CompUnitCount, uint32_t LocalTypeUnitCount, + uint32_t BucketCount, uint32_t NameCount) + : CompUnitCount(CompUnitCount), LocalTypeUnitCount(LocalTypeUnitCount), + BucketCount(BucketCount), NameCount(NameCount) {} void emit(Dwarf5AccelTableWriter &Ctx); }; - struct AttributeEncoding { - dwarf::Index Index; - dwarf::Form Form; - }; Header Header; - DenseMap> Abbreviations; + DenseMap> + Abbreviations; ArrayRef> CompUnits; - llvm::function_ref getCUIndexForEntry; + ArrayRef> TypeUnits; + llvm::function_ref + getIndexForEntry; MCSymbol *ContributionEnd = nullptr; MCSymbol *AbbrevStart = Asm->createTempSymbol("names_abbrev_start"); MCSymbol *AbbrevEnd = Asm->createTempSymbol("names_abbrev_end"); MCSymbol *EntryPool = Asm->createTempSymbol("names_entries"); - DenseSet getUniqueTags() const; - - // Right now, we emit uniform attributes for all tags. - SmallVector getUniformAttributes() const; + void populateAbbrevsMap(); void emitCUList() const; + void emitTUList() const; void emitBuckets() const; void emitStringOffsets() const; void emitAbbrevs() const; @@ -236,7 +233,9 @@ class Dwarf5AccelTableWriter : public AccelTableWriter { Dwarf5AccelTableWriter( AsmPrinter *Asm, const AccelTableBase &Contents, ArrayRef> CompUnits, - llvm::function_ref GetCUIndexForEntry); + ArrayRef> TypeUnits, + llvm::function_ref + getIndexForEntry); void emit(); }; @@ -388,31 +387,39 @@ void Dwarf5AccelTableWriter::Header::emit(Dwarf5AccelTableWriter &Ctx) { Asm->OutStreamer->emitBytes({AugmentationString, AugmentationStringSize}); } +static uint32_t constexpr LowerBitSize = dwarf::DW_IDX_type_hash; +static uint32_t getTagFromAbbreviationTag(const uint32_t AbbrvTag) { + return AbbrvTag >> LowerBitSize; +} +static uint32_t +constructAbbreviationTag(const unsigned Tag, + const GetIndexForEntryReturnType &EntryRet) { + uint32_t AbbrvTag = 0; + if (EntryRet) + AbbrvTag |= 1 << EntryRet->second.Index; + AbbrvTag |= 1 << dwarf::DW_IDX_die_offset; + AbbrvTag |= Tag << LowerBitSize; + return AbbrvTag; +} template -DenseSet Dwarf5AccelTableWriter::getUniqueTags() const { - DenseSet UniqueTags; +void Dwarf5AccelTableWriter::populateAbbrevsMap() { for (auto &Bucket : Contents.getBuckets()) { for (auto *Hash : Bucket) { for (auto *Value : Hash->Values) { + GetIndexForEntryReturnType EntryRet = + getIndexForEntry(*static_cast(Value)); unsigned Tag = static_cast(Value)->getDieTag(); - UniqueTags.insert(Tag); + uint32_t AbbrvTag = constructAbbreviationTag(Tag, EntryRet); + if (Abbreviations.count(AbbrvTag) == 0) { + SmallVector UA; + if (EntryRet) + UA.push_back(EntryRet->second); + UA.push_back({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4}); + Abbreviations.try_emplace(AbbrvTag, UA); + } } } } - return UniqueTags; -} - -template -SmallVector::AttributeEncoding, 2> -Dwarf5AccelTableWriter::getUniformAttributes() const { - SmallVector UA; - if (CompUnits.size() > 1) { - size_t LargestCUIndex = CompUnits.size() - 1; - dwarf::Form Form = DIEInteger::BestForm(/*IsSigned*/ false, LargestCUIndex); - UA.push_back({dwarf::DW_IDX_compile_unit, Form}); - } - UA.push_back({dwarf::DW_IDX_die_offset, dwarf::DW_FORM_ref4}); - return UA; } template @@ -426,6 +433,17 @@ void Dwarf5AccelTableWriter::emitCUList() const { } } +template +void Dwarf5AccelTableWriter::emitTUList() const { + for (const auto &TU : enumerate(TypeUnits)) { + Asm->OutStreamer->AddComment("Type unit " + Twine(TU.index())); + if (std::holds_alternative(TU.value())) + Asm->emitDwarfSymbolReference(std::get(TU.value())); + else + Asm->emitDwarfLengthOrOffset(std::get(TU.value())); + } +} + template void Dwarf5AccelTableWriter::emitBuckets() const { uint32_t Index = 1; @@ -453,10 +471,11 @@ void Dwarf5AccelTableWriter::emitAbbrevs() const { Asm->OutStreamer->emitLabel(AbbrevStart); for (const auto &Abbrev : Abbreviations) { Asm->OutStreamer->AddComment("Abbrev code"); - assert(Abbrev.first != 0); - Asm->emitULEB128(Abbrev.first); - Asm->OutStreamer->AddComment(dwarf::TagString(Abbrev.first)); + uint32_t Tag = getTagFromAbbreviationTag(Abbrev.first); + assert(Tag != 0); Asm->emitULEB128(Abbrev.first); + Asm->OutStreamer->AddComment(dwarf::TagString(Tag)); + Asm->emitULEB128(Tag); for (const auto &AttrEnc : Abbrev.second) { Asm->emitULEB128(AttrEnc.Index, dwarf::IndexString(AttrEnc.Index).data()); Asm->emitULEB128(AttrEnc.Form, @@ -471,16 +490,21 @@ void Dwarf5AccelTableWriter::emitAbbrevs() const { template void Dwarf5AccelTableWriter::emitEntry(const DataT &Entry) const { - auto AbbrevIt = Abbreviations.find(Entry.getDieTag()); + GetIndexForEntryReturnType EntryRet = getIndexForEntry(Entry); + uint32_t AbbrvTag = constructAbbreviationTag(Entry.getDieTag(), EntryRet); + auto AbbrevIt = Abbreviations.find(AbbrvTag); assert(AbbrevIt != Abbreviations.end() && "Why wasn't this abbrev generated?"); - + assert(getTagFromAbbreviationTag(AbbrevIt->first) == Entry.getDieTag() && + "Invalid Tag"); Asm->emitULEB128(AbbrevIt->first, "Abbreviation code"); + for (const auto &AttrEnc : AbbrevIt->second) { Asm->OutStreamer->AddComment(dwarf::IndexString(AttrEnc.Index)); switch (AttrEnc.Index) { - case dwarf::DW_IDX_compile_unit: { - DIEInteger ID(getCUIndexForEntry(Entry)); + case dwarf::DW_IDX_compile_unit: + case dwarf::DW_IDX_type_unit: { + DIEInteger ID(EntryRet->first); ID.emitValue(Asm, AttrEnc.Form); break; } @@ -512,22 +536,21 @@ template Dwarf5AccelTableWriter::Dwarf5AccelTableWriter( AsmPrinter *Asm, const AccelTableBase &Contents, ArrayRef> CompUnits, - llvm::function_ref getCUIndexForEntry) + ArrayRef> TypeUnits, + llvm::function_ref + getIndexForEntry) : AccelTableWriter(Asm, Contents, false), - Header(CompUnits.size(), Contents.getBucketCount(), + Header(CompUnits.size(), TypeUnits.size(), Contents.getBucketCount(), Contents.getUniqueNameCount()), - CompUnits(CompUnits), getCUIndexForEntry(std::move(getCUIndexForEntry)) { - DenseSet UniqueTags = getUniqueTags(); - SmallVector UniformAttributes = getUniformAttributes(); - - Abbreviations.reserve(UniqueTags.size()); - for (uint32_t Tag : UniqueTags) - Abbreviations.try_emplace(Tag, UniformAttributes); + CompUnits(CompUnits), TypeUnits(TypeUnits), + getIndexForEntry(std::move(getIndexForEntry)) { + populateAbbrevsMap(); } template void Dwarf5AccelTableWriter::emit() { Header.emit(*this); emitCUList(); + emitTUList(); emitBuckets(); emitHashes(); emitStringOffsets(); @@ -545,12 +568,17 @@ void llvm::emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents, AppleAccelTableWriter(Asm, Contents, Atoms, SecBegin).emit(); } -void llvm::emitDWARF5AccelTable( - AsmPrinter *Asm, AccelTable &Contents, - const DwarfDebug &DD, ArrayRef> CUs) { +void llvm::emitDWARF5AccelTable(AsmPrinter *Asm, + AccelTable &Contents, + const DwarfDebug &DD, + ArrayRef> CUs, + ArrayRef> TUs) { std::vector> CompUnits; + std::vector> TypeUnits; SmallVector CUIndex(CUs.size()); - int Count = 0; + DenseMap TUIndex(TUs.size()); + int CUCount = 0; + int TUCount = 0; for (const auto &CU : enumerate(CUs)) { switch (CU.value()->getCUNode()->getNameTableKind()) { case DICompileUnit::DebugNameTableKind::Default: @@ -559,13 +587,25 @@ void llvm::emitDWARF5AccelTable( default: continue; } - CUIndex[CU.index()] = Count++; + CUIndex[CU.index()] = CUCount++; assert(CU.index() == CU.value()->getUniqueID()); const DwarfCompileUnit *MainCU = DD.useSplitDwarf() ? CU.value()->getSkeleton() : CU.value().get(); CompUnits.push_back(MainCU->getLabelBegin()); } + for (const auto &TU : enumerate(TUs)) { + switch (TU.value()->getCUNode()->getNameTableKind()) { + case DICompileUnit::DebugNameTableKind::Default: + break; + default: + continue; + } + TUIndex[&TU.value()->getUnitDie()] = TUCount++; + const DwarfTypeUnit *MainTU = TU.value().get(); + TypeUnits.push_back(MainTU->getLabelBegin()); + } + if (CompUnits.empty()) return; @@ -573,11 +613,21 @@ void llvm::emitDWARF5AccelTable( Asm->getObjFileLowering().getDwarfDebugNamesSection()); Contents.finalize(Asm, "names"); + dwarf::Form CUIndexForm = + DIEInteger::BestForm(/*IsSigned*/ false, CompUnits.size() - 1); + dwarf::Form TUIndexForm = + DIEInteger::BestForm(/*IsSigned*/ false, TypeUnits.size() - 1); Dwarf5AccelTableWriter( - Asm, Contents, CompUnits, - [&](const DWARF5AccelTableData &Entry) { + Asm, Contents, CompUnits, TypeUnits, + [&](const DWARF5AccelTableData &Entry) -> GetIndexForEntryReturnType { const DIE *CUDie = Entry.getDie().getUnitDie(); - return CUIndex[DD.lookupCU(CUDie)->getUniqueID()]; + GetIndexForEntryReturnType Index = std::nullopt; + if (CUDie->getTag() == dwarf::DW_TAG_type_unit) + Index = {TUIndex[CUDie], {dwarf::DW_IDX_type_unit, TUIndexForm}}; + else if (CUIndex.size() > 1) + Index = {CUIndex[DD.lookupCU(CUDie)->getUniqueID()], + {dwarf::DW_IDX_compile_unit, CUIndexForm}}; + return Index; }) .emit(); } @@ -585,11 +635,13 @@ void llvm::emitDWARF5AccelTable( void llvm::emitDWARF5AccelTable( AsmPrinter *Asm, AccelTable &Contents, ArrayRef> CUs, - llvm::function_ref - getCUIndexForEntry) { + llvm::function_ref< + GetIndexForEntryReturnType(const DWARF5AccelTableStaticData &)> + getIndexForEntry) { + std::vector> TypeUnits; Contents.finalize(Asm, "names"); - Dwarf5AccelTableWriter(Asm, Contents, CUs, - getCUIndexForEntry) + Dwarf5AccelTableWriter( + Asm, Contents, CUs, TypeUnits, getIndexForEntry) .emit(); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index ee2ab71ad28e4..8a680dd9c6976 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -305,6 +305,7 @@ void Loc::MMI::addFrameIndexExpr(const DIExpression *Expr, int FI) { static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, bool GenerateTypeUnits, + bool HasSplitDwarf, DebuggerKind Tuning, const Triple &TT) { // Honor an explicit request. @@ -312,7 +313,8 @@ static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, return AccelTables; // Accelerator tables with type units are currently not supported. - if (GenerateTypeUnits) + if (GenerateTypeUnits && + (DwarfVersion < 5 || HasSplitDwarf || !TT.isOSBinFormatELF())) return AccelTableKind::None; // Accelerator tables get emitted if targetting DWARF v5 or LLDB. DWARF v5 @@ -325,6 +327,9 @@ static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, : AccelTableKind::Dwarf; return AccelTableKind::None; } +void DwarfDebug::addTypeUnit(std::unique_ptr U) { + InfoHolder.addTypeUnit(std::move(U)); +} DwarfDebug::DwarfDebug(AsmPrinter *A) : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()), @@ -400,8 +405,9 @@ DwarfDebug::DwarfDebug(AsmPrinter *A) A->TM.getTargetTriple().isOSBinFormatWasm()) && GenerateDwarfTypeUnits; - TheAccelTableKind = computeAccelTableKind( - DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple()); + TheAccelTableKind = + computeAccelTableKind(DwarfVersion, GenerateTypeUnits, HasSplitDwarf, + DebuggerTuning, A->TM.getTargetTriple()); // Work around a GDB bug. GDB doesn't support the standard opcode; // SCE doesn't support GNU's; LLDB prefers the standard opcode, which @@ -2394,7 +2400,7 @@ void DwarfDebug::emitAccelDebugNames() { if (getUnits().empty()) return; - emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits()); + emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits(), getTypeUnits()); } // Emit visible names into a hashed accelerator table section. @@ -3499,7 +3505,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, // Types referencing entries in the address table cannot be placed in type // units. if (AddrPool.hasBeenUsed()) { - + AccelTypeUntsDebugNames.clear(); // Remove all the types built while building this type. // This is pessimistic as some of these types might not be dependent on // the type that used an address. @@ -3514,11 +3520,15 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, return; } - // If the type wasn't dependent on fission addresses, finish adding the type - // and all its dependent types. for (auto &TU : TypeUnitsToAdd) { InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get()); InfoHolder.emitUnit(TU.first.get(), useSplitDwarf()); + if (getDwarfVersion() >= 5 && + getAccelTableKind() == AccelTableKind::Dwarf) { + addTypeUnit(std::move(TU.first)); + AccelDebugNames.addEntries(AccelTypeUntsDebugNames); + AccelTypeUntsDebugNames.clear(); + } } } CU.addDIETypeSignature(RefDie, Signature); @@ -3548,7 +3558,12 @@ void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU, AppleAccel.addName(Ref, Die); break; case AccelTableKind::Dwarf: - AccelDebugNames.addName(Ref, Die); + // The type unit can be discarded, so need to add references to final + // acceleration table once we know it's complete and we emit it. + if (TypeUnitsUnderConstruction.empty()) + AccelDebugNames.addName(Ref, Die); + else + AccelTypeUntsDebugNames.addName(Ref, Die); break; case AccelTableKind::Default: llvm_unreachable("Default should have already been resolved."); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 75649a747602e..f6870d514ea0e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -497,6 +497,7 @@ class DwarfDebug : public DebugHandlerBase { /// Accelerator tables. AccelTable AccelDebugNames; + AccelTable AccelTypeUntsDebugNames; AccelTable AccelNames; AccelTable AccelObjC; AccelTable AccelNamespace; @@ -515,6 +516,13 @@ class DwarfDebug : public DebugHandlerBase { return InfoHolder.getUnits(); } + /// Returns Type Units constructed for this module. + const SmallVectorImpl> &getTypeUnits() { + return InfoHolder.getTypeUnits(); + } + + void addTypeUnit(std::unique_ptr U); + using InlinedEntity = DbgValueHistoryMap::InlinedEntity; void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU, @@ -780,6 +788,9 @@ class DwarfDebug : public DebugHandlerBase { /// Returns what kind (if any) of accelerator tables to emit. AccelTableKind getAccelTableKind() const { return TheAccelTableKind; } + /// Seet TheAccelTableKind + void setTheAccelTableKind(AccelTableKind K) { TheAccelTableKind = K; }; + bool useAppleExtensionAttributes() const { return HasAppleExtensionAttributes; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp index eab798c0da784..5de7c91f021a8 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp @@ -24,6 +24,10 @@ void DwarfFile::addUnit(std::unique_ptr U) { CUs.push_back(std::move(U)); } +void DwarfFile::addTypeUnit(std::unique_ptr U) { + TUs.push_back(std::move(U)); +} + // Emit the various dwarf units to the unit section USection with // the abbreviations going into ASection. void DwarfFile::emitUnits(bool UseOffsets) { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h index f76858fc2f36a..452a8f82379cd 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -28,6 +28,7 @@ class DbgLabel; class DINode; class DILocalScope; class DwarfCompileUnit; +class DwarfTypeUnit; class DwarfUnit; class LexicalScope; class MCSection; @@ -59,6 +60,9 @@ class DwarfFile { // A pointer to all units in the section. SmallVector, 1> CUs; + // A pointer to all type units in the section. + SmallVector, 1> TUs; + DwarfStringPool StrPool; // List of range lists for a given compile unit, separate from the ranges for @@ -103,6 +107,11 @@ class DwarfFile { return CUs; } + /// Returns type units that were constructed. + const SmallVectorImpl> &getTypeUnits() { + return TUs; + } + std::pair addRange(const DwarfCompileUnit &CU, SmallVector R); @@ -124,6 +133,11 @@ class DwarfFile { /// Add a unit to the list of CUs. void addUnit(std::unique_ptr U); + /// Add a unit to the list of TUs. + /// Preserves type unit so that memory is not released before DWARF5 + /// accelerator table is created. + void addTypeUnit(std::unique_ptr U); + /// Emit all of the units to the section listed with the given /// abbreviation section. void emitUnits(bool UseOffsets); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index d30f0ef7af348..620f4288bd720 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1778,6 +1778,10 @@ void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) { } void DwarfTypeUnit::emitHeader(bool UseOffsets) { + if (!DD->useSplitDwarf()) { + LabelBegin = Asm->createTempSymbol("tu_begin"); + Asm->OutStreamer->emitLabel(LabelBegin); + } DwarfUnit::emitCommonHeader(UseOffsets, DD->useSplitDwarf() ? dwarf::DW_UT_split_type : dwarf::DW_UT_type); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h index 8f17e94c2d1c3..1cda82db0b269 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -362,6 +362,8 @@ class DwarfTypeUnit final : public DwarfUnit { DwarfCompileUnit &CU; MCDwarfDwoLineTable *SplitLineTable; bool UsedLineTable = false; + /// The start of the type unit within .debug_nfo section. + MCSymbol *LabelBegin = nullptr; unsigned getOrCreateSourceID(const DIFile *File) override; void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override; @@ -372,6 +374,8 @@ class DwarfTypeUnit final : public DwarfUnit { DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable = nullptr); void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } + /// Returns Type Signature. + uint64_t getTypeSignature() const { return TypeSignature; } void setType(const DIE *Ty) { this->Ty = Ty; } /// Emit the header for this unit, not including the initial length field. @@ -385,6 +389,11 @@ class DwarfTypeUnit final : public DwarfUnit { void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override; DwarfCompileUnit &getCU() override { return CU; } + /// Get the the symbol for start of the section for this type unit. + MCSymbol *getLabelBegin() const { + assert(LabelBegin && "LabelBegin is not initialized"); + return LabelBegin; + } }; } // end llvm namespace #endif diff --git a/llvm/lib/DWARFLinker/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/DWARFStreamer.cpp index ff719d0a59baf..75e189775dfa5 100644 --- a/llvm/lib/DWARFLinker/DWARFStreamer.cpp +++ b/llvm/lib/DWARFLinker/DWARFStreamer.cpp @@ -307,10 +307,19 @@ void DwarfStreamer::emitDebugNames( } Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection()); + dwarf::Form Form = DIEInteger::BestForm(/*IsSigned*/ false, + (uint64_t)UniqueIdToCuMap.size() - 1); + /// llvm-dwarfutil doesn't support type units + .debug_names right now anyway, + /// so just keeping current behavior. emitDWARF5AccelTable( Asm.get(), Table, CompUnits, - [&UniqueIdToCuMap](const DWARF5AccelTableStaticData &Entry) { - return UniqueIdToCuMap[Entry.getCUIndex()]; + [&UniqueIdToCuMap, &Form](const DWARF5AccelTableStaticData &Entry) + -> GetIndexForEntryReturnType { + GetIndexForEntryReturnType Index = std::nullopt; + if (UniqueIdToCuMap.size() > 1) + Index = {UniqueIdToCuMap[Entry.getCUIndex()], + {dwarf::DW_IDX_compile_unit, Form}}; + return Index; }); } diff --git a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp b/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp index 7885e3013a51d..4c2e4c45fd8e6 100644 --- a/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp +++ b/llvm/lib/DWARFLinkerParallel/DWARFEmitterImpl.cpp @@ -230,10 +230,20 @@ void DwarfEmitterImpl::emitDebugNames( return; Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection()); - emitDWARF5AccelTable(Asm.get(), Table, CUOffsets, - [&CUidToIdx](const DWARF5AccelTableStaticData &Entry) { - return CUidToIdx[Entry.getCUIndex()]; - }); + dwarf::Form Form = + DIEInteger::BestForm(/*IsSigned*/ false, (uint64_t)CUidToIdx.size() - 1); + /// DWARFLinker doesn't support type units + .debug_names right now anyway, + /// so just keeping current behavior. + emitDWARF5AccelTable( + Asm.get(), Table, CUOffsets, + [&CUidToIdx, &Form](const DWARF5AccelTableStaticData &Entry) + -> GetIndexForEntryReturnType { + GetIndexForEntryReturnType Index = std::nullopt; + if (CUidToIdx.size() > 1) + Index = {CUidToIdx[Entry.getCUIndex()], + {dwarf::DW_IDX_compile_unit, Form}}; + return Index; + }); } void DwarfEmitterImpl::emitAppleNamespaces( diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index 7d8289ed420ab..2c090599c22cd 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -635,7 +635,7 @@ std::optional DWARFDebugNames::Entry::getCUOffset() const { } void DWARFDebugNames::Entry::dump(ScopedPrinter &W) const { - W.printHex("Abbrev", Abbr->Code); + DictScope AbbrevScope(W, ("Abbrev: 0x" + Twine::utohexstr(Abbr->Code)).str()); W.startLine() << formatv("Tag: {0}\n", Abbr->Tag); assert(Abbr->Attributes.size() == Values.size()); for (auto Tuple : zip_first(Abbr->Attributes, Values)) { diff --git a/llvm/test/DebugInfo/X86/accel-tables-dwarf5.ll b/llvm/test/DebugInfo/X86/accel-tables-dwarf5.ll index e7cf7968003d9..243dea608a2d7 100644 --- a/llvm/test/DebugInfo/X86/accel-tables-dwarf5.ll +++ b/llvm/test/DebugInfo/X86/accel-tables-dwarf5.ll @@ -22,7 +22,6 @@ ; RUN: | llvm-readobj --sections - | FileCheck --check-prefix=DEBUG_NAMES %s ; NONE-NOT: apple_names -; NONE-NOT: debug_names ; DEBUG_NAMES-NOT: apple_names ; DEBUG_NAMES: debug_names diff --git a/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll b/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll index 3fc91ef85df1f..f3b1d5c88996a 100644 --- a/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll +++ b/llvm/test/DebugInfo/X86/debug-names-dwarf64.ll @@ -26,12 +26,12 @@ ; CHECK-NEXT: CU[0]: 0x00000000 ; CHECK-NEXT: ] ; CHECK-NEXT: Abbreviations [ -; CHECK-NEXT: Abbreviation 0x34 { -; CHECK-NEXT: Tag: DW_TAG_variable +; CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_base_type ; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 ; CHECK-NEXT: } -; CHECK-NEXT: Abbreviation 0x24 { -; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_variable ; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 ; CHECK-NEXT: } ; CHECK-NEXT: ] @@ -40,9 +40,10 @@ ; CHECK-NEXT: Hash: 0xB888030 ; CHECK-NEXT: String: {{.+}} "int" ; CHECK-NEXT: Entry @ {{.+}} { -; CHECK-NEXT: Abbrev: 0x24 -; CHECK-NEXT: Tag: DW_TAG_base_type -; CHECK-NEXT: DW_IDX_die_offset: [[TYPEDIE]] +; CHECK-NEXT: Abbrev: [[ABBREV]] { +; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: DW_IDX_die_offset: [[TYPEDIE]] +; CHECK-NEXT: } ; CHECK-NEXT: } ; CHECK-NEXT: } ; CHECK-NEXT: ] @@ -51,9 +52,10 @@ ; CHECK-NEXT: Hash: 0xB887389 ; CHECK-NEXT: String: {{.+}} "foo" ; CHECK-NEXT: Entry @ {{.+}} { -; CHECK-NEXT: Abbrev: 0x34 -; CHECK-NEXT: Tag: DW_TAG_variable -; CHECK-NEXT: DW_IDX_die_offset: [[VARDIE]] +; CHECK-NEXT: Abbrev: [[ABBREV1]] { +; CHECK-NEXT: Tag: DW_TAG_variable +; CHECK-NEXT: DW_IDX_die_offset: [[VARDIE]] +; CHECK-NEXT: } ; CHECK-NEXT: } ; CHECK-NEXT: } ; CHECK-NEXT: ] diff --git a/llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll b/llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll new file mode 100644 index 0000000000000..e86a226fc880a --- /dev/null +++ b/llvm/test/DebugInfo/X86/debug-names-types-monolithic.ll @@ -0,0 +1,168 @@ +; This checks that .debug_names can be generated with monolithic -fdebug-type-sections. + +; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t +; RUN: llvm-dwarfdump -debug-info -debug-names %t | FileCheck %s + +; CHECK: .debug_info contents: +; CHECK: DW_TAG_type_unit +; CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus_14) +; CHECK-NEXT: DW_AT_stmt_list (0x00000000) +; CHECK-NEXT: DW_AT_str_offsets_base (0x00000008) +; CHECK: DW_TAG_structure_type +; CHECK-NEXT: DW_AT_calling_convention (DW_CC_pass_by_value) +; CHECK-NEXT: DW_AT_name ("Foo") +; CHECK-NEXT: DW_AT_byte_size (0x08) +; CHECK-NEXT: DW_AT_decl_file ("/typeSmall/main.cpp") +; CHECK-NEXT: DW_AT_decl_line (1) +; CHECK: DW_TAG_member +; CHECK-NEXT: DW_AT_name ("c1") +; CHECK-NEXT: DW_AT_type (0x00000033 "char *") +; CHECK-NEXT: DW_AT_decl_file ("/typeSmall/main.cpp") +; CHECK-NEXT: DW_AT_decl_line (2) +; CHECK-NEXT: DW_AT_data_member_location (0x00) +; CHECK: DW_TAG_pointer_type +; CHECK-NEXT: DW_AT_type (0x00000038 "char") +; CHECK: DW_TAG_base_type +; CHECK-NEXT: DW_AT_name ("char") +; CHECK-NEXT: DW_AT_encoding (DW_ATE_signed_char) +; CHECK-NEXT: DW_AT_byte_size (0x01) +; CHECK: .debug_names contents: +; CHECK: Compilation Unit offsets [ +; CHECK-NEXT: CU[0]: 0x00000000 +; CHECK-NEXT: ] +; CHECK-NEXT: Local Type Unit offsets [ +; CHECK-NEXT: LocalTU[0]: 0x00000000 +; CHECK-NEXT: ] +; CHECK: Abbreviations [ +; CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_structure_type +; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-NEXT: } +; CHECK-NEXT: Abbreviation [[ABBREV3:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_structure_type +; CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data1 +; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-NEXT: } +; CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-NEXT: } +; CHECK-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_subprogram +; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-NEXT: } +; CHECK-NEXT: Abbreviation [[ABBREV4:0x[0-9a-f]*]] { +; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data1 +; CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 +; CHECK-NEXT: } +; CHECK-NEXT: ] +; CHECK-NEXT: Bucket 0 [ +; CHECK-NEXT: Name 1 { +; CHECK-NEXT: Hash: 0xB888030 +; CHECK-NEXT: String: {{.+}} "int" +; CHECK-NEXT: Entry @ {{.+}} { +; CHECK-NEXT: Abbrev: [[ABBREV]] { +; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: DW_IDX_die_offset: 0x0000003e +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: ] +; CHECK-NEXT: Bucket 1 [ +; CHECK-NEXT: Name 2 { +; CHECK-NEXT: Hash: 0xB887389 +; CHECK-NEXT: String: {{.+}} "Foo" +; CHECK-NEXT: Entry @ {{.+}} { +; CHECK-NEXT: Abbrev: [[ABBREV3]] { +; CHECK-NEXT: Tag: DW_TAG_structure_type +; CHECK-NEXT: DW_IDX_type_unit: 0x00 +; CHECK-NEXT: DW_IDX_die_offset: 0x00000023 +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: Entry @ 0xaa { +; CHECK-NEXT: Abbrev: [[ABBREV1]] { +; CHECK-NEXT: Tag: DW_TAG_structure_type +; CHECK-NEXT: DW_IDX_die_offset: 0x00000042 +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: ] +; CHECK-NEXT: Bucket 2 [ +; CHECK-NEXT: Name 3 { +; CHECK-NEXT: Hash: 0x7C9A7F6A +; CHECK-NEXT: String: {{.+}} "main" +; CHECK-NEXT: Entry @ {{.+}} { +; CHECK-NEXT: Abbrev: [[ABBREV2]] { +; CHECK-NEXT: Tag: DW_TAG_subprogram +; CHECK-NEXT: DW_IDX_die_offset: 0x00000023 +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: ] +; CHECK-NEXT: Bucket 3 [ +; CHECK-NEXT: Name 4 { +; CHECK-NEXT: Hash: 0x7C952063 +; CHECK-NEXT: String: {{.+}} "char" +; CHECK-NEXT: Entry @ {{.+}} { +; CHECK-NEXT: Abbrev: [[ABBREV4]] { +; CHECK-NEXT: Tag: DW_TAG_base_type +; CHECK-NEXT: DW_IDX_type_unit: 0x00 +; CHECK-NEXT: DW_IDX_die_offset: 0x00000038 +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: } +; CHECK-NEXT: ] +; CHECK-NEXT: } + + +; ModuleID = 'main.cpp' +source_filename = "main.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.Foo = type { ptr } + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 !dbg !10 { +entry: + %retval = alloca i32, align 4 + %f = alloca %struct.Foo, align 8 + store i32 0, ptr %retval, align 4 + call void @llvm.dbg.declare(metadata ptr %f, metadata !15, metadata !DIExpression()), !dbg !21 + ret i32 0, !dbg !22 +} + +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false) +!1 = !DIFile(filename: "main.cpp", directory: "/typeSmall", checksumkind: CSK_MD5, checksum: "e5b402e9dbafe24c7adbb087d1f03549") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{!"clang version 18.0.0"} +!10 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) +!11 = !DISubroutineType(types: !12) +!12 = !{!13} +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !{} +!15 = !DILocalVariable(name: "f", scope: !10, file: !1, line: 5, type: !16) +!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS3Foo") +!17 = !{!18} +!18 = !DIDerivedType(tag: DW_TAG_member, name: "c1", scope: !16, file: !1, line: 2, baseType: !19, size: 64) +!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) +!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!21 = !DILocation(line: 5, column: 6, scope: !10) +!22 = !DILocation(line: 6, column: 2, scope: !10) diff --git a/llvm/test/DebugInfo/X86/debug-names-types-split.ll b/llvm/test/DebugInfo/X86/debug-names-types-split.ll new file mode 100644 index 0000000000000..d5908aeaf114a --- /dev/null +++ b/llvm/test/DebugInfo/X86/debug-names-types-split.ll @@ -0,0 +1,57 @@ +; This checks that .debug_names is not generated with split-dwarf + -fdebug-type-sections. + +; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj -split-dwarf-file=mainTypes.dwo --split-dwarf-output=mainTypes.dwo %s -o %t +; RUN: llvm-readelf --sections %t | FileCheck %s + +; CHECK-NOT: .debug_names + +; ModuleID = 'main.cpp' +source_filename = "main.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.Foo = type { ptr } + +; Function Attrs: mustprogress noinline norecurse nounwind optnone uwtable +define dso_local noundef i32 @main() #0 !dbg !10 { +entry: + %retval = alloca i32, align 4 + %f = alloca %struct.Foo, align 8 + store i32 0, ptr %retval, align 4 + call void @llvm.dbg.declare(metadata ptr %f, metadata !15, metadata !DIExpression()), !dbg !21 + ret i32 0, !dbg !22 +} + +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { mustprogress noinline norecurse nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } +attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8} +!llvm.ident = !{!9} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0 (ssh://git.vip.facebook.com/data/gitrepos/osmeta/external/llvm-project 680deb27e25976d9b74ad7b48ec5cb96be0e44b6)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "main.dwo", emissionKind: FullDebug, splitDebugInlining: false) +!1 = !DIFile(filename: "main.cpp", directory: "/home/ayermolo/local/tasks/T138552329/typeSmallSplit", checksumkind: CSK_MD5, checksum: "e5b402e9dbafe24c7adbb087d1f03549") +!2 = !{i32 7, !"Dwarf Version", i32 5} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = !{i32 1, !"wchar_size", i32 4} +!5 = !{i32 8, !"PIC Level", i32 2} +!6 = !{i32 7, !"PIE Level", i32 2} +!7 = !{i32 7, !"uwtable", i32 2} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{!"clang version 18.0.0 (ssh://git.vip.facebook.com/data/gitrepos/osmeta/external/llvm-project 680deb27e25976d9b74ad7b48ec5cb96be0e44b6)"} +!10 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14) +!11 = !DISubroutineType(types: !12) +!12 = !{!13} +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !{} +!15 = !DILocalVariable(name: "f", scope: !10, file: !1, line: 5, type: !16) +!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !17, identifier: "_ZTS3Foo") +!17 = !{!18} +!18 = !DIDerivedType(tag: DW_TAG_member, name: "c1", scope: !16, file: !1, line: 2, baseType: !19, size: 64) +!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) +!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) +!21 = !DILocation(line: 5, column: 6, scope: !10) +!22 = !DILocation(line: 6, column: 2, scope: !10) diff --git a/llvm/test/DebugInfo/X86/dwarfdump-debug-names.s b/llvm/test/DebugInfo/X86/dwarfdump-debug-names.s index 009a87325e8b4..cb211733c6f8e 100644 --- a/llvm/test/DebugInfo/X86/dwarfdump-debug-names.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-debug-names.s @@ -151,7 +151,7 @@ # CHECK-NEXT: CU[0]: 0x00000000 # CHECK-NEXT: ] # CHECK-NEXT: Abbreviations [ -# CHECK-NEXT: Abbreviation 0x2e { +# CHECK-NEXT: Abbreviation [[ABBREV:0x[0-9a-f]*]] { # CHECK-NEXT: Tag: DW_TAG_subprogram # CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 # CHECK-NEXT: } @@ -164,18 +164,20 @@ # CHECK-NEXT: Hash: 0xB887389 # CHECK-NEXT: String: 0x00000000 "foo" # CHECK-NEXT: Entry @ 0x4f { -# CHECK-NEXT: Abbrev: 0x2E -# CHECK-NEXT: Tag: DW_TAG_subprogram -# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: Abbrev: [[ABBREV]] +# CHECK-NEXT: Tag: DW_TAG_subprogram +# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: Name 2 { # CHECK-NEXT: Hash: 0xB5063D0B # CHECK-NEXT: String: 0x00000004 "_Z3foov" # CHECK-NEXT: Entry @ 0x58 { -# CHECK-NEXT: Abbrev: 0x2E -# CHECK-NEXT: Tag: DW_TAG_subprogram -# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: Abbrev: [[ABBREV]] +# CHECK-NEXT: Tag: DW_TAG_subprogram +# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: ] @@ -197,7 +199,7 @@ # CHECK-NEXT: CU[0]: 0x00000002 # CHECK-NEXT: ] # CHECK-NEXT: Abbreviations [ -# CHECK-NEXT: Abbreviation 0x34 { +# CHECK-NEXT: Abbreviation [[ABBREV1:0x[0-9a-f]*]] { # CHECK-NEXT: Tag: DW_TAG_variable # CHECK-NEXT: DW_IDX_die_offset: DW_FORM_ref4 # CHECK-NEXT: } @@ -207,9 +209,10 @@ # CHECK-NEXT: Hash: 0xB8860BA # CHECK-NEXT: String: 0x0000000c "bar" # CHECK-NEXT: Entry @ 0xa3 { -# CHECK-NEXT: Abbrev: 0x34 -# CHECK-NEXT: Tag: DW_TAG_variable -# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: Abbrev: [[ABBREV1]] +# CHECK-NEXT: Tag: DW_TAG_variable +# CHECK-NEXT: DW_IDX_die_offset: 0x00000001 +# CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: ] @@ -237,7 +240,7 @@ # CHECK-NEXT: ForeignTU[0]: 0xffffff00ffffffff # CHECK-NEXT: ] # CHECK-NEXT: Abbreviations [ -# CHECK-NEXT: Abbreviation 0x1 { +# CHECK-NEXT: Abbreviation [[ABBREV2:0x[0-9a-f]*]] { # CHECK-NEXT: Tag: DW_TAG_base_type # CHECK-NEXT: DW_IDX_type_unit: DW_FORM_data4 # CHECK-NEXT: DW_IDX_type_hash: DW_FORM_data8 @@ -248,10 +251,11 @@ # CHECK-NEXT: Hash: 0xB887389 # CHECK-NEXT: String: 0x00000000 "foo" # CHECK-NEXT: Entry @ 0x111 { -# CHECK-NEXT: Abbrev: 0x1 -# CHECK-NEXT: Tag: DW_TAG_base_type -# CHECK-NEXT: DW_IDX_type_unit: 0x00000001 -# CHECK-NEXT: DW_IDX_type_hash: 0x0000ff03ffffffff +# CHECK-NEXT: Abbrev: [[ABBREV2]] +# CHECK-NEXT: Tag: DW_TAG_base_type +# CHECK-NEXT: DW_IDX_type_unit: 0x00000001 +# CHECK-NEXT: DW_IDX_type_hash: 0x0000ff03ffffffff +# CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: } # CHECK-NEXT: ] diff --git a/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test b/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test index f1680ced6e5b4..04b2f9b158994 100644 --- a/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test +++ b/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test @@ -4,13 +4,12 @@ RUN: dsymutil -accelerator=Apple -oso-prepend-path=%p/../Inputs %p/../Inputs/acc RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON -RUN: dsymutil --linker llvm -accelerator=Dwarf -oso-prepend-path=%p/../Inputs \ -RUN: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM -RUN: dsymutil --linker llvm -accelerator=Apple -oso-prepend-path=%p/../Inputs \ -RUN: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM - -RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON -RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON +RUN2: dsymutil --linker llvm -accelerator=Dwarf -oso-prepend-path=%p/../Inputs \ +RUN2: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM +RUN2: dsymutil --linker llvm -accelerator=Apple -oso-prepend-path=%p/../Inputs \ +RUN2: %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM +RUN2: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON +RUN2: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON COMMON: .debug_info contents COMMON: {{.*}}DW_TAG_namespace @@ -29,8 +28,9 @@ DWARF-NEXT: Hash: {{.*}} DWARF-NEXT: String: {{.*}} "C" DWARF-NEXT: Entry {{.*}} { DWARF-NEXT: Abbrev: {{.*}} -DWARF-NEXT: Tag: DW_TAG_namespace -DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]] +DWARF-NEXT: Tag: DW_TAG_namespace +DWARF-NEXT: DW_IDX_die_offset: [[NAMESPACE]] +DWARF-NEXT: } DWARF-NEXT: } DWARF-NEXT: Entry {{.*}} { DWARF-NEXT: Abbrev: {{.*}} diff --git a/llvm/test/tools/dsymutil/ARM/dwarf5-dwarf4-combination-macho.test b/llvm/test/tools/dsymutil/ARM/dwarf5-dwarf4-combination-macho.test index 90f6818b8c8e5..3e4d904909316 100644 --- a/llvm/test/tools/dsymutil/ARM/dwarf5-dwarf4-combination-macho.test +++ b/llvm/test/tools/dsymutil/ARM/dwarf5-dwarf4-combination-macho.test @@ -44,7 +44,7 @@ CHECK:.debug_abbrev contents: CHECK-NEXT: Abbrev table for offset: 0x00000000 CHECK: .debug_info contents: -CHECK: 0x00000000: Compile Unit: length = 0x0000004a, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 +CHECK: 0x00000000: Compile Unit: length = 0x0000004a, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 CHECK: DW_AT_producer [DW_FORM_strx] (indexed (00000000) string = "Apple clang version 14.0.3 (clang-1403.0.22.14.1)") CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000001) string = "a.cpp") CHECK: DW_AT_LLVM_sysroot [DW_FORM_strx] (indexed (00000002) string = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk") @@ -59,12 +59,12 @@ CHECK-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x[[ CHECK: DW_AT_linkage_name [DW_FORM_strx] (indexed (00000005) string = "_Z4foo2i") CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000006) string = "foo2") CHECK: 0x0000003c: DW_TAG_formal_parameter [3] (0x0000002c) -CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]: +CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]: CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START:]], 0x[[#%.16x,LOCLIST_PAIR_END:]]): [[LOCLIST_EXPR:.*]] CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START2:]], 0x[[#%.16x,LOCLIST_PAIR_END2:]]): [[LOCLIST_EXPR2:.*]]) CHECK: DW_AT_name [DW_FORM_strx] (indexed (00000007) string = "a") -CHECK: 0x0000004e: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x00{{00|5a}}, addr_size = 0x08 +CHECK: 0x0000004e: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x00{{00|5a}}, addr_size = 0x08 CHECK: DW_AT_producer [DW_FORM_strp] ( .debug_str[0x00000001] = "Apple clang version 14.0.3 (clang-1403.0.22.14.1)") CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000e0] = "b.cpp") CHECK: DW_AT_LLVM_sysroot [DW_FORM_strp] ( .debug_str[0x00000039] = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk") @@ -79,7 +79,7 @@ CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,LOC_LOWPC CHECK: DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000e6] = "_Z3bari") CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000ee] = "bar") CHECK: 0x0000009d: DW_TAG_formal_parameter {{.*}} (0x00000080) -CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]: +CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]: CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START:]], 0x[[#%.16x,LOC_PAIR_END:]]): [[LOC_EXPR:.*]] CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START2:]], 0x[[#%.16x,LOC_PAIR_END2:]]): [[LOC_EXPR2:.*]]) CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000f2] = "x") @@ -91,7 +91,7 @@ CHECK-NEXT: (0x[[#sub(LOC_PAIR_START2,LOC_LOWPC)]], 0x[[#sub(LOC_PAIR CHECK: .debug_loclists contents: CHECK-NEXT: 0x00000000: locations list header: length = 0x00000018, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000 -CHECK-NEXT: 0x[[LOCLIST_OFFSET]]: +CHECK-NEXT: 0x[[LOCLIST_OFFSET]]: CHECK-NEXT: DW_LLE_base_addressx (0x0000000000000000) CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END,LOCLIST_LOWPC)]]) CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START2,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END2,LOCLIST_LOWPC)]]) @@ -205,7 +205,7 @@ CHECK-NEXT: 0x00000028: 000000dc "int" CHECK: .debug_names contents: CHECK-NEXT: Name Index @ 0x0 { CHECK-NEXT: Header { -CHECK-NEXT: Length: 0xBC +CHECK-NEXT: Length: 0xC4 CHECK-NEXT: Format: DWARF32 CHECK-NEXT: Version: 5 CHECK-NEXT: CU count: 2 @@ -213,6 +213,6 @@ CHECK-NEXT: Local TU count: 0 CHECK-NEXT: Foreign TU count: 0 CHECK-NEXT: Bucket count: 5 CHECK-NEXT: Name count: 5 -CHECK-NEXT: Abbreviations table size: 0x11 +CHECK-NEXT: Abbreviations table size: 0x13 CHECK-NEXT: Augmentation: 'LLVM0700' CHECK-NEXT: } diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug-names-misaligned.s b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-misaligned.s index 0acc745af1e5a..0ad4f50e98d98 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/debug-names-misaligned.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug-names-misaligned.s @@ -84,7 +84,7 @@ # CHECK: Name 1 { # CHECK-NEXT: String: 0x00000000 "foo" # CHECK-NEXT: Entry @ 0x37 { -# CHECK-NEXT: Abbrev: 0x2E +# CHECK-NEXT: Abbrev: 0x2e # CHECK-NEXT: Tag: DW_TAG_subprogram # CHECK-NEXT: DW_IDX_die_offset: 0x00000001 # CHECK-NEXT: }