如何欺骗 *.so 库使用缺失的 @GLIBC_2.6 函数?
我需要在不太新的 RHEL 5.6 上运行相对较新的软件包。
我有第 3 方库 (lib3rdparty.so
),它是针对 glibc 2.6 编译的,而 RHEL 5.6 仅安装了 2.5。但在库中只有几个对 sched_getcpu@@GLIBC_2.6
的引用。我已经像这样检查了它
readelf -s lib3rdparty.so | egrep "@GLIBC_2.[6-9]"
,以找到对已安装的 GLIBC_2.5
更新的内容的引用。输出是
0 FUNC GLOBAL DEFAULT UND sched_getcpu@GLIBC_2.6 (62)
0 FUNC GLOBAL DEFAULT UND sched_getcpu@@GLIBC_2.6
所以,我只有 GLIBC_2.6
中的一个函数。现在我想让图书馆认为我有这个功能。为此,我伪造了小型库(libcheat.so
),就像它提到的此处。现在我有 libcheat.so
文件,如果通过 readelf
运行,将显示此字符串:
10 FUNC GLOBAL DEFAULT 11 sched_getcpu@@GLIBC_2.6
使用此库,我成功构建了与 动态链接的可执行文件lib3rdparty.so
。如果没有这个库,我将无法构建任何东西,因为 ld
无法找到对 sched_getcpu
的引用。
但问题在于运行此文件:当我尝试运行它时,出现以下错误:
./hello_world: version `GLIBC_2.6' not found (required by ./lib3rdparty.so)
因此,我相信还有最后一步可以使其工作,但我不知道该怎么做。我尝试使用 /etc/ld.conf.preload 并导出 LD_LIBRARY_PATH ,这样它就会指向我的库,以便在其他库之前加载。但它不会运行。尝试通过 strace
运行它,但没有任何有意义的输出。
有什么想法吗?
I need to run relatively new package on not-so-new RHEL 5.6.
I have 3rd party library (lib3rdparty.so
) which is compiled against glibc 2.6 while RHEL 5.6 have only 2.5 installed. But in the library there is only a couple of references to sched_getcpu@@GLIBC_2.6
. I've checked it like this
readelf -s lib3rdparty.so | egrep "@GLIBC_2.[6-9]"
to find references to something newer than GLIBC_2.5
which is installed. The output is
0 FUNC GLOBAL DEFAULT UND sched_getcpu@GLIBC_2.6 (62)
0 FUNC GLOBAL DEFAULT UND sched_getcpu@@GLIBC_2.6
So, I have only one function from GLIBC_2.6
. Now I want to make library think, that I have this function. For that purpose I forged small library (libcheat.so
) like it mentioned here. Now I have libcheat.so
file which, if run through readelf
, will show this string:
10 FUNC GLOBAL DEFAULT 11 sched_getcpu@@GLIBC_2.6
With this library I managed to succesfully build executable which is dynamically linked with lib3rdparty.so
. Without this library I can't build anything, because ld
can't find reference to sched_getcpu
.
But the problem is with running this file: when I try to run it I have a following error:
./hello_world: version `GLIBC_2.6' not found (required by ./lib3rdparty.so)
So, I believe there is one last step to make it work, but I don't know what to do. I've tried to use /etc/ld.conf.preload
and exporting LD_LIBRARY_PATH
so it would point to my library to load before others. But it won't run. Tried to run it through strace
but have no meaningful output.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您选择的解决方法是否是最好的方法。为什么不为应用程序提供更新的 glibc?您可以尝试使用
LD_PRELOAD
环境变量传递它。为了获得最佳二进制兼容性,您可以从较新的发行版获取 glibc 二进制文件,或者为 RHEL 5.6 重建较新的 glibc 版本。另外,尝试修改 LD_DEBUG 环境变量以查看动态链接器的作用。
I'm not sure if the workaround you picked up is the best way to go. Why not supplying a newer glibc for the application? You can try to pass it over using the
LD_PRELOAD
environment variable. For best binary compatibility, you can obtain a glibc binary from a newer distribution version, or rebuild a newer glibc version for RHEL 5.6.Also, try to fiddle with the
LD_DEBUG
environment variable to see what the dynamic linker does.好吧,我相信我应该提到“最后一步”,在我的例子中包括修补二进制第三方库。
objdump
我找到了一个地址,lib3rdparty.so
搜索GLIBC_2.6
hexedit
我将此地址替换为导出GLIBC_2.5
的位置(您应该以相反的顺序搜索字节)。我还用 2.5 替换了符号。GLIBC_2.5
,所以我使用sched_getcpu@@GLIBC_2.5
作为内联汇编器之后我把在
lib3rdparty.so
附近的libcheat.so
,将LD_LIBRARY_PATH
设置为.
,我的二进制文件开始工作。我不确定这些东西是否完全正确,但如果您遇到此类问题,这个问题和答案可能会有所帮助。Ok, I believe I should mention "last step" which in my case included patching of binary 3rd party libraries.
objdump
I found an address wherelib3rdparty.so
searches forGLIBC_2.6
hexedit
I replaced this address with the one whereGLIBC_2.5
was exported (you should search for bytes in reversed order). Also I replaced symbol with 2.5.objdump
I've checked that all references now usingGLIBC_2.5
libcheat.so
assched_getcpu
now was referencingGLIBC_2.5
, so I usedsched_getcpu@@GLIBC_2.5
as assembler inlineAfter that I put
libcheat.so
nearlib3rdparty.so
, setLD_LIBRARY_PATH
to.
and my binary started to work. I'm not sure that this stuff will work totally correct, but if you stumbled into this kind of problem, this question and answer might be of some help.