在Linux中使用LD_PRELOAD混合64位/32位环境 [英] Using LD_PRELOAD mixed 64bit/32bit environment in Linux
问题描述
我想将LD_PRELOAD设置为指向一个共享库,在该共享库中我可以运行64位或32位应用程序.显然,共享库和可执行文件必须在位上匹配.
I would like to set LD_PRELOAD to point to a shared library where I might run either a 64bit or 32bit application. It is obvious that the shared library and the executable have to match in bit-ness.
$ LD_PRELOAD=/lib64/lib_init.so ./hello32
ERROR: ld.so: object '/lib64/lib_init.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored
其中hello32是32位应用程序.世界上有一些页面说我应该能够做到:
where hello32 is a 32 bit application. There are some pages out in the world that say that I should be able to do:
$ LD_PRELOAD='/$LIB/lib_init.so' ./hello32
ERROR: ld.so: object '/$LIB/lib_init.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored
根据应用程序是32位还是64位,$ LIB将在lib和lib64之间自动切换.但这显然行不通.
Where $LIB will automatically switch between lib and lib64 depending on whether the application is 32 or 64bit. But obviously this doesn't work.
有一些技巧可以使这项工作吗?LD_PRELOAD_32,LD_PRELOAD_64?谢谢!
Is there some trick to make this work? LD_PRELOAD_32, LD_PRELOAD_64? Thanks!
推荐答案
通过指定库的完整路径,您不要让动态链接程序根据二进制体系结构调整其搜索路径.仅定义库名称,然后让链接程序为您选择正确的库.例如:
By specifying full path to the library, you don't let dynamic linker to adjust it's search path according to binaries architecture. Define only library name and let linker to pick the correct library for you. E.g.:
$ LD_PRELOAD=lib_init.so ./hello32
将在/lib中搜索lib_init.so,而
will search for lib_init.so in /lib, while
$ LD_PRELOAD=lib_init.so ./hello64
将在/lib64中搜索
will search in /lib64
这篇关于在Linux中使用LD_PRELOAD混合64位/32位环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!