开发者

How can I remove linked library from executable file

All.

Someone created an executable file.

# ldd test_bin 
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x4082d000)
    libA.so.0 => /usr/lib/libA.so.0 (0x408fe000)
    libB.so.0 => /usr/lib/libB.so.0 (0x4093e000)
    libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x409ad000)
    libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x409fe000)
    librt.so.1 => /lib/librt.so.1 (0x40a0a000)
    libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x40a19000)
    libdbus-1.so.3 => /usr/lib/libdbus-1.so.3 (0x40b25000)
    libssl.so.0.9.8 => /usr/lib/libssl.so.0.9.8 (0x40b67000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x40bb0000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x40bc3000)
    libc.so.6 => /lib/libc.so.6 (0x40be3000)
    libm.so.6 => /lib/libm.so.6 (0x40d11000)
    libcrypto.so.0.9.8 => /usr/lib/libcrypto.so.0.9.8 (0x40d87000)
    /lib/ld-linux.so.3 (0x40000000)
    libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x40f4e000)
    libdl.so.2 => /lib/libdl.so.2 (0x40f59000)

In this case, I want to merge libB.so into libA.so.

So I create libA.so that is covered all APIs provided by libB.so.

Then I have to re-link with this library. But I don't have any source for test_bin.

How can I remove libB.so linking from executable file without any sources?

Is it possible? I just look around binutils. But I haven't found for it.

Please give me an 开发者_开发技巧advice.


You could go the easy route and make libB.so and libB.so.0 a symlink to libA.so.0. Doesn't modify the executable, but is a quick and portable solution.


I don't think it is possible, because even when you make libA.so wrap libB.so (what you described as covers), libA.so still depends on the functions of libB.so, so both have to be linked to your executable. The only workaround that I know it's what @thiton proposed or make libA.so implement libB.so without depending on it, i.e., implement all functions of libB.so or only the ones you need.


edit executable and replace

libA.so.0 

with

libB.so.0 

this works because sizeo of "libA.so.0" is the same as sizeo of "libB.so.0".

If u add or remove extra symbol it will break executable for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜