diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-23 19:00:41 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-23 19:43:44 +0100 |
commit | 22b81105541ccf1deac2d712a8e1b6067ae18f2a (patch) | |
tree | 4d344d843ed54e700ff124b85e51fd6e5f14499c /Userland/Libraries/LibELF | |
parent | 46a94a9a9ef62dcdb7034fc99828a4510cfa3275 (diff) | |
download | serenity-22b81105541ccf1deac2d712a8e1b6067ae18f2a.zip |
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. :^)
Diffstat (limited to 'Userland/Libraries/LibELF')
-rw-r--r-- | Userland/Libraries/LibELF/DynamicObject.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibELF/DynamicObject.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Libraries/LibELF/DynamicObject.cpp b/Userland/Libraries/LibELF/DynamicObject.cpp index af9540f467..8b3bd8c0bb 100644 --- a/Userland/Libraries/LibELF/DynamicObject.cpp +++ b/Userland/Libraries/LibELF/DynamicObject.cpp @@ -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()); diff --git a/Userland/Libraries/LibELF/DynamicObject.h b/Userland/Libraries/LibELF/DynamicObject.h index b5b309fff7..3a1a183728 100644 --- a/Userland/Libraries/LibELF/DynamicObject.h +++ b/Userland/Libraries/LibELF/DynamicObject.h @@ -75,6 +75,7 @@ public: } 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 value() const { return m_sym.st_value; } unsigned size() const { return m_sym.st_size; } @@ -264,6 +265,7 @@ private: explicit DynamicObject(VirtualAddress base_address, VirtualAddress dynamic_section_address); StringView symbol_string_table_string(Elf32_Word) const; + const char* raw_symbol_string_table_string(Elf32_Word) const; void parse(); template<typename F> |