From cf92efc497778c4abd5f402ba315020093aef4ad Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Sun, 21 Apr 2024 12:05:46 -0400 Subject: [PATCH] LibELF: Get rid of DynamicLoader::m_cached_dynamic_object The strategy of recreating an object for the second time after DynamicLoader::map is interesting, of course, but it doesn't help comprehensibility of the code, unfortunately. --- Userland/Libraries/LibELF/DynamicLoader.cpp | 17 ----------------- Userland/Libraries/LibELF/DynamicLoader.h | 4 +--- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/Userland/Libraries/LibELF/DynamicLoader.cpp b/Userland/Libraries/LibELF/DynamicLoader.cpp index f9962e5fcaf..c404b81edd3 100644 --- a/Userland/Libraries/LibELF/DynamicLoader.cpp +++ b/Userland/Libraries/LibELF/DynamicLoader.cpp @@ -98,23 +98,6 @@ DynamicLoader::~DynamicLoader() } } -DynamicObject const& DynamicLoader::dynamic_object() const -{ - if (!m_cached_dynamic_object) { - VirtualAddress dynamic_section_address; - - image().for_each_program_header([&dynamic_section_address](auto program_header) { - if (program_header.type() == PT_DYNAMIC) { - dynamic_section_address = VirtualAddress(program_header.raw_data()); - } - }); - VERIFY(!dynamic_section_address.is_null()); - - m_cached_dynamic_object = ELF::DynamicObject::create(m_filepath, VirtualAddress(image().base_address()), dynamic_section_address); - } - return *m_cached_dynamic_object; -} - void DynamicLoader::find_tls_size_and_alignment() { image().for_each_program_header([this](auto program_header) { diff --git a/Userland/Libraries/LibELF/DynamicLoader.h b/Userland/Libraries/LibELF/DynamicLoader.h index 43984c79452..3bd9162195c 100644 --- a/Userland/Libraries/LibELF/DynamicLoader.h +++ b/Userland/Libraries/LibELF/DynamicLoader.h @@ -88,7 +88,7 @@ public: static Optional lookup_symbol(const ELF::DynamicObject::Symbol&); void copy_initial_tls_data_into(Bytes buffer) const; - DynamicObject const& dynamic_object() const; + DynamicObject const& dynamic_object() const { return *m_dynamic_object; } bool is_fully_relocated() const { return m_fully_relocated; } bool is_fully_initialized() const { return m_fully_initialized; } @@ -178,8 +178,6 @@ private: Vector m_direct_ifunc_relocations; Vector m_plt_ifunc_relocations; - mutable RefPtr m_cached_dynamic_object; - bool m_fully_relocated { false }; bool m_fully_initialized { false }; };