Skip to content
Snippets Groups Projects
Commit c8eda379 authored by Avi Kivity's avatar Avi Kivity
Browse files

elf: lazy relocate the PLT GOT

Instead of looking up the actual symbols, adjust the existing entry to point
back at the PLT.  This will later case the stub at the first three entries
of the PLT to get called with the symbol index on the stack, for run-time
resolution.
parent ca8dc796
No related branches found
No related tags found
No related merge requests found
......@@ -348,12 +348,31 @@ namespace elf {
}
}
void elf_object::relocate_pltgot()
{
auto rel = dynamic_ptr<Elf64_Rela>(DT_JMPREL);
auto nrel = dynamic_val(DT_PLTRELSZ) / sizeof(*rel);
for (auto p = rel; p < rel + nrel; ++p) {
auto info = p->r_info;
u32 sym = info >> 32;
u32 type = info & 0xffffffff;
assert(type = R_X86_64_JUMP_SLOT);
void *addr = _base + p->r_offset;
// The JUMP_SLOT entry already points back to the PLT, just
// make sure it is relocated relative to the object base.
*static_cast<u64*>(addr) += reinterpret_cast<u64>(_base);
}
}
void elf_object::relocate()
{
assert(!dynamic_exists(DT_REL));
if (dynamic_exists(DT_RELA)) {
relocate_rela();
}
if (dynamic_exists(DT_JMPREL)) {
relocate_pltgot();
}
}
unsigned long
......
......@@ -272,6 +272,7 @@ namespace elf {
symbol_module symbol(unsigned idx);
Elf64_Xword symbol_tls_module(unsigned idx);
void relocate_rela();
void relocate_pltgot();
protected:
program& _prog;
Elf64_Ehdr _ehdr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment