A step-by-step exploration of minimizing a GCC-compiled C binary on Linux, starting from 15,816 bytes and reaching 400 bytes. Each optimization step is explained: stripping symbols (-s), removing startup files (-nostartfiles), eliminating libc and dynamic linking (-nostdlib -static -no-pie), dropping the .comment section (-fno-ident), removing stack unwind tables (-fno-asynchronous-unwind-tables -fno-exceptions), stripping GNU property notes (-Wa,-mx86-used-note=no), and finally removing page-alignment padding (-Wl,--nmagic). The final binary contains only the ELF header, two program headers, 11 bytes of x86-64 instructions (a direct syscall to exit(0)), and section metadata — totaling 400 bytes.

13m read timeFrom blog.weineng.me
Post cover image
2.4K Impressions