1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:38:10 +00:00

LibELF: Don't recompute the same ELF hashes over and over

When performing a global symbol lookup, we were recomputing the symbol
hashes once for every dynamic object searched. The hash function was
at the very top of a profile (15%) of program startup.

With this change, the hash function is no longer visible among the top
stacks in the profile. :^)
This commit is contained in:
Andreas Kling 2021-02-23 18:44:09 +01:00
parent af6a633468
commit d6af3302e8
4 changed files with 29 additions and 27 deletions

View file

@ -38,6 +38,7 @@
#include <LibELF/DynamicLinker.h>
#include <LibELF/DynamicLoader.h>
#include <LibELF/DynamicObject.h>
#include <LibELF/Hashes.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <sys/types.h>
@ -64,8 +65,12 @@ bool g_do_breakpoint_trap_before_entry { false };
Optional<DynamicObject::SymbolLookupResult> DynamicLinker::lookup_global_symbol(const StringView& symbol)
{
Optional<DynamicObject::SymbolLookupResult> weak_result;
auto gnu_hash = compute_gnu_hash(symbol);
auto sysv_hash = compute_sysv_hash(symbol);
for (auto& lib : g_global_objects) {
auto res = lib->lookup_symbol(symbol);
auto res = lib->lookup_symbol(symbol, gnu_hash, sysv_hash);
if (!res.has_value())
continue;
if (res.value().bind == STB_GLOBAL)