forcing linking with a different SONAME than this of library

烂漫一生 提交于 2019-12-08 07:37:57

问题


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.

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 ... ).

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.


回答1:


patchelf is your friend. You can do something like: patchelf --replace-needed libcapi10.so.3 libcapi10.so.4 <your_thing>.

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




回答2:


My current best answer allowing to fullfill my need.

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.

best hints in stackverflow found there : How can I change the filename of a shared library after building a program that depends on it?



来源:https://stackoverflow.com/questions/14611140/forcing-linking-with-a-different-soname-than-this-of-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!