mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +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:
parent
46a94a9a9e
commit
22b8110554
2 changed files with 9 additions and 5 deletions
|
@ -310,13 +310,10 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(const StringView& name, u32 h
|
||||||
for (hash1 &= ~1;; ++current_sym) {
|
for (hash1 &= ~1;; ++current_sym) {
|
||||||
hash2 = *(current_chain++);
|
hash2 = *(current_chain++);
|
||||||
auto symbol = m_dynamic.symbol(current_sym);
|
auto symbol = m_dynamic.symbol(current_sym);
|
||||||
if ((hash1 == (hash2 & ~1)) && name == symbol.name()) {
|
if ((hash1 == (hash2 & ~1)) && name == symbol.raw_name())
|
||||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Returning GNU dynamic symbol with index {} for {}: {}", current_sym, symbol.name(), symbol.address().as_ptr());
|
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
if (hash2 & 1)
|
||||||
if (hash2 & 1) {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
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() };
|
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
|
DynamicObject::InitializationFunction DynamicObject::init_section_function() const
|
||||||
{
|
{
|
||||||
ASSERT(has_init_section());
|
ASSERT(has_init_section());
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView name() const { return m_dynamic.symbol_string_table_string(m_sym.st_name); }
|
StringView name() const { return m_dynamic.symbol_string_table_string(m_sym.st_name); }
|
||||||
|
const char* raw_name() const { return m_dynamic.raw_symbol_string_table_string(m_sym.st_name); }
|
||||||
unsigned section_index() const { return m_sym.st_shndx; }
|
unsigned section_index() const { return m_sym.st_shndx; }
|
||||||
unsigned value() const { return m_sym.st_value; }
|
unsigned value() const { return m_sym.st_value; }
|
||||||
unsigned size() const { return m_sym.st_size; }
|
unsigned size() const { return m_sym.st_size; }
|
||||||
|
@ -264,6 +265,7 @@ private:
|
||||||
explicit DynamicObject(VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
explicit DynamicObject(VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
||||||
|
|
||||||
StringView symbol_string_table_string(Elf32_Word) const;
|
StringView symbol_string_table_string(Elf32_Word) const;
|
||||||
|
const char* raw_symbol_string_table_string(Elf32_Word) const;
|
||||||
void parse();
|
void parse();
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue