mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:17:42 +00:00
LibELF: Implement PLT relocations for x86_64
This commit is contained in:
parent
1d4ae9194e
commit
d3127efc01
3 changed files with 44 additions and 3 deletions
|
@ -8,5 +8,42 @@
|
||||||
.globl _plt_trampoline
|
.globl _plt_trampoline
|
||||||
.hidden _plt_trampoline
|
.hidden _plt_trampoline
|
||||||
.type _plt_trampoline,@function
|
.type _plt_trampoline,@function
|
||||||
_plt_trampoline:
|
_plt_trampoline: # (object, relocation_index)
|
||||||
int3
|
# save flags/registers (https://stackoverflow.com/questions/18024672/what-registers-are-preserved-through-a-linux-x86-64-function-call)
|
||||||
|
pushfq
|
||||||
|
pushq %rax
|
||||||
|
pushq %rcx
|
||||||
|
pushq %rdx
|
||||||
|
pushq %rsi
|
||||||
|
pushq %rdi
|
||||||
|
pushq %r8
|
||||||
|
pushq %r9
|
||||||
|
pushq %r10
|
||||||
|
pushq %r11
|
||||||
|
|
||||||
|
movq 80(%rsp), %rdi # object
|
||||||
|
movq 88(%rsp), %rsi # relocation_index
|
||||||
|
|
||||||
|
# offset = index * sizeof(Elf64_Rela)
|
||||||
|
shlq $3, %rsi
|
||||||
|
leaq (%rsi, %rsi, 2), %rsi
|
||||||
|
|
||||||
|
call _fixup_plt_entry@PLT
|
||||||
|
|
||||||
|
movq %rax, 88(%rsp) # replace object argument with symbol address
|
||||||
|
|
||||||
|
# restore flags/registers
|
||||||
|
popq %r11
|
||||||
|
popq %r10
|
||||||
|
popq %r9
|
||||||
|
popq %r8
|
||||||
|
popq %rdi
|
||||||
|
popq %rsi
|
||||||
|
popq %rdx
|
||||||
|
popq %rcx
|
||||||
|
popq %rax
|
||||||
|
popfq
|
||||||
|
|
||||||
|
addq $8, %rsp # remove relocation_index argument
|
||||||
|
|
||||||
|
retq
|
||||||
|
|
|
@ -506,7 +506,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
|
||||||
u8* relocation_address = relocation.address().as_ptr();
|
u8* relocation_address = relocation.address().as_ptr();
|
||||||
|
|
||||||
if (m_elf_image.is_dynamic())
|
if (m_elf_image.is_dynamic())
|
||||||
*(u32*)relocation_address += (FlatPtr)m_dynamic_object->base_address().as_ptr();
|
*(FlatPtr*)relocation_address += (FlatPtr)m_dynamic_object->base_address().as_ptr();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,7 +449,11 @@ NonnullRefPtr<DynamicObject> DynamicObject::create(const String& filename, Virtu
|
||||||
VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
|
VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
|
||||||
{
|
{
|
||||||
auto relocation = plt_relocation_section().relocation_at_offset(relocation_offset);
|
auto relocation = plt_relocation_section().relocation_at_offset(relocation_offset);
|
||||||
|
#if ARCH(I386)
|
||||||
VERIFY(relocation.type() == R_386_JMP_SLOT);
|
VERIFY(relocation.type() == R_386_JMP_SLOT);
|
||||||
|
#else
|
||||||
|
VERIFY(relocation.type() == R_X86_64_JUMP_SLOT);
|
||||||
|
#endif
|
||||||
auto symbol = relocation.symbol();
|
auto symbol = relocation.symbol();
|
||||||
u8* relocation_address = relocation.address().as_ptr();
|
u8* relocation_address = relocation.address().as_ptr();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue