我试图使用 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
看起来有点矫枉过正,但也许 libs
或 symbols
会显示一些有用的东西。
关于c - LD_PRELOAD什么时候会被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29273277/