Skip to content
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
3 changes: 3 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ class BinaryContext {
/// Returns true if DWARF4 or lower is used.
bool isDWARFLegacyUsed() const { return ContainsDwarfLegacy; }

/// Returns true if DWARFUnit is valid.
bool isValidDwarfUnit(DWARFUnit &DU) const;

std::map<unsigned, DwarfLineTable> &getDwarfLineTables() {
return DwarfLineTablesCUMap;
}
Expand Down
3 changes: 2 additions & 1 deletion bolt/include/bolt/Core/DIEBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ class DIEBuilder {
std::optional<BOLTDWARF5AccelTableData *> Parent,
uint32_t NumberParentsInChain);

void registerUnit(DWARFUnit &DU, bool NeedSort);
/// Returns true if DWARFUnit is registered successfully.
bool registerUnit(DWARFUnit &DU, bool NeedSort);

/// \return the unique ID of \p U if it exists.
std::optional<uint32_t> getUnitId(const DWARFUnit &DU);
Expand Down
16 changes: 16 additions & 0 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,10 +1624,26 @@ DWARFContext *BinaryContext::getDWOContext() const {
return &DWOCUs.begin()->second->getContext();
}

bool BinaryContext::isValidDwarfUnit(DWARFUnit &DU) const {
// Invalid DWARF unit with a DWOId but lacking a dwo_name.
if (DU.getDWOId() && !DU.isDWOUnit() &&
!DU.getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name})) {
this->outs() << "BOLT-ERROR: broken DWARF found in CU at offset 0x"
<< Twine::utohexstr(DU.getOffset()) << " (DWOId=0x"
<< Twine::utohexstr(*(DU.getDWOId()))
<< ", missing DW_AT_dwo_name / DW_AT_GNU_dwo_name)\n";
return false;
}
return true;
}

/// Handles DWO sections that can either be in .o, .dwo or .dwp files.
void BinaryContext::preprocessDWODebugInfo() {
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
DWARFUnit *const DwarfUnit = CU.get();
if (!isValidDwarfUnit(*DwarfUnit))
continue;
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
std::string DWOName = dwarf::toString(
DwarfUnit->getUnitDIE().find(
Expand Down
10 changes: 7 additions & 3 deletions bolt/lib/Core/DIEBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ DWARFDie DIEBuilder::resolveDIEReference(
if ((RefCU =
getUnitForOffset(*this, *DwarfContext, TmpRefOffset, AttrSpec))) {
/// Trying to add to current working set in case it's cross CU reference.
registerUnit(*RefCU, true);
if (!registerUnit(*RefCU, true))
return DWARFDie();
DWARFDataExtractor DebugInfoData = RefCU->getDebugInfoExtractor();
if (DwarfDebugInfoEntry.extractFast(*RefCU, &TmpRefOffset, DebugInfoData,
RefCU->getNextUnitOffset(), 0)) {
Expand Down Expand Up @@ -1008,12 +1009,14 @@ static uint64_t getHash(const DWARFUnit &DU) {
return DU.getOffset();
}

void DIEBuilder::registerUnit(DWARFUnit &DU, bool NeedSort) {
bool DIEBuilder::registerUnit(DWARFUnit &DU, bool NeedSort) {
if (!BC.isValidDwarfUnit(DU))
return false;
auto IterGlobal = AllProcessed.insert(getHash(DU));
// If DU is already in a current working set or was already processed we can
// skip it.
if (!IterGlobal.second)
return;
return true;
if (getState().Type == ProcessingType::DWARF4TUs) {
getState().DWARF4TUVector.push_back(&DU);
} else if (getState().Type == ProcessingType::DWARF5TUs) {
Expand All @@ -1034,6 +1037,7 @@ void DIEBuilder::registerUnit(DWARFUnit &DU, bool NeedSort) {
if (getState().DUList.size() == getState().CloneUnitCtxMap.size())
getState().CloneUnitCtxMap.emplace_back();
getState().DUList.push_back(&DU);
return true;
}

std::optional<uint32_t> DIEBuilder::getUnitId(const DWARFUnit &DU) {
Expand Down
Loading
Loading