Skip to content

Instantly share code, notes, and snippets.

@kinichiro
Last active August 29, 2015 14:05
Show Gist options
  • Save kinichiro/66191f27963c9efe25d0 to your computer and use it in GitHub Desktop.
Save kinichiro/66191f27963c9efe25d0 to your computer and use it in GitHub Desktop.
sample code for dl_iterate_phdr()
/* test_dl_iterate_phdr.c */
#define _GNU_SOURCE
#include <stdio.h>
#include <link.h>
static int
test_phdr(struct dl_phdr_info *i, size_t size, void *data) {
printf("0x%8.8x %-30.30s 0x%8.8x %d %d %d %d 0x%8.8x\n",
i->dlpi_addr, i->dlpi_name, i->dlpi_phdr, i->dlpi_phnum,
i->dlpi_adds, i->dlpi_subs, i->dlpi_tls_modid,
i->dlpi_tls_data
);
return 0;
}
int main() {
dl_iterate_phdr(test_phdr, NULL);
}
0x00000000 0x00400040 8 4 0 0 0x00000000
0x16aff000 0x161ff040 4 4 0 0 0x00000000
0x00000000 /lib64/libc.so.6 0x9a000040 10 4 0 1 0xc7343698
0x00000000 /lib64/ld-linux-x86-64.so.2 0x99800040 7 4 0 0 0x00000000
# gcc test_dl_iterate_phdr.c
test_dl_iterate_phdr.c:3:18: fatal error: link.h: No such file or directory
compilation terminated.
https://www.gnu.org/software/gnulib/manual/html_node/dl_005fiterate_005fphdr.html
says,
Portability problems not fixed by Gnulib:
This function is missing on some platforms: Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment