Skip to content
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

[LLVM][DWARF] Chnage order for .debug_names abbrev print out #80229

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 5 additions & 3 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,15 @@ class DWARFDebugNames : public DWARFAcceleratorTable {

/// Abbreviation describing the encoding of Name Index entries.
struct Abbrev {
uint32_t Code; ///< Abbreviation code
uint64_t AbbrevOffset; /// < Abbreviation offset in the .debug_names section
ayermolo marked this conversation as resolved.
Show resolved Hide resolved
uint32_t Code; ///< Abbreviation code
dwarf::Tag Tag; ///< Dwarf Tag of the described entity.
std::vector<AttributeEncoding> Attributes; ///< List of index attributes.

Abbrev(uint32_t Code, dwarf::Tag Tag,
Abbrev(uint32_t Code, dwarf::Tag Tag, uint64_t AbbrevOffset,
std::vector<AttributeEncoding> Attributes)
: Code(Code), Tag(Tag), Attributes(std::move(Attributes)) {}
: AbbrevOffset(AbbrevOffset), Code(Code), Tag(Tag),
Attributes(std::move(Attributes)) {}

void dump(ScopedPrinter &W) const;
};
Expand Down
19 changes: 13 additions & 6 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE) {
}

static DWARFDebugNames::Abbrev sentinelAbbrev() {
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), {});
return DWARFDebugNames::Abbrev(0, dwarf::Tag(0), 0, {});
}

static bool isSentinel(const DWARFDebugNames::Abbrev &Abbr) {
Expand All @@ -505,7 +505,7 @@ DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getEmptyKey() {
}

DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getTombstoneKey() {
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), {});
return DWARFDebugNames::Abbrev(~0, dwarf::Tag(0), 0, {});
}

Expected<DWARFDebugNames::AttributeEncoding>
Expand Down Expand Up @@ -540,7 +540,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
return createStringError(errc::illegal_byte_sequence,
"Incorrectly terminated abbreviation table.");
}

const uint64_t AbbrevOffset = *Offset;
uint32_t Code = Section.AccelSection.getULEB128(Offset);
if (Code == 0)
return sentinelAbbrev();
Expand All @@ -549,7 +549,7 @@ DWARFDebugNames::NameIndex::extractAbbrev(uint64_t *Offset) {
auto AttrEncOr = extractAttributeEncodings(Offset);
if (!AttrEncOr)
return AttrEncOr.takeError();
return Abbrev(Code, dwarf::Tag(Tag), std::move(*AttrEncOr));
return Abbrev(Code, dwarf::Tag(Tag), AbbrevOffset, std::move(*AttrEncOr));
}

Error DWARFDebugNames::NameIndex::extract() {
Expand Down Expand Up @@ -847,8 +847,15 @@ void DWARFDebugNames::NameIndex::dumpForeignTUs(ScopedPrinter &W) const {

void DWARFDebugNames::NameIndex::dumpAbbreviations(ScopedPrinter &W) const {
ListScope AbbrevsScope(W, "Abbreviations");
for (const auto &Abbr : Abbrevs)
Abbr.dump(W);
std::vector<const Abbrev *> AbbrevsVect;
for (const llvm::DWARFDebugNames::Abbrev &Abbr : Abbrevs)
ayermolo marked this conversation as resolved.
Show resolved Hide resolved
AbbrevsVect.push_back(&Abbr);
std::sort(AbbrevsVect.begin(), AbbrevsVect.end(),
Copy link
Contributor

@felipepiovezan felipepiovezan Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never use std::sort, instead using the range-based (with some shuffling magic for expensive asserts) sort from stl extras:

sort(AbbrevsVect, [] (...){});

https://llvm.org/docs/CodingStandards.html#beware-of-non-deterministic-sorting-order-of-equal-elements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My interpretation that only applies if we have equal elements. Which shouldn't be the case in this case. Abbrev offsets are monotonically increasing.

[](const Abbrev *LHS, const Abbrev *RHS) {
return LHS->AbbrevOffset < RHS->AbbrevOffset;
});
for (const llvm::DWARFDebugNames::Abbrev *Abbr : AbbrevsVect)
ayermolo marked this conversation as resolved.
Show resolved Hide resolved
Abbr->dump(W);
}

void DWARFDebugNames::NameIndex::dumpBucket(ScopedPrinter &W,
Expand Down
Loading