Skip to content

Commit 6e73ff8

Browse files
committed
[BOLT][DWARF] Add support to debug_names for
DW_AT_abstract_origin/DW_AT_specification According to the DWARF spec a DIE that has DW_AT_specification or DW_AT_abstract_origin can be part of .debug_name if a DIE those attribute points to has DW_AT_name or DW_AT_linkage_name.
1 parent dbbdee2 commit 6e73ff8

File tree

5 files changed

+894
-136
lines changed

5 files changed

+894
-136
lines changed

bolt/lib/Core/DebugNames.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ DWARF5AcceleratorTable::addAccelTableEntry(
234234
addUnit(Unit, DWOID);
235235
}
236236

237-
auto addEntry =
238-
[&](DIEValue ValName) -> std::optional<BOLTDWARF5AccelTableData *> {
237+
auto getName = [&](DIEValue ValName) -> std::optional<std::string> {
239238
if ((!ValName || ValName.getForm() == dwarf::DW_FORM_string) &&
240239
NameToUse.empty())
241240
return std::nullopt;
@@ -268,7 +267,16 @@ DWARF5AcceleratorTable::addAccelTableEntry(
268267
// This the same hash function used in DWARF5AccelTableData.
269268
It.HashValue = caseFoldingDjbHash(Name);
270269
}
270+
return Name;
271+
};
272+
273+
auto addEntry =
274+
[&](DIEValue ValName) -> std::optional<BOLTDWARF5AccelTableData *> {
275+
std::optional<std::string> Name = getName(ValName);
276+
if (!Name)
277+
return std::nullopt;
271278

279+
auto &It = Entries[*Name];
272280
bool IsTU = false;
273281
uint32_t DieTag = 0;
274282
uint32_t UnitID = getUnitID(Unit, IsTU, DieTag);
@@ -278,7 +286,7 @@ DWARF5AcceleratorTable::addAccelTableEntry(
278286
if (Iter == CUOffsetsToPatch.end())
279287
BC.errs() << "BOLT-WARNING: [internal-dwarf-warning]: Could not find "
280288
"DWO ID in CU offsets for second Unit Index "
281-
<< Name << ". For DIE at offset: "
289+
<< *Name << ". For DIE at offset: "
282290
<< Twine::utohexstr(CurrentUnitOffset + Die.getOffset())
283291
<< ".\n";
284292
SecondIndex = Iter->second;
@@ -295,11 +303,33 @@ DWARF5AcceleratorTable::addAccelTableEntry(
295303
return It.Values.back();
296304
};
297305

298-
std::optional<BOLTDWARF5AccelTableData *> NameEntry =
299-
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_name));
300-
std::optional<BOLTDWARF5AccelTableData *> LinkageNameEntry =
301-
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
302-
return NameEntry ? NameEntry : LinkageNameEntry;
306+
// Minor optimization not to add entry twice for DW_TAG_namespace if it has no
307+
// DW_AT_name.
308+
if (!(Die.getTag() == dwarf::DW_TAG_namespace &&
309+
!Die.findAttribute(dwarf::Attribute::DW_AT_name)))
310+
addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
311+
// For the purposes of determining whether a debugging information entry has a
312+
// particular attribute (such as DW_AT_name), if debugging information entry A
313+
// has a DW_AT_specification or DW_AT_abstract_origin attribute pointing to
314+
// another debugging information entry B, any attributes of B are considered
315+
// to be part of A.
316+
if (DIEValue AbstrOrigin =
317+
Die.findAttribute(dwarf::Attribute::DW_AT_abstract_origin)) {
318+
const DIEEntry &DIEENtry = AbstrOrigin.getDIEEntry();
319+
DIE &EntryDie = DIEENtry.getEntry();
320+
addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
321+
return addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_name));
322+
}
323+
if (DIEValue AbstrOrigin =
324+
Die.findAttribute(dwarf::Attribute::DW_AT_specification)) {
325+
const DIEEntry &DIEENtry = AbstrOrigin.getDIEEntry();
326+
DIE &EntryDie = DIEENtry.getEntry();
327+
addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
328+
return addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_name));
329+
}
330+
331+
return addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_name));
332+
;
303333
}
304334

305335
/// Algorithm from llvm implementation.

0 commit comments

Comments
 (0)