--- slug: tiny-binaries title: "Tiny Binaries" date: "2021-12-31T09:28:32-04:00" --- 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][stdout]. 2. Return an exit code of `0`. I tested [Assembly][], [C][], [Go][], and [Rust][] with various combinations of optimizations and build options. Here's a plot of the results (**note:** [log scale][] X axis): {{< figure src="/files/posts/tiny-binaries/sizes-all.svg" class=image caption="All Static Binary Sizes" >}} Here's a plot of the smallest static binary sizes (<1k, linear scale X axis): {{< figure src="/files/posts/tiny-binaries/sizes-tiny.svg" class=image caption="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][tiny-elf]. Source code, build instructions, a [CSV][] of results, and additional details are available in the [companion GitHub repository][repo]. **Update (2022-01-01):** See [Tiny Binaries: Assembly Optimization][tb-asm] for an explanation of the assembly results. [x86-64]: https://en.wikipedia.org/wiki/X86-64 "64-bit version of x86 instruction set" [linux]: https://en.wikipedia.org/wiki/Linux "Linux operating system" [assembly]: https://en.wikipedia.org/wiki/Assembly_language "Assembly language" [c]: https://en.wikipedia.org/wiki/C_(programming_language) "C programming language" [go]: https://golang.org/ "Go programming language" [rust]: https://www.rust-lang.org/ "Rust programming language" [log scale]: https://en.wikipedia.org/wiki/Logarithmic_scale "Logarithmic scale" [repo]: https://github.com/pablotron/tiny-binaries "Tiny Binaries GitHub repository" [tiny-elf]: https://nathanotterness.com/2021/10/tiny_elf_modernized.html "Tiny ELF Files: Revisited in 2021" [stdout]: https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout) "Standard output." [csv]: https://en.wikipedia.org/wiki/Comma-separated_values "Comma-Separated Values" [tb-asm]: {{< ref "/posts/2022-01-01-tiny-binaries-assembly-optimization.md" >}} "Tiny Binaries: Assembly Optimization"