libdrgn: x86-64: support R_X86_64_PC32 relocation type

This is used for .orc_unwind_ip for kernel modules.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2021-03-26 10:28:10 -07:00
parent e0aaaf203d
commit 090064f20d
3 changed files with 11 additions and 0 deletions

View File

@ -298,6 +298,15 @@ invalid_offset:
memcpy(dst, &value, sizeof(value)); memcpy(dst, &value, sizeof(value));
break; break;
} }
case R_X86_64_PC32: {
uint32_t value = sym_value + r_addend - (relocating->addr + r_offset);
if (dst_size < sizeof(value))
goto invalid_offset;
if (relocating->bswap)
value = bswap_32(value);
memcpy(dst, &value, sizeof(value));
break;
}
case R_X86_64_32: { case R_X86_64_32: {
uint32_t value = sym_value + r_addend; uint32_t value = sym_value + r_addend;
if (dst_size < sizeof(value)) if (dst_size < sizeof(value))

View File

@ -682,6 +682,7 @@ static struct drgn_error *relocate_elf_section(Elf_Scn *scn, Elf_Scn *reloc_scn,
struct drgn_relocating_section relocating = { struct drgn_relocating_section relocating = {
.buf = data->d_buf, .buf = data->d_buf,
.buf_size = data->d_size, .buf_size = data->d_size,
.addr = sh_addrs[elf_ndxscn(scn)],
.bswap = bswap, .bswap = bswap,
}; };

View File

@ -28,6 +28,7 @@ struct drgn_register_layout {
struct drgn_relocating_section { struct drgn_relocating_section {
char *buf; char *buf;
size_t buf_size; size_t buf_size;
uint64_t addr;
bool bswap; bool bswap;
}; };