summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-21 00:29:08 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-21 00:29:52 +0100
commitf23b29f60581667597fc7db27abd6f1d5911b5b0 (patch)
tree22cf1dc7d7d012c29ceac9c7017be0e12ec5d407 /Userland/Libraries
parenta43910acc3aeb979c1fe74f2a3d0d39ea867b219 (diff)
downloadserenity-f23b29f60581667597fc7db27abd6f1d5911b5b0.zip
LibELF: Move DynamicObject::lookup_symbol() to DynamicLoader
Also simplify it by removing an unreachable code path.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibELF/DynamicLoader.cpp11
-rw-r--r--Userland/Libraries/LibELF/DynamicLoader.h4
-rw-r--r--Userland/Libraries/LibELF/DynamicObject.cpp19
-rw-r--r--Userland/Libraries/LibELF/DynamicObject.h2
4 files changed, 14 insertions, 22 deletions
diff --git a/Userland/Libraries/LibELF/DynamicLoader.cpp b/Userland/Libraries/LibELF/DynamicLoader.cpp
index ead38bee73..63be9b4548 100644
--- a/Userland/Libraries/LibELF/DynamicLoader.cpp
+++ b/Userland/Libraries/LibELF/DynamicLoader.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2019-2020, Andrew Kaster <andrewdkaster@gmail.com>
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
+ * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,6 +29,7 @@
#include <AK/Debug.h>
#include <AK/Optional.h>
#include <AK/StringBuilder.h>
+#include <LibELF/DynamicLinker.h>
#include <LibELF/DynamicLoader.h>
#include <LibELF/Validation.h>
#include <assert.h>
@@ -570,9 +572,14 @@ void DynamicLoader::call_object_init_functions()
}
}
-Optional<DynamicObject::SymbolLookupResult> DynamicLoader::lookup_symbol(const ELF::DynamicObject::Symbol& symbol) const
+Optional<DynamicObject::SymbolLookupResult> DynamicLoader::lookup_symbol(const ELF::DynamicObject::Symbol& symbol)
{
- return m_dynamic_object->lookup_symbol(symbol);
+ dbgln_if(DYNAMIC_LOAD_DEBUG, "looking up symbol: {}", symbol.name());
+ if (symbol.is_undefined() || symbol.bind() == STB_WEAK)
+ return DynamicLinker::lookup_global_symbol(symbol.name());
+
+ dbgln_if(DYNAMIC_LOAD_DEBUG, "symbol is defined in its object");
+ return DynamicObject::SymbolLookupResult { symbol.value(), symbol.address(), symbol.bind(), &symbol.object() };
}
} // end namespace ELF
diff --git a/Userland/Libraries/LibELF/DynamicLoader.h b/Userland/Libraries/LibELF/DynamicLoader.h
index 54dac90884..cc85270c2b 100644
--- a/Userland/Libraries/LibELF/DynamicLoader.h
+++ b/Userland/Libraries/LibELF/DynamicLoader.h
@@ -71,6 +71,8 @@ public:
VirtualAddress text_segment_load_address() const { return m_text_segment_load_address; }
bool is_dynamic() const { return m_elf_image.is_dynamic(); }
+ static Optional<DynamicObject::SymbolLookupResult> lookup_symbol(const ELF::DynamicObject::Symbol&);
+
private:
DynamicLoader(int fd, String filename, void* file_data, size_t file_size);
@@ -121,8 +123,6 @@ private:
RelocationResult do_relocation(size_t total_tls_size, const DynamicObject::Relocation&);
size_t calculate_tls_size() const;
- Optional<DynamicObject::SymbolLookupResult> lookup_symbol(const ELF::DynamicObject::Symbol&) const;
-
String m_filename;
String m_program_interpreter;
size_t m_file_size { 0 };
diff --git a/Userland/Libraries/LibELF/DynamicObject.cpp b/Userland/Libraries/LibELF/DynamicObject.cpp
index 7de32583f6..a238f731cf 100644
--- a/Userland/Libraries/LibELF/DynamicObject.cpp
+++ b/Userland/Libraries/LibELF/DynamicObject.cpp
@@ -28,7 +28,7 @@
#include <AK/Debug.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
-#include <LibELF/DynamicLinker.h>
+#include <LibELF/DynamicLoader.h>
#include <LibELF/DynamicObject.h>
#include <LibELF/exec_elf.h>
#include <string.h>
@@ -458,7 +458,7 @@ static const char* name_for_dtag(Elf32_Sword d_tag)
}
}
-Optional<DynamicObject::SymbolLookupResult> DynamicObject::lookup_symbol(const StringView& name) const
+auto DynamicObject::lookup_symbol(const StringView& name) const -> Optional<SymbolLookupResult>
{
auto result = hash_section().lookup_symbol(name);
if (!result.has_value())
@@ -482,7 +482,7 @@ VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
auto symbol = relocation.symbol();
u8* relocation_address = relocation.address().as_ptr();
- auto result = lookup_symbol(symbol);
+ auto result = DynamicLoader::lookup_symbol(symbol);
if (!result.has_value()) {
dbgln("did not find symbol: {}", symbol.name());
ASSERT_NOT_REACHED();
@@ -496,17 +496,4 @@ VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
return symbol_location;
}
-Optional<DynamicObject::SymbolLookupResult> DynamicObject::lookup_symbol(const ELF::DynamicObject::Symbol& symbol) const
-{
- dbgln_if(DYNAMIC_LOAD_DEBUG, "looking up symbol: {}", symbol.name());
- if (symbol.is_undefined() || symbol.bind() == STB_WEAK)
- return DynamicLinker::lookup_global_symbol(symbol.name());
-
- if (!symbol.is_undefined()) {
- dbgln_if(DYNAMIC_LOAD_DEBUG, "symbol is defined in its object");
- return SymbolLookupResult { symbol.value(), symbol.address(), symbol.bind(), &symbol.object() };
- }
- return DynamicLinker::lookup_global_symbol(symbol.name());
-}
-
} // end namespace ELF
diff --git a/Userland/Libraries/LibELF/DynamicObject.h b/Userland/Libraries/LibELF/DynamicObject.h
index ca71208e81..e65b02652f 100644
--- a/Userland/Libraries/LibELF/DynamicObject.h
+++ b/Userland/Libraries/LibELF/DynamicObject.h
@@ -264,8 +264,6 @@ public:
// Will be called from _fixup_plt_entry, as part of the PLT trampoline
VirtualAddress patch_plt_entry(u32 relocation_offset);
- Optional<SymbolLookupResult> lookup_symbol(const ELF::DynamicObject::Symbol&) const;
-
bool elf_is_dynamic() const { return m_is_elf_dynamic; }
private: