Is there any way to change the SONAME of a binary

2019-02-08 23:16发布

问题:

My program depends on libcurl.so.3, but in RHEL6, there is no soft like this libcurl.so.3 ->libcurl.so.4 (my program can run smoothly when I create this link). But there is a soft link like this: libcurl.so->libcurl.so.4.

I would like to modify the SONAME of libcurl.so.3.0.0.0 directly from libcurl.so.3 to libcurl.so. Then I can run my program on RHEL 6 without creating a soft link myself.

Maybe my solution is stupid, but I think learning how to modify the binary directly is an interesting thing.

Tahnk you for your comment, devnull. maybe i did not tell clearly.

$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 this to libcurl.so

回答1:

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


回答2:

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



标签: linux libcurl