How to remove a specific ELF section, without stripping other symbols?

anol picture anol · Jul 16, 2015 · Viewed 9.9k times · Source

I have an ELF 32-bit x86 file which contains an .eh_frame section, despite my attempts1 to remove it.

I'd like to remove the .eh_frame section, without touching any symbols in other sections, including unused ones.

strip does not seem to have an option --remove-only, and it always ends up modifying other sections.

How can I remove a single ELF section without modifying anything else in the file?

1As suggested in other questions, I tried several variants of gcc-3.4.3 -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables, but the .eh_frame section is always there. This is probably due to the fact that I have to use an old GCC (3.4.3)... the source file itself contains nothing special that might require these sections: int main() { return 0; }.

Answer

anol picture anol · Jul 16, 2015

strip, despite the name, is not the right tool here.

A possible solution is objcopy --remove-section .eh_frame a.out, where a.out is the name of the ELF file to be modified.

Unfortunately, unless you know about objcopy, you may end up searching for solutions with strip, without finding any.