DynamicLoader: Fix R_386_PC32 relocation

I was not accounting elf base with offset
This commit is contained in:
2026-04-04 22:31:00 +03:00
parent c7690053ae
commit 8c5fa1c0b8

View File

@@ -455,15 +455,15 @@ static void handle_tls_relocation(const LoadedElf& elf, const RelocT& reloc)
#elif defined(__i686__) #elif defined(__i686__)
switch (ELF32_R_TYPE(reloc.r_info)) switch (ELF32_R_TYPE(reloc.r_info))
{ {
case R_386_TLS_TPOFF:
*reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_offset - symbol_elf->tls_offset;
break;
case R_386_TLS_DTPMOD32: case R_386_TLS_DTPMOD32:
*reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_elf->tls_module; *reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_elf->tls_module;
break; break;
case R_386_TLS_DTPOFF32: case R_386_TLS_DTPOFF32:
*reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_offset; *reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_offset;
break; break;
case R_386_TLS_TPOFF:
*reinterpret_cast<uint32_t*>(elf.base + reloc.r_offset) = symbol_offset - symbol_elf->tls_offset;
break;
default: default:
print(STDERR_FILENO, "unsupported tls reloc type "); print(STDERR_FILENO, "unsupported tls reloc type ");
print_uint(STDERR_FILENO, ELF32_R_TYPE(reloc.r_info)); print_uint(STDERR_FILENO, ELF32_R_TYPE(reloc.r_info));
@@ -589,7 +589,7 @@ static uintptr_t handle_relocation(const LoadedElf& elf, const RelocT& reloc, bo
break; break;
case R_386_PC32: case R_386_PC32:
size = 4; size = 4;
value = symbol_address - reloc.r_offset; value = symbol_address - (elf.base + reloc.r_offset);
add_addend = true; add_addend = true;
break; break;
case R_386_GLOB_DAT: case R_386_GLOB_DAT: