Is there any way to change the SONAME of a binary

2019-02-08 23:15发布

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

标签: linux libcurl
2条回答
淡お忘
2楼-- · 2019-02-08 23:33

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

查看更多
对你真心纯属浪费
3楼-- · 2019-02-08 23:46

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
查看更多
登录 后发表回答