diff --git a/lib/libpmcstat/libpmcstat_image.c b/lib/libpmcstat/libpmcstat_image.c --- a/lib/libpmcstat/libpmcstat_image.c +++ b/lib/libpmcstat/libpmcstat_image.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -295,6 +296,7 @@ size_t i, nph, nsh; const char *path, *elfbase; char *p, *endp; + bool first_exec_segment; uintfptr_t minva, maxva; Elf *e; Elf_Scn *scn; @@ -384,7 +386,7 @@ * loaded. Additionally, for dynamically linked executables, * save the pathname to the runtime linker. */ - if (eh.e_type == ET_EXEC) { + if (eh.e_type != ET_REL) { if (elf_getphnum(e, &nph) == 0) { warnx( "WARNING: Could not determine the number of program headers in \"%s\": %s.", @@ -392,6 +394,7 @@ elf_errmsg(-1)); goto done; } + first_exec_segment = true; for (i = 0; i < eh.e_phnum; i++) { if (gelf_getphdr(e, i, &ph) != &ph) { warnx( @@ -416,8 +419,10 @@ break; case PT_LOAD: if ((ph.p_flags & PF_X) != 0 && - (ph.p_offset & (-ph.p_align)) == 0) + first_exec_segment) { image->pi_vaddr = ph.p_vaddr & (-ph.p_align); + first_exec_segment = false; + } break; } }