forcing linking with a different SONAME than this of library
Asked Answered
L

2

2

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.

Longo answered 30/1, 2013 at 18:28 Comment(4)
self-commenting : related question #2759754Longo
duplicate question #12475267Longo
Do libcapi10.so.3 and libcapi10.so.4 have the same SO_NAME? Are you wanting to link your executable to both libraries at the same time, or do you want it to choose only one of the libraries if present and run time?Ministrant
libcapi10.so.3 and libcapi10.so.4 are the SONAME, files are libcapi10.so.3.6.1... Executable should run with either the first or the second, both can't be installed normaly on the system, if it is the case (a hack) then symbolic link created with ldconfig on libcapi10.so will be used.Longo
D
7

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.

Dimple answered 15/5, 2017 at 14:53 Comment(0)
L
0

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?

Longo answered 2/3, 2013 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.