linux
使用 ldd
查看程序依赖的动态库
$ ldd /usr/bin/bash
linux-vdso.so.1 (0x00007ffdd2749000)
libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fcecb9b6100)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcecb9b0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcecb7c5000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcecbb21000)
verbose
模式
$ ldd --verbose /usr/bin/bash
linux-vdso.so.1 (0x00007ffce299c000)
libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f6fb24dd000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6fb24d6100)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6fb22ec000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6fb2648000)
Version information:
/usr/bin/bash:
libdl.so.2 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libdl.so.2
libtinfo.so.6 (NCURSES6_TINFO_5.0.19991023) => /lib/x86_64-linux-gnu/libtinfo.so.6
libc.so.6 (GLIBC_2.11) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.8) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.15) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libtinfo.so.6:
libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.16) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libdl.so.2:
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
/lib/x86_64-linux-gnu/libc.so.6:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
Find dynamic library required by program using readelf
.
$ readelf --dynamic /usr/bin/bash | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libtinfo.so.6]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
$ readelf -d a.out | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
read library requirement of running processes from /proc//maps.
$ awk '/.so/{print $6}' /proc/$(pgrep bash | head -n1)/maps | sort -u
/usr/lib/x86_64-linux-gnu/ld-2.29.so
/usr/lib/x86_64-linux-gnu/libc-2.29.so
/usr/lib/x86_64-linux-gnu/libdl-2.29.so
/usr/lib/x86_64-linux-gnu/libnss_files-2.29.so
/usr/lib/x86_64-linux-gnu/libtinfo.so.6.1
View shared library requirement of a running process using lsof
$ lsof -p $(pgrep bash | head -n1) | grep mem
bash 4470 user mem REG 8,1 51672 404577 /usr/lib/x86_64-linux-gnu/libnss_files-2.29.so
bash 4470 user mem REG 8,1 14529344 401393 /usr/lib/locale/locale-archive
bash 4470 user mem REG 8,1 2000480 403822 /usr/lib/x86_64-linux-gnu/libc-2.29.so
bash 4470 user mem REG 8,1 18656 403961 /usr/lib/x86_64-linux-gnu/libdl-2.29.so
bash 4470 user mem REG 8,1 183528 404929 /usr/lib/x86_64-linux-gnu/libtinfo.so.6.1
bash 4470 user mem REG 8,1 26402 789841 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
bash 4470 user mem REG 8,1 179032 403610 /usr/lib/x86_64-linux-gnu/ld-2.29.so
pgrep bash | head -n1
gets the ID of the first process named bash
Use pmap
to gather shared library requirement of a program.
$ pmap $(pgrep bash | head -n1) | grep .so | awk '{ print $4 }' | sort -u
ld-2.29.so
libc-2.29.so
libdl-2.29.so
libnss_files-2.29.so
libtinfo.so.6.1
windows
开源工具Dependencies
https://github.com/lucasg/Dependencies/releases
vs工具
dumpbin
from Visual Studio tools (VCin folder) can help here:
dumpbin /dependents your_dll_file.dll
https://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency
https://www.simplified.guide/linux/show-shared-library-dependency