Is there any way to change the SONAME of a binary directly?

14

My program depends on libcurl.so.3, but in RHEL6 there is no symbolic link libcurl.so.3 ⇾ libcurl.so.4 (my program can run smoothly when I create this link). However, there is symbolic link libcurl.so ⇾ libcurl.so.4.

I would like to modify the SONAME embedded in libcurl.so.3.0.0.0 file from libcurl.so.3 to libcurl.so so that I could run my program on RHEL 6 without creating a symbolic link.

My solution could not be optimal but I think learning how to modify the binary directly is valuable.

$readelf -d libcurl.so.3.0.0 

Dynamic segment at offset 0x303cc contains 25 entries:

  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libssl.so.2]
 0x0000000e (SONAME)                     Library soname: [libcurl.so.3]

I would like to change libcurl.so.3 above to libcurl.so.

linux
linker
shared-libraries
libcurl
binaryfiles
asked on Stack Overflow Aug 27, 2013 by user2721786 • edited Mar 19, 2019 by Piotr Dobrogost

2 Answers

15

Yes, you can use patchelf like this (from its Readme):

patchelf --set-soname libnewname.so.3.4.5 path/to/libmylibrary.so.1.2.3
answered on Stack Overflow Jan 15, 2018 by Timmmm
0

You should avoid removing the version of the SO object, as for example when your application depends on a specific libc (libc.so.6).

The proper way to do it, if you want to use another lib is using the LD_PRELOAD variable before calling your application

If you set LD_PRELOAD to the path of the new file, that file will be loaded before any other library (including even C runtime, libc.so).

answered on Stack Overflow Nov 6, 2014 by Breno Leitão

User contributions licensed under CC BY-SA 3.0