[llvm] [BOLT][DWARF] Add support for transitive DW_AT_name/DW_AT_linkage_name resolution for DW_AT_name/DW_AT_linkage_name. (PR #119493)
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 07:21:06 PST 2024
================
@@ -359,24 +339,97 @@ DWARF5AcceleratorTable::addAccelTableEntry(
<< ".\n";
return std::nullopt;
}
- EntryDie = Iter->second;
- } else {
- const DIEEntry &DIEENtry = Value.getDIEEntry();
- EntryDie = &DIEENtry.getEntry();
+ return Iter->second;
}
-
- addEntry(EntryDie->findAttribute(dwarf::Attribute::DW_AT_linkage_name));
- return addEntry(EntryDie->findAttribute(dwarf::Attribute::DW_AT_name));
+ const DIEEntry &DIEENtry = Value.getDIEEntry();
+ return {{&Unit, &DIEENtry.getEntry()}};
};
- if (std::optional<BOLTDWARF5AccelTableData *> Entry =
- processReferencedDie(dwarf::Attribute::DW_AT_abstract_origin))
+ DIEValue AttrValLinkageName;
+ DIEValue AttrValName = Die.findAttribute(dwarf::Attribute::DW_AT_name);
+ DWARFUnit *RefUnit = &Unit;
+ const DIE *RefDieUsed = &Die;
+ // It is possible to have DW_TAG_subprogram only with DW_AT_linkage_name that
+ // DW_AT_abstract_origin/DW_AT_specification point to.
+ while (!AttrValName) {
+ std::optional<std::pair<DWARFUnit *, const DIE *>> RefDUDie =
+ getReferenceDie(Value, RefDieUsed);
+ if (!RefDUDie)
+ break;
+ RefUnit = RefDUDie->first;
+ const DIE &RefDie = *RefDUDie->second;
+ RefDieUsed = &RefDie;
+ if (!AttrValLinkageName)
+ AttrValLinkageName =
+ RefDie.findAttribute(dwarf::Attribute::DW_AT_linkage_name);
+ AttrValName = RefDie.findAttribute(dwarf::Attribute::DW_AT_name);
+ Value = RefDie.findAttribute(dwarf::Attribute::DW_AT_abstract_origin);
+ if (!Value)
+ Value = RefDie.findAttribute(dwarf::Attribute::DW_AT_specification);
+ }
+ addEntry(Unit, Die, DWOID, Parent,
+ getName(*RefUnit, DWOID, NameToUse, AttrValLinkageName),
+ NumberParentsInChain);
+ return addEntry(Unit, Die, DWOID, Parent,
+ getName(*RefUnit, DWOID, NameToUse, AttrValName),
+ NumberParentsInChain);
+}
+
+std::optional<BOLTDWARF5AccelTableData *>
+DWARF5AcceleratorTable::addAccelTableEntry(
+ DWARFUnit &Unit, const DIE &Die, const std::optional<uint64_t> &DWOID,
+ const uint32_t NumberParentsInChain,
+ std::optional<BOLTDWARF5AccelTableData *> &Parent) {
+ if (Unit.getVersion() < 5 || !NeedToCreate)
+ return std::nullopt;
+ std::string NameToUse = "";
+
+ if (!canProcess(Unit, Die, NameToUse, false))
+ return std::nullopt;
+
+ // Addes a Unit to either CU, LocalTU or ForeignTU list the first time we
+ // encounter it.
+ // Invoking it here so that we don't add Units that don't have any entries.
+ if (&Unit != CurrentUnit) {
+ CurrentUnit = &Unit;
+ addUnit(Unit, DWOID);
+ }
+
+ // Minor optimization not to add entry twice for DW_TAG_namespace if it has no
+ // DW_AT_name.
+ std::optional<BOLTDWARF5AccelTableData *> LinkageEntry = std::nullopt;
+ DIEValue NameVal = Die.findAttribute(dwarf::Attribute::DW_AT_name);
+ DIEValue LinkageNameVal =
+ Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name);
+ if (!(Die.getTag() == dwarf::DW_TAG_namespace && !NameVal))
+ LinkageEntry = addEntry(Unit, Die, DWOID, Parent,
+ getName(Unit, DWOID, NameToUse, LinkageNameVal),
+ NumberParentsInChain);
+
+ std::optional<BOLTDWARF5AccelTableData *> NameEntry =
+ addEntry(Unit, Die, DWOID, Parent,
+ getName(Unit, DWOID, NameToUse, NameVal), NumberParentsInChain);
+ if (NameEntry)
+ return NameEntry;
+
+ // The DIE doesn't have DW_AT_name or DW_AT_linkage_name, so we need to see if
+ // we can follow other attributes to find them. For the purposes of
+ // determining whether a debugging information entry has a particular
----------------
dcci wrote:
debugging -> debug.
https://github.com/llvm/llvm-project/pull/119493
More information about the llvm-commits
mailing list