1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +00:00

LibELF: Move DynamicObject::lookup_symbol() to DynamicLoader

Also simplify it by removing an unreachable code path.
This commit is contained in:
Andreas Kling 2021-02-21 00:29:08 +01:00
parent a43910acc3
commit f23b29f605
4 changed files with 14 additions and 22 deletions

View file

@ -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