c - LD_PRELOAD什么时候会被忽略

标签 c linux

我试图使用 LD_PRELOAD 来包装系统中的一些函数,我首先导出环境变量 LD_PRELOAD 以指向我的 .so 文件,然后我运行系统,我总是得到 ERROR: ld.so: object '/full/path/to/wrap.so' from LD_PRELOAD cannot be preloaded: ignored. 所以我试图在手册页上理解 LD_PRELOAD :

A list of additional, user-specified, ELF shared libraries to be loaded before all others. The items of the list can be separated by spaces or colons. This can be used to selectively override functions in other shared libraries. The libraries are searched for using the rules given under DESCRIPTION. For set-user-ID/set-group-ID ELF binaries, preload pathnames containing slashes are ignored, and libraries in the standard search directories are loaded only if the set-user-ID permission bit is enabled on the library file.

我不是100%理解上面的文字,首先,它说

For set-user-ID/set-group-ID ELF binaries, preload pathnames containing slashes are ignored

如果不能使用斜杠,如何设置LA_PRELOAD的完整路径?

第二,它说

and libraries in the standard search directories are loaded only if...

什么是标准搜索目录?

我的最后一个问题是了解什么时候会忽略 LD_PRELOAD?感谢您的帮助。

编辑:

当我像这样将 LD_PRELOAD 导出到 /usr/lib/ 中的共享库时:export LD_PRELOAD=shared-lib.so,我摆脱了上面的错误,但我没有root权限,所以我无法将任何文件放在/usr/lib/下,对此有什么建议吗?我想如果我能设法导出 LD_PRELOAD 而没有任何斜线,它应该可以工作,但除非共享库文件位于 /usr/lib/ 中,否则 LD_PRELOAD 需要完整路径。

最佳答案

您可能想要导出 LD_DEBUG=files 以深入了解正在发生的事情,尽管输出会非常冗长并且可能需要一段时间才能找到相关行。

编辑:因为这没有帮助,您可能想尝试其他 LD_DEBUG 选项:

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
all         all previous options combined
statistics  display relocation statistics
unused      determined unused DSOs
help        display this help message and exit

all 看起来有点矫枉过正,但也许 libssymbols 会显示一些有用的东西。

关于c - LD_PRELOAD什么时候会被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29273277/

相关文章:

linux - 如何解释 ArUco 的输出

python - Python 'self' 定义中的名称错误

linux - linux脚本的source和./execution的区别

linux - selinux 阻止用户监听小于 32768 的端口(不,它大于 1024)

c - 将军事时间解析为 HH MM 和 SS/

c - 从 for 循环中的字节中提取半字节

c - 如何查看输入文件的第一个字符是否为数字? C编程

c - 如何为Raspberry Pi编写简单的UART Linux设备驱动程序?

php - UTF-8贯穿始终

c - 获取指令指针指向的给定地址的指令