Linux下使用LD_PRELOAD混合64bit/32bit环境 [英] Using LD_PRELOAD mixed 64bit/32bit environment in Linux

查看:41
本文介绍了Linux下使用LD_PRELOAD混合64bit/32bit环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 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

$LIB 将根据应用程序是 32 位还是 64 位自动在 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混合64bit/32bit环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆