linux - GNU ld 的 --audit 标志有什么作用?

标签 linux shared-libraries ld glibc elf

我有一个应用程序,我想在其中使用 rtld-audit Linux 提供的接口(interface)来 Hook 共享库加载过程。如果我使用 LD_AUDIT 环境变量告诉动态链接器在我运行我的程序时使用我的审计库 audit.so,这会很好用。

不过,我想让它更自动化一些,不需要特殊的环境设置。 GNU ld 提供了一个--audit 标志,说明如下:

--audit AUDITLIB

Adds AUDITLIB to the "DT_AUDIT" entry of the dynamic section. AUDITLIB is not checked for existence, nor will it use the DT_SONAME specified in the library. If specified multiple times "DT_AUDIT" will contain a colon separated list of audit interfaces to use. If the linker finds an object with an audit entry while searching for shared libraries, it will add a corresponding "DT_DEPAUDIT" entry in the output file. This option is only meaningful on ELF platforms supporting the rtld-audit interface.

这向我建议,如果我使用 --audit audit.so 链接我的程序,那么它应该将我的审计库与该程序相关联。我希望在程序运行时加载审计库。

果然,使用 readelf,我可以验证使用此标志会导致 audit.so 在 ELF header 中注册为审计库。但是,如果我在未设置 LD_AUDIT 的情况下运行我的程序,则永远不会调用审计库。似乎我必须设置 LD_AUDIT=audit.so 才能获得我想要的行为。

这引出了一个问题:--audit 标志实际上做了什么?上面引用的手册页之外的任何文档似乎都非常稀缺。我不清楚 Linux 动态加载器甚至使用 ELF header 中的 DT_AUDIT 字段。这是设计使然吗?

最佳答案

This begs the question: what does the --audit flag actually do?

它设置了DT_AUDIT动态入口,谁愿意关注它。

问题是(从 current trunk 开始)GLIBC 动态加载器关注它(查找process_dl_audit 例程)。它只关注LD_AUDIT环境变量,并在直接调用加载器时关注--audit标志:ld.so

直到有人贡献代码也关注DT_AUDIT--audit 标志到ld 将保持无用。

关于linux - GNU ld 的 --audit 标志有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34034009/

相关文章:

linux - 防止脚本因错误而停止

c++ - 使用静态初始化的副作用进行一次性初始化

c++ - 我们如何让一个共享指针指向另一个共享指针的对象呢?

c++ - 在cygwin下 boost c++静态链接路径

linux - Unix 命令 ls -lrt 给出意想不到的结果

linux - 如何使用symfony4在远程ubuntu服务器上执行linux命令?

linux - 如何在具有相应名称的文件夹中根据其名称在 Linux 中移动文件?

c++ - 共享库路径作为可执行目录

ios - 为什么我的应用程序突然无法构建并提示这些 "ld"和 "clang"错误?

收集 2 : fatal error: ld terminated with signal 11 [Segmentation fault]