Skip to content

Revert "[CLANG][DWARF] Handle DIE offset collision in DW_IDX_parent" #95302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 15 additions & 34 deletions llvm/include/llvm/CodeGen/AccelTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,18 @@ class AppleAccelTableData : public AccelTableData {

/// Helper class to identify an entry in DWARF5AccelTable based on their DIE
/// offset and UnitID.
struct OffsetAndUnitID {
uint64_t Offset = 0;
uint32_t UnitID = 0;
bool IsTU = false;
OffsetAndUnitID() = default;
OffsetAndUnitID(uint64_t Offset, uint32_t UnitID, bool IsTU)
: Offset(Offset), UnitID(UnitID), IsTU(IsTU) {}
uint64_t offset() const { return Offset; };
uint32_t unitID() const { return UnitID; };
bool isTU() const { return IsTU; }
};
struct OffsetAndUnitID : std::pair<uint64_t, uint32_t> {
using Base = std::pair<uint64_t, uint32_t>;
OffsetAndUnitID(Base B) : Base(B) {}

template <> struct DenseMapInfo<OffsetAndUnitID> {
static inline OffsetAndUnitID getEmptyKey() {
OffsetAndUnitID Entry;
Entry.Offset = uint64_t(-1);
return Entry;
}
static inline OffsetAndUnitID getTombstoneKey() {
OffsetAndUnitID Entry;
Entry.Offset = uint64_t(-2);
return Entry;
}
static unsigned getHashValue(const OffsetAndUnitID &Val) {
return (unsigned)llvm::hash_combine(Val.offset(), Val.unitID(), Val.IsTU);
}
static bool isEqual(const OffsetAndUnitID &LHS, const OffsetAndUnitID &RHS) {
return LHS.offset() == RHS.offset() && LHS.unitID() == RHS.unitID() &&
LHS.IsTU == RHS.isTU();
}
OffsetAndUnitID(uint64_t Offset, uint32_t UnitID) : Base(Offset, UnitID) {}
uint64_t offset() const { return first; };
uint32_t unitID() const { return second; };
};

template <>
struct DenseMapInfo<OffsetAndUnitID> : DenseMapInfo<OffsetAndUnitID::Base> {};

/// The Data class implementation for DWARF v5 accelerator table. Unlike the
/// Apple Data classes, this class is just a DIE wrapper, and does not know to
/// serialize itself. The complete serialization logic is in the
Expand All @@ -297,11 +277,12 @@ class DWARF5AccelTableData : public AccelTableData {
public:
static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }

DWARF5AccelTableData(const DIE &Die, const uint32_t UnitID, const bool IsTU);
DWARF5AccelTableData(const DIE &Die, const uint32_t UnitID,
const bool IsTU = false);
DWARF5AccelTableData(const uint64_t DieOffset,
const std::optional<uint64_t> DefiningParentOffset,
const unsigned DieTag, const unsigned UnitID,
const bool IsTU)
const bool IsTU = false)
: OffsetVal(DieOffset), ParentOffset(DefiningParentOffset),
DieTag(DieTag), AbbrevNumber(0), IsTU(IsTU), UnitID(UnitID) {}

Expand All @@ -315,7 +296,7 @@ class DWARF5AccelTableData : public AccelTableData {
}

OffsetAndUnitID getDieOffsetAndUnitID() const {
return {getDieOffset(), getUnitID(), isTU()};
return {getDieOffset(), UnitID};
}

unsigned getDieTag() const { return DieTag; }
Expand All @@ -341,7 +322,7 @@ class DWARF5AccelTableData : public AccelTableData {
assert(isNormalized() && "Accessing DIE Offset before normalizing.");
if (!ParentOffset)
return std::nullopt;
return OffsetAndUnitID(*ParentOffset, getUnitID(), isTU());
return OffsetAndUnitID(*ParentOffset, getUnitID());
}

/// Sets AbbrevIndex for an Entry.
Expand Down Expand Up @@ -435,7 +416,7 @@ class DWARF5AccelTable : public AccelTable<DWARF5AccelTableData> {
for (auto *Data : Entry.second.getValues<DWARF5AccelTableData *>()) {
addName(Entry.second.Name, Data->getDieOffset(),
Data->getParentDieOffset(), Data->getDieTag(),
Data->getUnitID(), Data->isTU());
Data->getUnitID(), true);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3592,8 +3592,7 @@ void DwarfDebug::addAccelNameImpl(
"Kind is TU but CU is being processed.");
// 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.
Current.addName(Ref, Die, Unit.getUniqueID(),
Unit.getUnitDie().getTag() == dwarf::DW_TAG_type_unit);
Current.addName(Ref, Die, Unit.getUniqueID());
break;
}
case AccelTableKind::Default:
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,20 +2247,17 @@ void DWARFLinker::emitAcceleratorEntriesForUnit(CompileUnit &Unit) {
DebugNames.addName(
Namespace.Name, Namespace.Die->getOffset(),
DWARF5AccelTableData::getDefiningParentDieOffset(*Namespace.Die),
Namespace.Die->getTag(), Unit.getUniqueID(),
Unit.getOutputUnitDIE()->getTag() == dwarf::DW_TAG_type_unit);
Namespace.Die->getTag(), Unit.getUniqueID());
for (const auto &Pubname : Unit.getPubnames())
DebugNames.addName(
Pubname.Name, Pubname.Die->getOffset(),
DWARF5AccelTableData::getDefiningParentDieOffset(*Pubname.Die),
Pubname.Die->getTag(), Unit.getUniqueID(),
Unit.getOutputUnitDIE()->getTag() == dwarf::DW_TAG_type_unit);
Pubname.Die->getTag(), Unit.getUniqueID());
for (const auto &Pubtype : Unit.getPubtypes())
DebugNames.addName(
Pubtype.Name, Pubtype.Die->getOffset(),
DWARF5AccelTableData::getDefiningParentDieOffset(*Pubtype.Die),
Pubtype.Die->getTag(), Unit.getUniqueID(),
Unit.getOutputUnitDIE()->getTag() == dwarf::DW_TAG_type_unit);
Pubtype.Die->getTag(), Unit.getUniqueID());
} break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,10 +1356,9 @@ void DWARFLinkerImpl::emitDWARFv5DebugNamesSection(const Triple &TargetTriple) {
case DwarfUnit::AccelType::Name:
case DwarfUnit::AccelType::Namespace:
case DwarfUnit::AccelType::Type: {
DebugNames->addName(
*DebugStrStrings.getExistingEntry(Info.String), Info.OutOffset,
std::nullopt /*ParentDIEOffset*/, Info.Tag, CU->getUniqueID(),
CU->getOutUnitDIE()->getTag() == dwarf::DW_TAG_type_unit);
DebugNames->addName(*DebugStrStrings.getExistingEntry(Info.String),
Info.OutOffset, std::nullopt /*ParentDIEOffset*/,
Info.Tag, CU->getUniqueID());
} break;

default:
Expand Down
69 changes: 0 additions & 69 deletions llvm/test/DebugInfo/X86/debug-names-types-die-offset-collision.ll

This file was deleted.

Loading