How to get list of shared libraries and their load address

Ever wondered how to get the list of shared libraries (DSO) in a running program and their load address?
This is how you can get it:

#include <link.h>
#include <execinfo.h>
#include <stdio.h>

int main(int argc, char **argv)
    struct link_map* l_ptr;

    for(l_ptr = _r_debug.r_map; l_ptr; l_ptr = l_ptr->l_next)
        printf("%s loaded at %ld\n", l_ptr->l_name,l_ptr->l_addr);

Leave a Comment