强制使用与库不同的SONAME进行链接 [英] forcing linking with a different SONAME than this of library

查看:129
本文介绍了强制使用与库不同的SONAME进行链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以与具有SONAME冲突的库的两个现有版本兼容的方式链接二进制文件? 这两个版本不共享相同的SONAME前缀.一个是libcapi10.so.3,另一个是libcapi10.so.4. 我无法重新编译它们,因为我将它们获取为二进制文件,并且由于这些都是经过认证的密码库,因此我无法使用正确的SONAME请求新的库.当然,如果一个是libcap10.so.3另一个是libcap10.so.3.1,我将不会遇到任何问题,因为我只需要链接第一个即可与第二个兼容. 这两个库被告知是二进制兼容的(我应该信任此信息). 我进行了搜索,但没有找到任何好的方法,或者使用链接器选项或使用objcopy.我想避免在编译链接时手动修补二进制文件以使用它.

How to link a binary in a manner to be compatible with two existing version of a library that have conflicting SONAME ? Those two versions don't share same SONAME prefix. One is libcapi10.so.3 and the other is libcapi10.so.4. I can't recompile them since i get them as binary, and since those are certified crypto libraries i can't request new one with right SONAME. Of course i would not have faced any problem if one was libcap10.so.3 and the other libcap10.so.3.1 since i would just need to link over the first to be compatible with the second. Those two libraries are told to be binary compatible ( i should trust this info ). I searched but didn't find any good way to do , either with linker options or using objcopy. I would like to avoid patching binary by hand to use it at compilation linking time.

回到我最初的问题:如何指定SONAME(在本例中为libcap10.so)用于链接?

So back to my initial question : How to specify SONAME to be ( in this case libcap10.so ) used for link ?

(我已经搜索过,而我目前的发现只是这是行不通的,但不幸的是,这是必需的……).

( I already searched, and my current findings are just that it is a no go, but unfortunately this is a requirement ... ).

更新: 我使用类似于sed的二进制工具对.so​​库进行了修补,将libcapi10.so.6 \ 0替换为libcapi10.so \ 0,它起作用了,因为新名称比以前的名称短,并且SONAME的elf结构是一个C字符串,结尾是0,并且在gcc链接期间不使用该elf校验和.我只在编译时使用该修补程序库,然后可以在目标系统上使用相同的二进制文件使用一个或另一个原始库.

Update: i patched .so library using a binary sed-like tool replacing libcapi10.so.6\0 with libcapi10.so\0, what works since new name is shorter than previous and that elf structure for SONAME is a C-string ended with a 0 and that elf checksum is not used during gcc linking. i used that patched library only at compilation time, then i can use either one or the other original library on my target system with the same binary.

推荐答案

patchelf 是你的朋友.您可以执行以下操作:patchelf --replace-needed libcapi10.so.3 libcapi10.so.4 <your_thing>.

Patchelf对于许多其他事情也很有用,例如更改RPATH.查看联机帮助页.非常漂亮的玩具.

Patchelf is useful for a variety of other things such as changing RPATH, too. Check out the manpage. Very nifty toy.

这篇关于强制使用与库不同的SONAME进行链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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