Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

linux - Does ldd also show dependencies of dependencies?

I have a binary for which ldd shows an unexpected dependency und libicuuc (from "icu").

#ldd A
[...]
libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00007faaf9722000)
libicuuc.so.49 => /usr/lib64/libicuuc.so.49 (0x00007faaf5689000)

Since on this system libxml depends dynamically on libicuuc, it makes sense that ldd enventually ends up finding it, but is it expected that libicuuc also appears in the ldd output for A? Is there some command to retrieve only the libraries that are linked in as dependencies of dependencies?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ldd shows all libraries that it would need to load when starting the application or loading a shared library.

readelf -d shows only direct dependencies of the binary.

$ readelf -d /opt/google/chrome/chrome | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXrandr.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libXrender.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXss.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libgobject-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgthread-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libglib-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgtk-x11-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgdk-x11-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libatk-1.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgdk_pixbuf-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libpangocairo-1.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libcairo.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libpango-1.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libfreetype.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libfontconfig.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libnss3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libnssutil3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libsmime3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libplc4.so]
 0x0000000000000001 (NEEDED)             Shared library: [libnspr4.so]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgconf-2.so.4]
 0x0000000000000001 (NEEDED)             Shared library: [libdbus-1.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libXcomposite.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libasound.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libXfixes.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libcups.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libgcrypt.so.11]
 0x0000000000000001 (NEEDED)             Shared library: [libbz2.so.1.0]
 0x0000000000000001 (NEEDED)             Shared library: [libexpat.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libudev.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

$ ldd /opt/google/chrome/chrome
    linux-vdso.so.1 =>  (0x00007fff9d3ff000)
    libX11.so.6 => /lib64/libX11.so.6 (0x00007f93186dc000)
    libXrandr.so.2 => /lib64/libXrandr.so.2 (0x00007f93184d3000)
    libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f93182c9000)
    libXss.so.1 => /lib64/libXss.so.1 (0x00007f93180c5000)
    libXext.so.6 => /lib64/libXext.so.6 (0x00007f9317eb2000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f9317caa000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f9317aa6000)
    libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f9317858000)
    libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f9317656000)
    libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f9317336000)
    libgtk-x11-2.0.so.0 => /lib64/libgtk-x11-2.0.so.0 (0x00007f9316cbf000)
    libgdk-x11-2.0.so.0 => /lib64/libgdk-x11-2.0.so.0 (0x00007f9316a00000)
    libatk-1.0.so.0 => /lib64/libatk-1.0.so.0 (0x00007f93167de000)
    libgdk_pixbuf-2.0.so.0 => /lib64/libgdk_pixbuf-2.0.so.0 (0x00007f93165bb000)
    libpangocairo-1.0.so.0 => /lib64/libpangocairo-1.0.so.0 (0x00007f93163ae000)
    libcairo.so.2 => /lib64/libcairo.so.2 (0x00007f9316103000)
    libpango-1.0.so.0 => /lib64/libpango-1.0.so.0 (0x00007f9315eb7000)
    libfreetype.so.6 => /usr/lib64/freetype-freeworld/libfreetype.so.6 (0x00007f9315c15000)
    libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f93159e0000)
    libnss3.so => /lib64/libnss3.so (0x00007f93156a4000)
    libnssutil3.so => /lib64/libnssutil3.so (0x00007f9315479000)
    libsmime3.so => /lib64/libsmime3.so (0x00007f931524c000)
    libplc4.so => /lib64/libplc4.so (0x00007f9315046000)
    libnspr4.so => /lib64/libnspr4.so (0x00007f9314e09000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9314bed000)
    libgconf-2.so.4 => /lib64/libgconf-2.so.4 (0x00007f93149bc000)
    libdbus-1.so.3 => /lib64/libdbus-1.so.3 (0x00007f9314778000)
    libXcomposite.so.1 => /lib64/libXcomposite.so.1 (0x00007f9314575000)
    libasound.so.2 => /lib64/libasound.so.2 (0x00007f9314294000)
    libXfixes.so.3 => /lib64/libXfixes.so.3 (0x00007f931408e000)
    libcups.so.2 => /lib64/libcups.so.2 (0x00007f9313e33000)
    libgcrypt.so.11 => /lib64/libgcrypt.so.11 (0x00007f9313bba000)
    libbz2.so.1.0 => not found
    libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f9313991000)
    libudev.so.0 => /lib64/libudev.so.0 (0x00007f9313782000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f931347f000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f9313184000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9312f6e000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f9312bb7000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003c7a000000)
    libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f9312999000)
    libffi.so.5 => /lib64/libffi.so.5 (0x00007f9312790000)
    libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f931258c000)
    libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x00007f931223f000)
    libpangoft2-1.0.so.0 => /lib64/libpangoft2-1.0.so.0 (0x00007f9312012000)
    libXinerama.so.1 => /lib64/libXinerama.so.1 (0x00007f9311e0f000)
    libXi.so.6 => /lib64/libXi.so.6 (0x00007f9311c00000)
    libXcursor.so.1 => /lib64/libXcursor.so.1 (0x00007f93119f4000)
    libXdamage.so.1 => /lib64/libXdamage.so.1 (0x00007f93117f1000)
    libpng15.so.15 => /lib64/libpng15.so.15 (0x00007f93115c7000)
    libpixman-1.so.0 => /lib64/libpixman-1.so.0 (0x00007f9311340000)
    libz.so.1 => /lib64/libz.so.1 (0x00007f9311129000)
    libplds4.so => /lib64/libplds4.so (0x00007f9310f24000)
    libdbus-glib-1.so.2 => /lib64/libdbus-glib-1.so.2 (0x00007f9310cfd000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f9310ab8000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f93107d3000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f93105a8000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f93103a3000)
    libgnutls.so.26 => /lib64/libgnutls.so.26 (0x00007f93100eb000)
    libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007f930fee7000)
    libavahi-common.so.3 => /lib64/libavahi-common.so.3 (0x00007f930fcd9000)
    libavahi-client.so.3 => /lib64/libavahi-client.so.3 (0x00007f930fac8000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f930f891000)
    libXau.so.6 => /lib64/libXau.so.6 (0x00007f930f68c000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f930f46b000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f930f251000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f930f046000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f930ee42000)
    libtasn1.so.3 => /lib64/libtasn1.so.3 (0x00007f930ec31000)
    libp11-kit.so.0 => /lib64/libp11-kit.so.0 (0x00007f930ea1e000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007f930e7b3000)

Is there some command to retrieve only the libraries that are linked in as dependencies of dependencies?

You can do set difference of ldd and readelf -d outputs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...