I have 3rd party library A, that requires some library B. A is linked to binrary, which is linked with static version B. Therefore there's no need in dynamic version of B any more.
A is not under my control and I cannot recompile it. Thus I want to remove NEEDED libA
entry from DYNAMIC section of A.
Is there a way to do it with objcopy or other tool?
Is there a way to do it with objcopy or other tool?
I don't know of any existing tool that can do this, although elfsh might be able to.
It is quite trivial to write a C program to do what you want: the .dynamic
section of libA.so
is a table of fixed-size records (of type ElfW(Dyn)
), terminated by an entry with .d_type == DT_NULL
. To get rid of a particular DT_NEEDED
entry, simply "slide" all following entries up (overwriting entry[n]
with entry[n+1]
, etc.). This will leave your .dynamic
with two DT_NULL
entries at the end, but nothing should ever care.
One complication is that if libB.so
contains versioned symbols that libA.so
references, then there will be additional references to libB.so
in DT_VERNEED
table, and these are more difficult to get rid of. If you don't get rid of VERNEED
references, the dynamic linker will fail assertions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With