[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:19:15 PST 2024
================
@@ -222,134 +222,114 @@ static uint64_t getEntryID(const BOLTDWARF5AccelTableData &Entry) {
return reinterpret_cast<uint64_t>(&Entry);
}
-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 = "";
-
- auto getUnitID = [&](const DWARFUnit &Unit, bool &IsTU,
- uint32_t &DieTag) -> uint32_t {
- IsTU = Unit.isTypeUnit();
- DieTag = Die.getTag();
- if (IsTU) {
- if (DWOID) {
- const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
- auto Iter = TUHashToIndexMap.find(TUHash);
- assert(Iter != TUHashToIndexMap.end() &&
- "Could not find TU hash in map");
- return Iter->second;
- }
- return LocalTUList.size() - 1;
+uint32_t DWARF5AcceleratorTable::getUnitID(const DWARFUnit &Unit,
+ const std::optional<uint64_t> &DWOID,
+ bool &IsTU) {
+ IsTU = Unit.isTypeUnit();
+ if (IsTU) {
+ if (DWOID) {
+ const uint64_t TUHash = cast<DWARFTypeUnit>(&Unit)->getTypeHash();
+ auto Iter = TUHashToIndexMap.find(TUHash);
+ assert(Iter != TUHashToIndexMap.end() && "Could not find TU hash in map");
+ return Iter->second;
}
- return CUList.size() - 1;
- };
+ return LocalTUList.size() - 1;
+ }
+ return CUList.size() - 1;
+}
- if (!canProcess(Unit, Die, NameToUse, false))
+std::optional<std::string> DWARF5AcceleratorTable::getName(
+ DWARFUnit &Unit, const std::optional<uint64_t> &DWOID,
+ const std::string &NameToUse, DIEValue ValName) {
+ if ((!ValName || ValName.getForm() == dwarf::DW_FORM_string) &&
+ NameToUse.empty())
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);
+ std::string Name = "";
+ uint64_t NameIndexOffset = 0;
+ if (NameToUse.empty()) {
+ NameIndexOffset = ValName.getDIEInteger().getValue();
+ if (ValName.getForm() != dwarf::DW_FORM_strp)
+ NameIndexOffset = getNameOffset(BC, Unit, NameIndexOffset);
+ // Counts on strings end with '\0'.
+ Name = std::string(&StrSection.data()[NameIndexOffset]);
+ } else {
+ Name = NameToUse;
}
-
- auto getName = [&](DIEValue ValName) -> std::optional<std::string> {
- if ((!ValName || ValName.getForm() == dwarf::DW_FORM_string) &&
- NameToUse.empty())
- return std::nullopt;
- std::string Name = "";
- uint64_t NameIndexOffset = 0;
- if (NameToUse.empty()) {
- NameIndexOffset = ValName.getDIEInteger().getValue();
- if (ValName.getForm() != dwarf::DW_FORM_strp)
- NameIndexOffset = getNameOffset(BC, Unit, NameIndexOffset);
- // Counts on strings end with '\0'.
- Name = std::string(&StrSection.data()[NameIndexOffset]);
- } else {
- Name = NameToUse;
- }
- auto &It = Entries[Name];
- if (It.Values.empty()) {
- if (DWOID && NameToUse.empty()) {
- // For DWO Unit the offset is in the .debug_str.dwo section.
- // Need to find offset for the name in the .debug_str section.
- llvm::hash_code Hash = llvm::hash_value(llvm::StringRef(Name));
- auto ItCache = StrCacheToOffsetMap.find(Hash);
- if (ItCache == StrCacheToOffsetMap.end())
- NameIndexOffset = MainBinaryStrWriter.addString(Name);
- else
- NameIndexOffset = ItCache->second;
- }
- if (!NameToUse.empty())
+ auto &It = Entries[Name];
+ if (It.Values.empty()) {
+ if (DWOID && NameToUse.empty()) {
+ // For DWO Unit the offset is in the .debug_str.dwo section.
+ // Need to find offset for the name in the .debug_str section.
+ llvm::hash_code Hash = llvm::hash_value(llvm::StringRef(Name));
+ auto ItCache = StrCacheToOffsetMap.find(Hash);
+ if (ItCache == StrCacheToOffsetMap.end())
NameIndexOffset = MainBinaryStrWriter.addString(Name);
- It.StrOffset = NameIndexOffset;
- // This the same hash function used in DWARF5AccelTableData.
- It.HashValue = caseFoldingDjbHash(Name);
+ else
+ NameIndexOffset = ItCache->second;
}
- return Name;
- };
+ if (!NameToUse.empty())
+ NameIndexOffset = MainBinaryStrWriter.addString(Name);
+ It.StrOffset = NameIndexOffset;
+ // This the same hash function used in DWARF5AccelTableData.
----------------
dcci wrote:
"this is"
https://github.com/llvm/llvm-project/pull/119493
More information about the llvm-commits
mailing list