diff options
| author | Mason Reed <mason@vector35.com> | 2025-04-06 21:00:43 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-04-06 21:11:00 -0400 |
| commit | 833375c0199d4e7c2555e6e9f14862ddc3ca120c (patch) | |
| tree | 5cebee81848306b30d5b205d0116f1bcdad7737c /view/sharedcache/core/MachO.cpp | |
| parent | c22d54c5d95f4d23629484579414387b0c7503ee (diff) | |
[SharedCache] Prevent some unneeded copies when processing
Also swapped out CacheEntry::m_images to a vector as its never actually used as a lookup
Diffstat (limited to 'view/sharedcache/core/MachO.cpp')
| -rw-r--r-- | view/sharedcache/core/MachO.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/view/sharedcache/core/MachO.cpp b/view/sharedcache/core/MachO.cpp index 14fffefd..0b296af1 100644 --- a/view/sharedcache/core/MachO.cpp +++ b/view/sharedcache/core/MachO.cpp @@ -556,17 +556,17 @@ std::vector<CacheSymbol> SharedCacheMachOHeader::ReadSymbolTable(BinaryView& vie return symbolList; } -std::optional<CacheSymbol> SharedCacheMachOHeader::AddExportTerminalSymbol( - const std::string& symbolName, const uint8_t* current, const uint8_t* end) const +bool SharedCacheMachOHeader::AddExportTerminalSymbol( + std::vector<CacheSymbol>& symbols, const std::string& symbolName, const uint8_t *current, const uint8_t *end) const { uint64_t symbolFlags = readValidULEB128(current, end); if (symbolFlags & EXPORT_SYMBOL_FLAGS_REEXPORT) - return std::nullopt; + return false; uint64_t imageOffset = readValidULEB128(current, end); uint64_t symbolAddress = textBase + imageOffset; if (symbolName.empty() || symbolAddress == 0) - return std::nullopt; + return false; // Tries to get the symbol type based off the section containing it. auto sectionSymbolType = [&]() -> BNSymbolType { @@ -595,13 +595,17 @@ std::optional<CacheSymbol> SharedCacheMachOHeader::AddExportTerminalSymbol( { case EXPORT_SYMBOL_FLAGS_KIND_REGULAR: case EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL: - return CacheSymbol(sectionSymbolType(), symbolAddress, symbolName); + symbols.emplace_back(sectionSymbolType(), symbolAddress, symbolName); + break; case EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE: - return CacheSymbol(DataSymbol, symbolAddress, symbolName); + symbols.emplace_back(DataSymbol, symbolAddress, symbolName); + break; default: LogWarn("Unhandled export symbol kind: %llx", symbolFlags & EXPORT_SYMBOL_FLAGS_KIND_MASK); - return std::nullopt; + return false; } + + return true; } // TODO: This is like 90% of the runtime. @@ -616,12 +620,7 @@ bool SharedCacheMachOHeader::ProcessLinkEditTrie(std::vector<CacheSymbol>& symbo // The terminal is an export symbol. if (terminalSize != 0) - { - // Add the export symbol is applicable. - auto symbol = AddExportTerminalSymbol(currentText, current, end); - if (symbol.has_value()) - symbols.push_back(*symbol); - } + AddExportTerminalSymbol(symbols, currentText, current, end); // TODO: Make this look better current = child; |
