ELF Binary Optimization for size
In Category C/C++ Linux Optimization
The following steps help in reducing the size of a Linux application ELF binary. These operations can be used for application binary as well as shared library.
Use compiler optimization flags
-Os (optimize for size)
-O2
While linking, try to use following options. But do not use ‘-s’ option for kernel modules.
# ld -r -s --discard-local --discard-all testApp.o -o testApp # ld -r -s --discard-local --discard-all testLib1.o testLib2.o -o testLib.so # ld -r --discard-local --discard-all testMod1.o testMod2.o -o testMod
Strip the binary including unnecessary sections
# strip --remove-section=.note --remove-section=.comment testApp # strip --remove-section=.note --remove-section=.comment testLib.so
Wow, this is very useful.. Thanks for sharing.