Linux可执二进制行文件和库依赖查看方法

Linux可执二进制行文件和库依赖查看方法,第1张

1、查看依赖

1.1、查看可执行文件依赖的库有哪些

举例,查看常用的ls工具,依赖哪些库:

1.2、查看动态库,依赖的库有哪些

举例,查看libcap依赖的库有哪些:

一、可执行文件/二进制文件依赖共享

ldd命令用来查看可执行文件依赖的共享库文件。

$ ldd --help

Usage: ldd [OPTION]... FILE...

--help print this help and exit

--version print version information and exit

-d, --data-relocs process data relocations

-r, --function-relocs process data and function relocations

-u, --unused print unused direct dependencies

-v, --verbose print all information

示例:

$ ldd helloworld

二、共享库依赖共享库关系

上面的ldd命令无法查看共享库的依赖关系,因为共享库本身并不是可执行文件,我们可以使用

objdump -x libhelloworld.so | grep NEEDED

其中,libhelloworld.so是你的库名称。

附:

readelf命令用于读取ELF Header信息

创建静态库:

ar -rcs test.a *.o

查看静态库:

ar -tv test.a

解压静态库:

ar -x test.a

查看程序依赖的动态库:

readelf -a xxx|grep library

如:可以看到,下面的交叉程序hello执行依赖于如下两个动态库。

rebi@ubuntu:~/test$ arm-none-linux-gnueabi-readelf -a hello|grep "library"

0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]

0x00000001 (NEEDED) Shared library: [libc.so.6]

rebi@ubuntu:~/test$

或者:readelf -l hello 即可。

nm xxx 查看符号

其中,T表示代码段,U表示在其它地方定义,所以需要确保必须在某个.o或库里被定义过。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/9023665.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-24
下一篇 2023-04-24

发表评论

登录后才能评论

评论列表(0条)

保存