Tiny Binaries

December 31, 2021

Out of curiousity I experimented with building the smallest possible static x86-64 Linux binaries in several programming languages.

Each binary does the following:

  1. Print hi! and a newline to standard output.
  2. 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):

All Static Binary Sizes

All Static Binary Sizes

Here’s a plot of the smallest static binary sizes (<1k, linear scale X axis):

Tiny Static Binary Sizes (&lt;1k)

Tiny Static Binary Sizes (<1k)

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.