Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing entry from DYNAMIC section of elf file

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?

like image 276
dimba Avatar asked Nov 12 '22 12:11

dimba


1 Answers

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.

like image 147
Employed Russian Avatar answered Dec 15 '22 16:12

Employed Russian