diff --git a/libc/malloc_debug/MapData.cpp b/libc/malloc_debug/MapData.cpp index e8fbc5401..ded81a2d5 100644 --- a/libc/malloc_debug/MapData.cpp +++ b/libc/malloc_debug/MapData.cpp @@ -116,14 +116,17 @@ static void read_loadbias(MapEntry* entry) { if (!get_val(entry, addr + offsetof(ElfW(Phdr), p_type), &phdr.p_type)) { return; } + if (!get_val(entry, addr + offsetof(ElfW(Phdr), p_flags), &phdr.p_flags)) { + return; + } if (!get_val(entry, addr + offsetof(ElfW(Phdr), p_offset), &phdr.p_offset)) { return; } - if (phdr.p_type == PT_LOAD && phdr.p_offset == entry->offset) { + if ((phdr.p_type == PT_LOAD) && (phdr.p_flags & PF_X) ) { if (!get_val(entry, addr + offsetof(ElfW(Phdr), p_vaddr), &phdr.p_vaddr)) { return; } - entry->load_bias = phdr.p_vaddr; + entry->load_bias = phdr.p_vaddr - phdr.p_offset; return; } addr += sizeof(phdr);