On Sat, Jun 11, 2016 at 3:12 PM, Carlo Kok <ck@remobjects.com> wrote:
On some (ubuntu 14.04.4, libc 2.19-0ubuntu6.9) systems I'm getting a sigsegv
when casting the link_map's l_addr to Elf64_Ehdr. This is something libgc
does and works fine on most linux systems, but not all.
This isn't guaranteed to work *at all*.
The l_addr is a *relocation*, or a delta between first PT_LOAD
.p_vaddr and the actual load address.
For non-PIE ET_EXEC, this delta is always 0. For non-prelinked ET_DYN
(which are normally linked with first PT_LOAD .p_vaddr == 0) it's the
actual load address (this is why it works most of the time).
But for any prelinked ET_DYN binary with first PT_LOAD .p_vaddr != 0,
this will crash and burn. See also "man prelink".
What am I missing here, and if this isn't guaranteed to work, how else can I
get all the loaded data segments.
Use dl_iterate_phdr().
Cheers,