运行 ldd 用于带参数的二进制文件

Run ldd for a binary with parameter

我知道 ldd 只能将二进制作为其参数我在这里问的是如何 运行 ldd 使用二进制,比如 mybin,带有二进制参数。例如,mybin --myparam ./configfile.conf

如果我为我的二进制文件添加 conf 文件,链接器会有所不同,因为它会在 运行 时间内使用插件的共享目标文件加载一些插件,plugin1.so 类似这样。我有一些未定义的参考问题,但我仍然不知道我丢失了哪个 .so 文件。

如果我 运行 ldd ./mybin,所有内容都已链接并且 运行 连接普通二进制文件就可以了。一旦我为我的二进制文件添加了 conf 文件,让它加载一些插件共享库,那么我的二进制文件将在加载这些库时报告错误(编码异常抛出,带有一些 undefined reference 错误消息)。

所以如果有办法 运行 lddmybin --myparam ./a.file 这样的东西会有很大帮助。

为此使用 LD_DEBUG 环境变量。要查看相关选项,运行 任何带有 LD_DEBUG=help 的命令。例如,运行ning LD_DEBUG=help ls 在我的机器上给出了这个输出:

LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  scopes      display scope information
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

调试您的 dlopen 或您正在使用的任何延迟加载机制的一种方法是 运行 您的可执行文件和带有 LD_DEBUG=all 的相关参数。这会给你一个冗长的输出,详细说明符号查找和搜索路径。此输出还会告诉您有关解析失败的信息。