How can I discover which shared libraries a process is using?

How can I discover which shared libraries a process is using?

Post by Jon Howel » Fri, 09 Jan 1998 04:00:00



When I run /usr/proc/bin/pmap, it is able to track down the list of
shared libraries that are mapped into memory by name, stat() them all,
and use that to turn the devno/inode pairs returned by the proc filesystem
ioctl()s into pathnames. I can watch it do this by simply 'truss'ing
pmap.

I want to do the same thing (discover the names of all shlibs
[potentially] in use), but I can't figure out what library calls to make,
or where the data structures that hold this info are documented.
I've read the man pages on 'elf,' but (a) they don't say what
various sections might contain, and (b) even if they did, they wouldn't
list a transitive closure of all libraries in use, which I think pmap
is able to recover by grubbing around in the maps maintained by the
dl*() functions.

Thanks for any tips.

        --Jon

                                       Jon Howell  170AE827

                http://www.cs.dartmouth.edu/~jonh  9C2E3DB3

 
 
 

How can I discover which shared libraries a process is using?

Post by Jon Howel » Sat, 10 Jan 1998 04:00:00


Quote:> Why not just running "ldd" on the binary?

I guess that is roughly what I want; I'd like to do this from within
a program (I'd like to know how ldd does it, basically). But I guess
for now, I could popen an ldd process... Thanks for pointing that out.

        --Jon

Quote:> >When I run /usr/proc/bin/pmap, it is able to track down the list of
> >shared libraries that are mapped into memory by name, stat() them all,
> >and use that to turn the devno/inode pairs returned by the proc filesystem
> >ioctl()s into pathnames. I can watch it do this by simply 'truss'ing
> >pmap.

> >I want to do the same thing (discover the names of all shlibs
> >[potentially] in use), but I can't figure out what library calls to make,
> >or where the data structures that hold this info are documented.
> >I've read the man pages on 'elf,' but (a) they don't say what
> >various sections might contain, and (b) even if they did, they wouldn't
> >list a transitive closure of all libraries in use, which I think pmap
> >is able to recover by grubbing around in the maps maintained by the
> >dl*() functions.

                                       Jon Howell  170AE827

                http://www.cs.dartmouth.edu/~jonh  9C2E3DB3


 
 
 

How can I discover which shared libraries a process is using?

Post by Barry Margoli » Sat, 10 Jan 1998 04:00:00




Quote:>> Why not just running "ldd" on the binary?

>I guess that is roughly what I want; I'd like to do this from within
>a program (I'd like to know how ldd does it, basically). But I guess
>for now, I could popen an ldd process... Thanks for pointing that out.

I think ldd does it by setting an environment variable that ld.so looks at
and then executing the program.  When this environment variable is set,
ld.so just prints out what it would have loaded and exits, rather than
actually loading them and continuing.

--

GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.

 
 
 

How can I discover which shared libraries a process is using?

Post by Michael R. Barb » Sat, 10 Jan 1998 04:00:00



: >> Why not just running "ldd" on the binary?
: >
: >I guess that is roughly what I want; I'd like to do this from within
: >a program (I'd like to know how ldd does it, basically). But I guess
: >for now, I could popen an ldd process... Thanks for pointing that out.
:
: I think ldd does it by setting an environment variable that ld.so looks at
: and then executing the program.  When this environment variable is set,
: ld.so just prints out what it would have loaded and exits, rather than
: actually loading them and continuing.
:
: --

This is correct.  When a trace variable is let, the linker just shows
you what shared libraries are used.

For an example of how this works (under Solaris 2.6):

scully:~% /usr/bin/sleep
usage: sleep time
scully:~% setenv LD_TRACE_LOADED_OBJECTS=1
scully:~% /usr/bin/sleep
        libc.so.1 =>     /usr/lib/libc.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
scully:~%

If you want a verbose listing, also setenv LD_VERBOSE=1

scully:~% setenv LD_VERBOSE=1
scully:~% /usr/bin/sleep

   find library=libc.so.1; required by /usr/bin/sleep
        libc.so.1 =>     /usr/lib/libc.so.1
   find version=libc.so.1
        libc.so.1 (SUNW_1.1) =>  /usr/lib/libc.so.1

   find library=libdl.so.1; required by /usr/lib/libc.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
   find version=libdl.so.1
        libdl.so.1 (SUNW_0.7) =>         /usr/lib/libdl.so.1
        libdl.so.1 (SUNWprivate_1.1) =>  /usr/lib/libdl.so.1
        libdl.so.1 (SISCD_2.3) =>        /usr/lib/libdl.so.1
scully:~%

If you want to see searchpath information, setenv LD_TRACE_SEARCH_PATHS=1.

Enjoy...

-Michael
-----------------------------------------------------------------------------

Sr. Systems Programmer/Analyst   Distributed Computing Services, MTU
Home:  (906) 482-8412            Work:  (906) 487-2112

 
 
 

How can I discover which shared libraries a process is using?

Post by Bart Smaalder » Tue, 13 Jan 1998 04:00:00


In Solaris 2.6 you can use the link auditing facilities to do what you
want... see


for details...

- Bart




> >> Why not just running "ldd" on the binary?

> >I guess that is roughly what I want; I'd like to do this from within
> >a program (I'd like to know how ldd does it, basically). But I guess
> >for now, I could popen an ldd process... Thanks for pointing that out.

> I think ldd does it by setting an environment variable that ld.so looks at
> and then executing the program.  When this environment variable is set,
> ld.so just prints out what it would have loaded and exits, rather than
> actually loading them and continuing.

> --

> GTE Internetworking, Powered by BBN, Cambridge, MA
> Support the anti-spam movement; see <http://www.cauce.org/>
> Please don't send technical questions directly to me, post them to newsgroups.

--
Bart Smaalders                  Solaris Clustering      SunSoft

http://playground.sun.com/~barts                   901 San Antonio Road
                                                        Palo Alto, CA
94303
 
 
 

How can I discover which shared libraries a process is using?

Post by Marc Duponche » Sun, 18 Jan 1998 04:00:00




> In Solaris 2.6 you can use the link auditing facilities to do what you
> want... see


> for details...

> - Bart

/usr/proc/bin/pldd also shows it:

     pldd                List the dynamic libraries  linked  into
                         each  process,  including shared objects
                         explicitly  attached  using  dlopen(3X).
                         See also ldd(1).

there are a lot of nifty programs in /usr/proc/bin. It's in my $PATH ;-)

--
  Marc Duponcheel