linux/gcc:C/C++ 内部的 ldd 功能程序
有没有一种简单有效的方法可以知道给定的动态链接的ELF
缺少运行所需的.so,所有这些都来自C/C++程序的内部 ?
我需要一个与 ldd 功能有些相似的程序,而不是尝试执行 ELF 来找出系统中的(满足/未满足)依赖项。也许通过某个库询问 ld-linux.so 实用程序? (我是linux这一部分的新手=)
注意:阅读
ldd
的源代码对我的意图没有多大帮助:看起来ldd
实际上是在分叉另一个进程并执行该程序。
如果在不执行程序的情况下无法知道程序是否具有未满足的依赖项,是否有某种方法至少可以在我的程序中快速列出该 ELF
所需的 .so?
预先感谢 =)
Is there a simple and efficient way to know that a given dynamically linked ELF
is missing a required .so for it to run, all from the inside of a C/C++ program?
I need a program with somewhat similar functionality as ldd
, without trying to execute the ELF
to find out the (met/unmet) dependencies in the system. Perhaps asking the ld-linux.so utility via some library? (I'm a newbie in this part of linux =)
NOTE: reading the source code of
ldd
was not very helpful for my intentions: it seems thatldd
is in fact forking another process and executing the program.
If it's not possible to know that a program has unmet dependencies without executing it, is there some way to, at least, quickly list the .so's required for that ELF
all from within my program?
Thanks in advance =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 ld.so(8),设置环境变量
LD_TRACE_LOADED_OBJECTS
到非空字符串将给出类似ldd
的结果(而不是正常执行二进制文件或库)。As per ld.so(8), setting the environment variable
LD_TRACE_LOADED_OBJECTS
to a non-empty string will giveldd
-like results (instead of executing the binary or library normally).您尝试过
dlopen
功能吗?您可以使用它来加载动态库(或者,对于您的情况,检查是否可以加载库)。获得所需库的列表更加困难,请查看 readelf 源
Have you tried
dlopen
function? you can use this to load a dynamic library (or, for your case, to ckeck if a library can be loaded).Having a list of needed libraries is more difficult, take a look to
handle_dynamic
function on readelf source使用 ptrace() 跟踪所有 open() 调用以查找程序所依赖的所有内容怎么样(但是,输出包括文件,而不仅仅是库)。或者也许通过文件名“/lib”中的前缀过滤输出会有所帮助。
What about using ptrace() to trace all open() calls to find all what the program depends on (however, the output includes files,not only libraries).Or maybe filtering the output by the prefix in file name "/lib" helps.