From b1285f83945d2d525cdc41d6ccdd6dba383e3872 Mon Sep 17 00:00:00 2001 From: Peilin Ye Date: Thu, 6 Jan 2022 18:00:30 -0800 Subject: [PATCH] libdrgn: Always fall back to libdwfl ELF relocation Simply doing "drgn" segmentation-faults on my machine: (gdb) bt #0 apply_elf_rela_x86_64 (relocating=relocating@entry=0x7fc843650c90, r_offset=0, r_type=2, r_addend=0, sym_value=) at ../../libdrgn/arch_x86_64.c:498 #1 0x00007fc88cbd523b in relocate_elf_section (platform=0x7fc843650c80, shdrnum=59, sh_addrs=0x7fc808000b20, symtab_scn=, reloc_scn=0x17614c8, scn=) at ../../libdrgn/debug_info.c:761 #2 relocate_elf_file (elf=) at ../../libdrgn/debug_info.c:865 #3 drgn_debug_info_find_sections (module=) at ../../libdrgn/debug_info.c:883 #4 drgn_debug_info_read_module (load=load@entry=0x7ffea9d70870, dindex_state=0x7ffea9d70810, head=0x163c6b0) at ../../libdrgn/debug_info.c:970 #5 0x00007fc88cbd5474 in drgn_debug_info_update_index._omp_fn.1 () at ../../libdrgn/debug_info.c:1037 #6 0x00007fc88cb19769 in ?? () from /usr/lib/x86_64-linux-gnu/libgomp.so.1 #7 0x00007fc88cb21f00 in ?? () from /usr/lib/x86_64-linux-gnu/libgomp.so.1 #8 0x00007fc88cb1f7aa in ?? () from /usr/lib/x86_64-linux-gnu/libgomp.so.1 #9 0x00007fc88dfb7fa3 in start_thread (arg=) at pthread_create.c:486 #10 0x00007fc88dafe4cf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 Always returning NULL in libdrgn/debug_info.c:relocate_elf_file() fixes the issue. I don't know, maybe it's a bug in drgn's implementation of ELF relocation, but add this hack for now. Signed-off-by: Peilin Ye --- libdrgn/debug_info.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdrgn/debug_info.c b/libdrgn/debug_info.c index 60817d1a2..6307622f9 100644 --- a/libdrgn/debug_info.c +++ b/libdrgn/debug_info.c @@ -1615,6 +1615,7 @@ static struct drgn_error *relocate_elf_section(Elf_Scn *scn, Elf_Scn *reloc_scn, static struct drgn_error *relocate_elf_file(Elf *elf) { struct drgn_error *err; + bool hack = true; GElf_Ehdr ehdr_mem, *ehdr; ehdr = gelf_getehdr(elf, &ehdr_mem); @@ -1628,7 +1629,7 @@ static struct drgn_error *relocate_elf_file(Elf *elf) struct drgn_platform platform; drgn_platform_from_elf(ehdr, &platform); - if (!platform.arch->apply_elf_rela) { + if (!platform.arch->apply_elf_rela || hack) { /* Unsupported; fall back to libdwfl. */ return NULL; }