Skip to content

Commit

Permalink
fileformat/elf: use ptrs in import cache instead of refs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMatula committed Sep 25, 2024
1 parent ff062cb commit eb3a17d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/fileformat/file_format/elf/elf_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,19 @@ void ElfFormat::loadSymbols(const ELFIO::elfio *file, const ELFIO::symbol_sectio
// To save space, this uses string references and relies on imports not
// being moved -- they should not be, as ImportTable stores vector of unique
// pointers, but if that ever changes, this will end badly.
std::set<std::pair<const std::string&, unsigned long long>> createdImports;
auto createdImportsComparator = [](
const std::pair<const std::string*, unsigned long long>& lhs,
const std::pair<const std::string*, unsigned long long>& rhs
) {
if (*(lhs.first) != *(rhs.first)) {
return *(lhs.first) < *(rhs.first);
}
return lhs.second < rhs.second;
};
std::set<
std::pair<const std::string*, unsigned long long>,
decltype(createdImportsComparator)
> createdImports(createdImportsComparator);

for(std::size_t i = 0, e = elfSymbolTable->get_loaded_symbols_num(); i < e; ++i)
{
Expand Down Expand Up @@ -1795,7 +1807,7 @@ void ElfFormat::loadSymbols(const ELFIO::elfio *file, const ELFIO::symbol_sectio
std::set<std::pair<std::string, unsigned long long>> addresses;
for (auto it = keyIter.first; it != keyIter.second; ++it)
{
if (createdImports.count({std::cref(it->first), it->second})) {
if (!createdImports.count({&it->first, it->second})) {
addresses.insert(*it);
}
}
Expand All @@ -1809,7 +1821,7 @@ void ElfFormat::loadSymbols(const ELFIO::elfio *file, const ELFIO::symbol_sectio
auto* inserted = importTable->addImport(std::move(import));

if (inserted) {
createdImports.emplace(inserted->getName(), inserted->getAddress());
createdImports.emplace(&inserted->getName(), inserted->getAddress());
}
}
if(keyIter.first == keyIter.second && getSectionFromAddress(value))
Expand All @@ -1821,7 +1833,7 @@ void ElfFormat::loadSymbols(const ELFIO::elfio *file, const ELFIO::symbol_sectio
auto* inserted = importTable->addImport(std::move(import));

if (inserted) {
createdImports.emplace(inserted->getName(), inserted->getAddress());
createdImports.emplace(&inserted->getName(), inserted->getAddress());
}
}
}
Expand Down

0 comments on commit eb3a17d

Please sign in to comment.