mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:12:08 +00:00
LibELF: Split do_relocation
into do_{direct,plt}_relocation
No functional changes intended. This is in preparation of a commit that overhauls how IFUNCs are resolved. This commit lets us move the implementation of PLT patching from `DynamicObject` to `DynamicLoader` where all other relocation code lives. For this, got[2] now stores the loader's address instead of the object's.
This commit is contained in:
parent
c4e0f5e5ee
commit
cd45c2d295
4 changed files with 82 additions and 56 deletions
|
@ -480,33 +480,6 @@ NonnullRefPtr<DynamicObject> DynamicObject::create(DeprecatedString const& filep
|
|||
return adopt_ref(*new DynamicObject(filepath, base_address, dynamic_section_address));
|
||||
}
|
||||
|
||||
// offset is in PLT relocation table
|
||||
VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
|
||||
{
|
||||
auto relocation = plt_relocation_section().relocation_at_offset(relocation_offset);
|
||||
VERIFY(relocation.type() == R_X86_64_JUMP_SLOT || relocation.type() == R_AARCH64_JUMP_SLOT);
|
||||
auto symbol = relocation.symbol();
|
||||
auto relocation_address = (FlatPtr*)relocation.address().as_ptr();
|
||||
|
||||
VirtualAddress symbol_location;
|
||||
auto result = DynamicLoader::lookup_symbol(symbol);
|
||||
if (result.has_value()) {
|
||||
symbol_location = result.value().address;
|
||||
|
||||
if (result.value().type == STT_GNU_IFUNC)
|
||||
symbol_location = VirtualAddress { reinterpret_cast<IfuncResolver>(symbol_location.get())() };
|
||||
} else if (symbol.bind() != STB_WEAK) {
|
||||
dbgln("did not find symbol while doing relocations for library {}: {}", m_filepath, symbol.name());
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "DynamicLoader: Jump slot relocation: putting {} ({}) into PLT at {}", symbol.name(), symbol_location, (void*)relocation_address);
|
||||
|
||||
*relocation_address = symbol_location.get();
|
||||
|
||||
return symbol_location;
|
||||
}
|
||||
|
||||
u32 DynamicObject::HashSymbol::gnu_hash() const
|
||||
{
|
||||
if (!m_gnu_hash.has_value())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue