I'd like to know which libraries are used by executables on my system. More specifically, I'd like to rank which libraries are used the most, along with the binaries that use them. How can I do this?
You will probably not be able to get an exact number if the executables use dlopen.
This is a great answer (I've up-voted it) but can you explain the "grep -P '\t.*so'" command? According to man, this interprets the pattern as a perl regexp, but my version of grep doesn't support it (man indicates this is a general issue). What bit of the regexp is perl-specific?
I think you may need to use ldd -v
Be aware that ldd actually runs the executable with a special environment variable, and the Linux dynamic linker recognizes this flag and just outputs the libraries rather than running the executable. Look at the source to ldd; on my system, it's a bash script. If the executable is statically linked and uses syscalls, and specifies a different loader, it can do arbitrary evil things. So don't use ldd on an executable you don't trust.
'ldd' doesn't work for me on cross-compiled binaries. The question is about finding the libraries used by programs on the current system (that would be native programs, as phrased). This is a good answer for that. However, I thought I'd mention that you need to use something else if looking for the shared libs for programs for a different system ('readelf' mentioned in another answer, worked for me)
This is GOLD ..
This should be safe too, unlike ldd which shouldn't be used on untrusted executables.
Also, obbjdump -p shows additional information like the RPATH, which may be of help when investigating dynamic linking issues with your executable.
+1 for the method that is actually safe and reliable (I've somehow got a system where musl-gcc regularly produces binaries such that calling ldd on the binary just executes the binary, so nowadays I am regularly reminded of just how unsafe ldd is).
Used this to find out if mariadb was actually using tc-malloc, which gets loaded by LD_PRELOAD. Works great.
I was looking for something that would show me '.so' for a given pid. This is exactly what I needed. Thanks!