Skip to content

Instantly share code, notes, and snippets.

@alanc
Created February 1, 2019 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanc/2f8c8170f8976b9fbf6b04676b765cd4 to your computer and use it in GitHub Desktop.
Save alanc/2f8c8170f8976b9fbf6b04676b765cd4 to your computer and use it in GitHub Desktop.
How to tell which library a function is from
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
void *sym;
Dl_info_t dlip;
sym = dlsym(RTLD_PROBE, "malloc");
if (sym == NULL) {
perror("dlsym failed");
exit(1);
}
if (dladdr(sym, &dlip) == 0) {
perror("dladdr failed");
exit(1);
}
printf("malloc: 0x%x in %s\n", sym, dlip.dli_fname);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment