From 8ad74684ea249c179d76e2624668b6d2dd3a8085 Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Mon, 22 Mar 2021 05:57:39 +0000 Subject: LibELF: DynamicObject: Add rpath and runpath helpers --- Userland/Libraries/LibELF/DynamicObject.cpp | 12 ++++++++++++ Userland/Libraries/LibELF/DynamicObject.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibELF/DynamicObject.cpp b/Userland/Libraries/LibELF/DynamicObject.cpp index 8d2b08ca6b..c379d21e82 100644 --- a/Userland/Libraries/LibELF/DynamicObject.cpp +++ b/Userland/Libraries/LibELF/DynamicObject.cpp @@ -72,6 +72,10 @@ void DynamicObject::dump() const if (m_has_soname) builder.appendff("DT_SONAME: {}\n", soname()); // FIXME: Validate that this string is null terminated? + if (m_has_rpath) + builder.appendff("DT_RPATH: {}\n", rpath()); + if (m_has_runpath) + builder.appendff("DT_RUNPATH: {}\n", runpath()); dbgln_if(DYNAMIC_LOAD_DEBUG, "Dynamic section at address {} contains {} entries:", m_dynamic_address.as_ptr(), num_dynamic_sections); dbgln_if(DYNAMIC_LOAD_DEBUG, "{}", builder.string_view()); @@ -163,6 +167,14 @@ void DynamicObject::parse() case DT_BIND_NOW: m_dt_flags |= DF_BIND_NOW; break; + case DT_RPATH: + m_rpath_index = entry.val(); + m_has_rpath = true; + break; + case DT_RUNPATH: + m_runpath_index = entry.val(); + m_has_runpath = true; + break; case DT_DEBUG: break; case DT_FLAGS_1: diff --git a/Userland/Libraries/LibELF/DynamicObject.h b/Userland/Libraries/LibELF/DynamicObject.h index 151f5d898d..8fa50bc18c 100644 --- a/Userland/Libraries/LibELF/DynamicObject.h +++ b/Userland/Libraries/LibELF/DynamicObject.h @@ -238,6 +238,8 @@ public: VirtualAddress plt_got_base_address() const { return m_base_address.offset(m_procedure_linkage_table_offset.value()); } VirtualAddress base_address() const { return m_base_address; } + StringView rpath() const { return m_has_rpath ? symbol_string_table_string(m_rpath_index) : StringView {}; } + StringView runpath() const { return m_has_runpath ? symbol_string_table_string(m_runpath_index) : StringView {}; } StringView soname() const { return m_has_soname ? symbol_string_table_string(m_soname_index) : StringView {}; } Optional tls_offset() const { return m_tls_offset; } @@ -320,6 +322,10 @@ private: bool m_has_soname { false }; Elf32_Word m_soname_index { 0 }; // Index into dynstr table for SONAME + bool m_has_rpath { false }; + Elf32_Word m_rpath_index { 0 }; // Index into dynstr table for RPATH + bool m_has_runpath { false }; + Elf32_Word m_runpath_index { 0 }; // Index into dynstr table for RUNPATH Optional m_tls_offset; Optional m_tls_size; -- cgit v1.2.3