Out of curiousity I experimented with building the smallest possible static x86-64 Linux binaries in several programming languages.
Each binary does the following:
- Print
hi!
and a newline to standard output. - Return an exit code of
0
.
I tested Assembly, C, Go, and Rust with various optimization and build option combinations.
Here’s a plot of the results (note: log scale X axis):
Here’s a plot of the smallest static binary sizes (<1k, linear scale X axis):
Full Disclosure: asm-opt
is the smallest legitimate result;
asm-elf
uses dirty tricks from Tiny ELF Files: Revisited in
2021.
Source code, build instructions, a CSV of results, and additional details are available in the companion GitHub repository.
Update (2022-01-01): See Tiny Binaries: Assembly Optimization for an explanation of the assembly results.
Update (2022-02-24): Rust 1.59.0 was released today and makes it significantly easier to create stripped binaries.
Update (2022-03-02): Added a follow up post with Go 1.18rc1, Rust 1.59, and TinyGo 0.22.