[LLVM[NFC] Refactor to allow debug_names entries to conatain DIE offset (#69399)
This is pre-cursor patch to enabling type units with DWARF5 acceleration tables. With this change it allows for entries to contain offsets directly, this way type units do not need to be preserved until .debug_names is written out.
This commit is contained in:
parent
d32e801d74
commit
da27c25c19
@ -252,44 +252,46 @@ class DWARF5AccelTableData : public AccelTableData {
|
||||
public:
|
||||
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
|
||||
|
||||
DWARF5AccelTableData(const DIE &Die) : Die(Die) {}
|
||||
DWARF5AccelTableData(const DIE &Die, const DwarfCompileUnit &CU);
|
||||
DWARF5AccelTableData(uint64_t DieOffset, unsigned DieTag, unsigned CUIndex)
|
||||
: OffsetVal(DieOffset), DieTag(DieTag), UnitID(CUIndex) {}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &OS) const override;
|
||||
#endif
|
||||
|
||||
const DIE &getDie() const { return Die; }
|
||||
uint64_t getDieOffset() const { return Die.getOffset(); }
|
||||
unsigned getDieTag() const { return Die.getTag(); }
|
||||
uint64_t getDieOffset() const {
|
||||
assert(std::holds_alternative<uint64_t>(OffsetVal) &&
|
||||
"Accessing DIE Offset before normalizing.");
|
||||
return std::get<uint64_t>(OffsetVal);
|
||||
}
|
||||
unsigned getDieTag() const { return DieTag; }
|
||||
unsigned getUnitID() const { return UnitID; }
|
||||
void normalizeDIEToOffset() {
|
||||
assert(std::holds_alternative<const DIE *>(OffsetVal) &&
|
||||
"Accessing offset after normalizing.");
|
||||
OffsetVal = std::get<const DIE *>(OffsetVal)->getOffset();
|
||||
}
|
||||
|
||||
protected:
|
||||
const DIE &Die;
|
||||
std::variant<const DIE *, uint64_t> OffsetVal;
|
||||
unsigned DieTag;
|
||||
unsigned UnitID;
|
||||
|
||||
uint64_t order() const override { return Die.getOffset(); }
|
||||
uint64_t order() const override { return getDieOffset(); }
|
||||
};
|
||||
|
||||
class DWARF5AccelTableStaticData : public AccelTableData {
|
||||
class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
|
||||
public:
|
||||
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
|
||||
|
||||
DWARF5AccelTableStaticData(uint64_t DieOffset, unsigned DieTag,
|
||||
unsigned CUIndex)
|
||||
: DieOffset(DieOffset), DieTag(DieTag), CUIndex(CUIndex) {}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void print(raw_ostream &OS) const override;
|
||||
#endif
|
||||
|
||||
uint64_t getDieOffset() const { return DieOffset; }
|
||||
unsigned getDieTag() const { return DieTag; }
|
||||
unsigned getCUIndex() const { return CUIndex; }
|
||||
|
||||
protected:
|
||||
uint64_t DieOffset;
|
||||
unsigned DieTag;
|
||||
unsigned CUIndex;
|
||||
|
||||
uint64_t order() const override { return DieOffset; }
|
||||
/// Convert DIE entries to explicit offset.
|
||||
/// Needs to be called after DIE offsets are computed.
|
||||
void convertDieToOffset() {
|
||||
for (auto &Entry : Entries) {
|
||||
for (AccelTableData *Value : Entry.second.Values) {
|
||||
static_cast<DWARF5AccelTableData *>(Value)->normalizeDIEToOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents,
|
||||
@ -306,8 +308,7 @@ void emitAppleAccelTable(AsmPrinter *Asm, AccelTable<DataT> &Contents,
|
||||
emitAppleAccelTableImpl(Asm, Contents, Prefix, SecBegin, DataT::Atoms);
|
||||
}
|
||||
|
||||
void emitDWARF5AccelTable(AsmPrinter *Asm,
|
||||
AccelTable<DWARF5AccelTableData> &Contents,
|
||||
void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents,
|
||||
const DwarfDebug &DD,
|
||||
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs);
|
||||
|
||||
@ -316,9 +317,9 @@ void emitDWARF5AccelTable(AsmPrinter *Asm,
|
||||
/// start of compilation unit, either offsets to the start of compilation
|
||||
/// unit themselves.
|
||||
void emitDWARF5AccelTable(
|
||||
AsmPrinter *Asm, AccelTable<DWARF5AccelTableStaticData> &Contents,
|
||||
AsmPrinter *Asm, DWARF5AccelTable &Contents,
|
||||
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
|
||||
llvm::function_ref<unsigned(const DWARF5AccelTableStaticData &)>
|
||||
llvm::function_ref<unsigned(const DWARF5AccelTableData &)>
|
||||
getCUIndexForEntry);
|
||||
|
||||
/// Accelerator table data implementation for simple Apple accelerator tables
|
||||
|
||||
@ -119,8 +119,7 @@ public:
|
||||
virtual void emitLineStrings(const NonRelocatableStringpool &Pool) = 0;
|
||||
|
||||
/// Emit DWARF debug names.
|
||||
virtual void
|
||||
emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) = 0;
|
||||
virtual void emitDebugNames(DWARF5AccelTable &Table) = 0;
|
||||
|
||||
/// Emit Apple namespaces accelerator table.
|
||||
virtual void
|
||||
@ -880,7 +879,7 @@ private:
|
||||
uint32_t LastCIEOffset = 0;
|
||||
|
||||
/// Apple accelerator tables.
|
||||
AccelTable<DWARF5AccelTableStaticData> DebugNames;
|
||||
DWARF5AccelTable DebugNames;
|
||||
AccelTable<AppleAccelTableStaticOffsetData> AppleNames;
|
||||
AccelTable<AppleAccelTableStaticOffsetData> AppleNamespaces;
|
||||
AccelTable<AppleAccelTableStaticOffsetData> AppleObjc;
|
||||
|
||||
@ -163,7 +163,7 @@ public:
|
||||
StringRef Bytes) override;
|
||||
|
||||
/// Emit DWARF debug names.
|
||||
void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table) override;
|
||||
void emitDebugNames(DWARF5AccelTable &Table) override;
|
||||
|
||||
/// Emit Apple namespaces accelerator table.
|
||||
void emitAppleNamespaces(
|
||||
|
||||
@ -357,6 +357,10 @@ void AppleAccelTableWriter::emit() const {
|
||||
emitData();
|
||||
}
|
||||
|
||||
DWARF5AccelTableData::DWARF5AccelTableData(const DIE &Die,
|
||||
const DwarfCompileUnit &CU)
|
||||
: OffsetVal(&Die), DieTag(Die.getTag()), UnitID(CU.getUniqueID()) {}
|
||||
|
||||
template <typename DataT>
|
||||
void Dwarf5AccelTableWriter<DataT>::Header::emit(Dwarf5AccelTableWriter &Ctx) {
|
||||
assert(CompUnitCount > 0 && "Index must have at least one CU.");
|
||||
@ -545,8 +549,8 @@ void llvm::emitAppleAccelTableImpl(AsmPrinter *Asm, AccelTableBase &Contents,
|
||||
}
|
||||
|
||||
void llvm::emitDWARF5AccelTable(
|
||||
AsmPrinter *Asm, AccelTable<DWARF5AccelTableData> &Contents,
|
||||
const DwarfDebug &DD, ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs) {
|
||||
AsmPrinter *Asm, DWARF5AccelTable &Contents, const DwarfDebug &DD,
|
||||
ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs) {
|
||||
std::vector<std::variant<MCSymbol *, uint64_t>> CompUnits;
|
||||
SmallVector<unsigned, 1> CUIndex(CUs.size());
|
||||
int Count = 0;
|
||||
@ -575,20 +579,19 @@ void llvm::emitDWARF5AccelTable(
|
||||
Dwarf5AccelTableWriter<DWARF5AccelTableData>(
|
||||
Asm, Contents, CompUnits,
|
||||
[&](const DWARF5AccelTableData &Entry) {
|
||||
const DIE *CUDie = Entry.getDie().getUnitDie();
|
||||
return CUIndex[DD.lookupCU(CUDie)->getUniqueID()];
|
||||
return CUIndex[Entry.getUnitID()];
|
||||
})
|
||||
.emit();
|
||||
}
|
||||
|
||||
void llvm::emitDWARF5AccelTable(
|
||||
AsmPrinter *Asm, AccelTable<DWARF5AccelTableStaticData> &Contents,
|
||||
AsmPrinter *Asm, DWARF5AccelTable &Contents,
|
||||
ArrayRef<std::variant<MCSymbol *, uint64_t>> CUs,
|
||||
llvm::function_ref<unsigned(const DWARF5AccelTableStaticData &)>
|
||||
llvm::function_ref<unsigned(const DWARF5AccelTableData &)>
|
||||
getCUIndexForEntry) {
|
||||
Contents.finalize(Asm, "names");
|
||||
Dwarf5AccelTableWriter<DWARF5AccelTableStaticData>(Asm, Contents, CUs,
|
||||
getCUIndexForEntry)
|
||||
Dwarf5AccelTableWriter<DWARF5AccelTableData>(Asm, Contents, CUs,
|
||||
getCUIndexForEntry)
|
||||
.emit();
|
||||
}
|
||||
|
||||
@ -687,11 +690,6 @@ void DWARF5AccelTableData::print(raw_ostream &OS) const {
|
||||
OS << " Tag: " << dwarf::TagString(getDieTag()) << "\n";
|
||||
}
|
||||
|
||||
void DWARF5AccelTableStaticData::print(raw_ostream &OS) const {
|
||||
OS << " Offset: " << getDieOffset() << "\n";
|
||||
OS << " Tag: " << dwarf::TagString(getDieTag()) << "\n";
|
||||
}
|
||||
|
||||
void AppleAccelTableOffsetData::print(raw_ostream &OS) const {
|
||||
OS << " Offset: " << Die.getOffset() << "\n";
|
||||
}
|
||||
|
||||
@ -1389,6 +1389,10 @@ void DwarfDebug::finalizeModuleInfo() {
|
||||
InfoHolder.computeSizeAndOffsets();
|
||||
if (useSplitDwarf())
|
||||
SkeletonHolder.computeSizeAndOffsets();
|
||||
|
||||
// Now that offsets are computed, can replace DIEs in debug_names Entry with
|
||||
// an actual offset.
|
||||
AccelDebugNames.convertDieToOffset();
|
||||
}
|
||||
|
||||
// Emit all Dwarf sections that should come after the content.
|
||||
@ -3547,9 +3551,11 @@ void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU,
|
||||
case AccelTableKind::Apple:
|
||||
AppleAccel.addName(Ref, Die);
|
||||
break;
|
||||
case AccelTableKind::Dwarf:
|
||||
AccelDebugNames.addName(Ref, Die);
|
||||
case AccelTableKind::Dwarf: {
|
||||
DwarfCompileUnit *DCU = CUMap.lookup(&CU);
|
||||
AccelDebugNames.addName(Ref, Die, *DCU);
|
||||
break;
|
||||
}
|
||||
case AccelTableKind::Default:
|
||||
llvm_unreachable("Default should have already been resolved.");
|
||||
case AccelTableKind::None:
|
||||
|
||||
@ -496,7 +496,7 @@ private:
|
||||
AddressPool AddrPool;
|
||||
|
||||
/// Accelerator tables.
|
||||
AccelTable<DWARF5AccelTableData> AccelDebugNames;
|
||||
DWARF5AccelTable AccelDebugNames;
|
||||
AccelTable<AppleAccelTableOffsetData> AccelNames;
|
||||
AccelTable<AppleAccelTableOffsetData> AccelObjC;
|
||||
AccelTable<AppleAccelTableOffsetData> AccelNamespace;
|
||||
|
||||
@ -291,8 +291,7 @@ void DwarfStreamer::emitLineStrings(const NonRelocatableStringpool &Pool) {
|
||||
}
|
||||
}
|
||||
|
||||
void DwarfStreamer::emitDebugNames(
|
||||
AccelTable<DWARF5AccelTableStaticData> &Table) {
|
||||
void DwarfStreamer::emitDebugNames(DWARF5AccelTable &Table) {
|
||||
if (EmittedUnits.empty())
|
||||
return;
|
||||
|
||||
@ -307,11 +306,10 @@ void DwarfStreamer::emitDebugNames(
|
||||
}
|
||||
|
||||
Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
|
||||
emitDWARF5AccelTable(
|
||||
Asm.get(), Table, CompUnits,
|
||||
[&UniqueIdToCuMap](const DWARF5AccelTableStaticData &Entry) {
|
||||
return UniqueIdToCuMap[Entry.getCUIndex()];
|
||||
});
|
||||
emitDWARF5AccelTable(Asm.get(), Table, CompUnits,
|
||||
[&UniqueIdToCuMap](const DWARF5AccelTableData &Entry) {
|
||||
return UniqueIdToCuMap[Entry.getUnitID()];
|
||||
});
|
||||
}
|
||||
|
||||
void DwarfStreamer::emitAppleNamespaces(
|
||||
|
||||
@ -223,16 +223,16 @@ void DwarfEmitterImpl::emitDIE(DIE &Die) {
|
||||
DebugInfoSectionSize += Die.getSize();
|
||||
}
|
||||
|
||||
void DwarfEmitterImpl::emitDebugNames(
|
||||
AccelTable<DWARF5AccelTableStaticData> &Table,
|
||||
DebugNamesUnitsOffsets &CUOffsets, CompUnitIDToIdx &CUidToIdx) {
|
||||
void DwarfEmitterImpl::emitDebugNames(DWARF5AccelTable &Table,
|
||||
DebugNamesUnitsOffsets &CUOffsets,
|
||||
CompUnitIDToIdx &CUidToIdx) {
|
||||
if (CUOffsets.empty())
|
||||
return;
|
||||
|
||||
Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
|
||||
emitDWARF5AccelTable(Asm.get(), Table, CUOffsets,
|
||||
[&CUidToIdx](const DWARF5AccelTableStaticData &Entry) {
|
||||
return CUidToIdx[Entry.getCUIndex()];
|
||||
[&CUidToIdx](const DWARF5AccelTableData &Entry) {
|
||||
return CUidToIdx[Entry.getUnitID()];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +87,7 @@ public:
|
||||
uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }
|
||||
|
||||
/// Emits .debug_names section according to the specified \p Table.
|
||||
void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &Table,
|
||||
void emitDebugNames(DWARF5AccelTable &Table,
|
||||
DebugNamesUnitsOffsets &CUOffsets,
|
||||
CompUnitIDToIdx &UnitIDToIdxMap);
|
||||
|
||||
|
||||
@ -1129,7 +1129,7 @@ void DWARFLinkerImpl::emitAppleAcceleratorSections(const Triple &TargetTriple) {
|
||||
}
|
||||
|
||||
void DWARFLinkerImpl::emitDWARFv5DebugNamesSection(const Triple &TargetTriple) {
|
||||
std::unique_ptr<AccelTable<DWARF5AccelTableStaticData>> DebugNames;
|
||||
std::unique_ptr<DWARF5AccelTable> DebugNames;
|
||||
|
||||
DebugNamesUnitsOffsets CompUnits;
|
||||
CompUnitIDToIdx CUidToIdx;
|
||||
@ -1144,7 +1144,7 @@ void DWARFLinkerImpl::emitDWARFv5DebugNamesSection(const Triple &TargetTriple) {
|
||||
|
||||
CU->AcceleratorRecords.forEach([&](const DwarfUnit::AccelInfo &Info) {
|
||||
if (DebugNames.get() == nullptr)
|
||||
DebugNames = std::make_unique<AccelTable<DWARF5AccelTableStaticData>>();
|
||||
DebugNames = std::make_unique<DWARF5AccelTable>();
|
||||
|
||||
switch (Info.Type) {
|
||||
case DwarfUnit::AccelType::Name:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user