This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A question about dynamic linking


On Wed, 2006-03-15 at 14:57 -0500, Daniel Jacobowitz wrote:
> On Wed, Mar 15, 2006 at 08:40:14PM +0100, Albert Miranda wrote:
> > I'm working on a project related with the dynamic linker and I need to
> > know which libraries have been loaded and where (in which base
> > addresses) from the same program that needs them to avoid mmapping a
> > library that's already been loaded.
> > 
> > Exploring through ld.so.1 code I've seen there's a list of link_map
> > structures that contains the information I need and is maintained
> > during the life of the loaded program (I assume this is done to
> > provide lazy binding), but when trying to access it through
> > dl_rtld_map I'm (logically) unable to do it (gcc doesn't complain but
> > ld.so.1 can't resolve the symbol).
> > 
> > Is there any way to do this?
> 
> Yes.  Instead of looking for the rtld map directly, go through
> _DYNAMIC; find the DT_DEBUG tag, which will point to a structure
> of type "struct r_debug".  And that'll point to the link map chain.

I do something like this:

    55 struct r_debug *
    56 utils_get_ld_debug(void)
    57 {
    58         ElfW(Dyn) *dyn;
    59         for (dyn = _DYNAMIC; dyn->d_tag != DT_NULL; dyn++) {
    60                 if (dyn->d_tag == DT_DEBUG) {
    61                         struct r_debug *r_debug;
    62                         r_debug = (struct r_debug *) dyn->d_un.d_ptr;
    63                         return r_debug;
    64                 }
    65         }
    66         return NULL;
    67 }

hope this helps,
Mathieu
-- 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]