[oclug] library dependancy

David F. Skoll dfs at roaringpenguin.com
Wed Jun 18 08:43:39 EDT 2003


Michael P. Soulier <msoulier at digitaltorque.ca> [030617 22:12]:

> >     Just don't run ldd on an unknown binary. It actually executes the
> > code.

No.  It executes /lib/ld-linux.so.2 with some special flags to obtain
the shared library names.  Although you will see an execve call to
the program, the program's main() function is never called -- the C
library startup code sees the special flag and just emits the library
dependencies rather than executing the code.

Example:

$ strace -f -eexecve ldd /bin/ls
execve("/usr/bin/ldd", ["ldd", "/bin/ls"], [/* 38 vars */]) = 0
[pid 14415] execve("/lib/ld-linux.so.2", ["/lib/ld-linux.so.2", "--verify", "/bin/ls"], [/* 37 vars */]) = 0
--- SIGCHLD (Child exited) ---
[pid 14416] execve("/bin/ls", ["/bin/ls"], [/* 42 vars */]) = 0
        libtermcap.so.2 => /lib/libtermcap.so.2 (0x40033000)
        libc.so.6 => /lib/libc.so.6 (0x40038000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
--- SIGCHLD (Child exited) ---

Although you see  execve("/bin/ls" ...), the only output is the list
of shared libraries.  ls's main function doesn't actually run.

--
David.



More information about the OCLUG mailing list