mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibELF: Move DynamicObject::lookup_symbol() to DynamicLoader
Also simplify it by removing an unreachable code path.
This commit is contained in:
parent
a43910acc3
commit
f23b29f605
Notes:
sideshowbarker
2024-07-18 22:04:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f23b29f6058
4 changed files with 14 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue