Nov 202016
 

Did you know that when you compile a C file and use external libraries ALL the library code gets put into your binary? Even function that you don’t use? This is the default for gcc, but there is a way to remove them:

Instead of doing
gcc h.c -o h-in-c

You would do:
gcc -s -Os -ffunction-sections -fdata-sections -fno-ident h.c -o h-in-c

Using gcc 6.2.0 a simple hello world was 8kb without optimizing and 6kb with optimizations! For dnsmasq the filesize dropped from 320kb to 282kb (and after UPX packing to 174kb)!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)