1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

LibELF: Avoid doing strlen() on everything while iterating GNU hash

It's a lot faster to iterate the GNU hash tables if we don't have to
compute the length of every symbol name before rejecting it anyway while
comparing the first character. :^)
This commit is contained in:
Andreas Kling 2021-02-23 19:00:41 +01:00
parent 46a94a9a9e
commit 22b8110554
2 changed files with 9 additions and 5 deletions

View file

@ -310,13 +310,10 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(const StringView& name, u32 h
for (hash1 &= ~1;; ++current_sym) {
hash2 = *(current_chain++);
auto symbol = m_dynamic.symbol(current_sym);
if ((hash1 == (hash2 & ~1)) && name == symbol.name()) {
dbgln_if(DYNAMIC_LOAD_DEBUG, "Returning GNU dynamic symbol with index {} for {}: {}", current_sym, symbol.name(), symbol.address().as_ptr());
if ((hash1 == (hash2 & ~1)) && name == symbol.raw_name())
return symbol;
}
if (hash2 & 1) {
if (hash2 & 1)
break;
}
}
return {};
@ -327,6 +324,11 @@ StringView DynamicObject::symbol_string_table_string(Elf32_Word index) const
return StringView { (const char*)base_address().offset(m_string_table_offset + index).as_ptr() };
}
const char* DynamicObject::raw_symbol_string_table_string(Elf32_Word index) const
{
return (const char*)base_address().offset(m_string_table_offset + index).as_ptr();
}
DynamicObject::InitializationFunction DynamicObject::init_section_function() const
{
ASSERT(has_init_section());