Binary is way bigger on linux than on macOS


I have noticed that binaries on linux (fedora & ubuntu) resulted from cargo build --release is way bigger than them on macOS. for example compiling this package on linux results in 4.8M but on my macOS it’s just 1.4M.

Is there a reason for this to happen, and how can I achieve that small size binary on linux?


I don’t have an answer to the difference, but on how to optimize read


It may be that the linux build uses more static linking, so it’s embedding more code in the binary? Is there much difference when you see what libraries are linked to dynamically using ldd?

I tried this out on my laptop with that repo and cross-compiling with cross for both windows and linux (I don’t have access to a mac, and cross doesn’t yet support x86_64-apple-darwin).

$ cross build --target x86_64-unknown-linux-gnu --release
$ du -h target/x86_64-unknown-linux-gnu/release/echo
6.1M	target/x86_64-unknown-linux-gnu/release/echo
$ ldd target/x86_64-unknown-linux-gnu/release/echo (0x00007ffe1cbbc000) => /usr/lib/ (0x00007fbd47ce1000) => /usr/lib/ (0x00007fbd47ad9000) => /usr/lib/ (0x00007fbd478bb000) => /usr/lib/ (0x00007fbd476a4000) => /usr/lib/ (0x00007fbd472ec000)
	/lib64/ => /usr/lib64/ (0x00007fbd48227000)

$ cargo rustc --release -- -C lto
$du -h target/release/echo
4.5M	target/release/echo

# compiling to x86_64 windows
$ cross build --target x86_64-pc-windows-gnu --release
$ du -h target/x86_64-pc-windows-gnu/release/echo.exe
8.5M	target/x86_64-pc-windows-gnu/release/echo.exe

So the windows binary turns out to be twice as big as the linux one. This makes things really interesting…

It may be useful to ask on the internal forum, seeing as a lot of people who work on rustc hang out there.


It’s the bloat from debug symbols (which Rust adds even in release mode). Bug:

Run strip and both will shrink down to 1.1MB.


strip did the trick indeed. thnx man