DynamicLoader: Cleanup lazy PLT relocations
This commit is contained in:
@@ -700,50 +700,16 @@ static void relocate_elf(LoadedElf& elf, bool lazy_load)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const size_t pltrelent = (elf.pltrel == DT_REL)
|
switch (elf.pltrel)
|
||||||
? sizeof(ElfNativeRelocation)
|
|
||||||
: sizeof(ElfNativeRelocationA);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < elf.pltrelsz / pltrelent; i++)
|
|
||||||
{
|
{
|
||||||
const auto info = (elf.pltrel == DT_REL)
|
case DT_REL:
|
||||||
? reinterpret_cast<ElfNativeRelocation*>(elf.jmprel)[i].r_info
|
for (size_t i = 0; i < elf.pltrelsz / sizeof(ElfNativeRelocation); i++)
|
||||||
: reinterpret_cast<ElfNativeRelocationA*>(elf.jmprel)[i].r_info;
|
*reinterpret_cast<uintptr_t*>(elf.base + reinterpret_cast<ElfNativeRelocation*>(elf.jmprel)[i].r_offset) += elf.base;
|
||||||
const auto offset = (elf.pltrel == DT_REL)
|
break;
|
||||||
? reinterpret_cast<ElfNativeRelocation*>(elf.jmprel)[i].r_offset
|
case DT_RELA:
|
||||||
: reinterpret_cast<ElfNativeRelocationA*>(elf.jmprel)[i].r_offset;
|
for (size_t i = 0; i < elf.pltrelsz / sizeof(ElfNativeRelocationA); i++)
|
||||||
|
*reinterpret_cast<uintptr_t*>(elf.base + reinterpret_cast<ElfNativeRelocationA*>(elf.jmprel)[i].r_offset) += elf.base;
|
||||||
#if defined(__x86_64__)
|
break;
|
||||||
if (ELF64_R_TYPE(info) != R_X86_64_JUMP_SLOT)
|
|
||||||
print_error_and_exit("jmprel relocation not R_X86_64_JUMP_SLOT", 0);
|
|
||||||
#elif defined(__i686__)
|
|
||||||
if (ELF32_R_TYPE(info) != R_386_JMP_SLOT)
|
|
||||||
print_error_and_exit("jmprel relocation not R_386_JMP_SLOT", 0);
|
|
||||||
#else
|
|
||||||
#error "unsupported architecture"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool do_relocation = false;
|
|
||||||
|
|
||||||
if (const uint32_t symbol_index = ELF_R_SYM(info))
|
|
||||||
{
|
|
||||||
const auto& symbol = *reinterpret_cast<ElfNativeSymbol*>(elf.symtab + symbol_index * elf.syment);
|
|
||||||
const char* symbol_name = reinterpret_cast<const char*>(elf.strtab + symbol.st_name);
|
|
||||||
if (strcmp(symbol_name, "__tls_get_addr") == 0 || strcmp(symbol_name, "___tls_get_addr") == 0)
|
|
||||||
do_relocation = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!do_relocation)
|
|
||||||
*reinterpret_cast<uintptr_t*>(elf.base + offset) += elf.base;
|
|
||||||
else switch (elf.pltrel)
|
|
||||||
{
|
|
||||||
case DT_REL:
|
|
||||||
handle_relocation(elf, reinterpret_cast<ElfNativeRelocation*>(elf.jmprel)[i], true);
|
|
||||||
break;
|
|
||||||
case DT_RELA:
|
|
||||||
handle_relocation(elf, reinterpret_cast<ElfNativeRelocationA*>(elf.jmprel)[i], true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user