Home

Awesome

Minimum Binary Size Windows

CI

The smallest hello world I could get on win10 x64 in rust. This isn't something meant to be used in production, more of a challenge. I'm in no ways an expert and I have seen windows binaries get smaller on windows. [2] If you can go smaller let me know how you did it :grin:

Results

464b :sunglasses:

❯ cargo +nightly install anonlink
❯ anonlink
❯ cargo +nightly run --release
Hello World!

❯ cargo +nightly build --release && (Get-Item ".\target\release\min-sized-rust-windows.exe").Length
   Compiling min-sized-rust-windows v0.1.0 (**\min-sized-rust-windows)
    Finished release [optimized] target(s) in 1.33s
464

Strategies

I'm excluding basic strategies here such as enabling lto and setting opt-level = 'z'. [0]

Future

References

  1. https://github.com/johnthagen/min-sized-rust
  2. www.catch22.net/tuts/win32/reducing-executable-size#use-the-right-linker-settings
  3. https://github.com/pts/pts-tinype
  4. https://news.ycombinator.com/item?id=25266892 (Thank you anonunivgrad & ChrisSD!)
  5. https://processhacker.sourceforge.io/doc/struct___r_t_l___u_s_e_r___p_r_o_c_e_s_s___p_a_r_a_m_e_t_e_r_s.html
  6. https://j00ru.vexillium.org/syscalls/nt/64/
  7. https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntwritefile

Credits