191 points · by adito · 11y ago · 57 comments
But honestly... does it really matter how small your executable is? I'd care a lot more about performance characteristics than binary size.
[1] http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
Of course, this is just an approximate general rule, and extremely small binaries (and generally any "pointless" experimentation) like this are mainly interesting from a learning point of view (or for small embedded microcontrollers), e.g. understanding syscalls and program start-up, and, for the write-up you link, the ELF format. (Not everything has to be inherently useful for an actual task.)
The key word here is I'd. The programming world is vast, and the range of hardware is likewise vast. So, so vast. Really huge. Pick a restriction you don't have to worry about; someone else out there does.
It demonstrates how much control you can choose to exert over your compiled program.
So we already knew that about assembler, now we also know Rust can be twisted quite close to that too.
Hello World in Rust with tip of tree (as of yesterday) is a ~500K binary that depends on glibc and friends.
Switching from println!() to std::io...write_str() actually made it larger!
Even if that means him dismissing me/my question entirely lol.
As I recall Rust is currently targeting only Intel and ARM backends.
And it's way too early to see if it'll make it.
Because that's explicitly one of the things Rust was developed for.
Here's a whole list of kernels and other OS projects that have been created using Rust:
https://github.com/rust-lang/rust/wiki/Operating-system-deve...
push 1
pop eax
mov edi, eax
mov esi, 400008h
push 7
pop edx
syscall
push 3ch
pop eax
xor edi, edi
syscall
It should be 10 bytes shorter.All of the machine code comes out of rustc. (Although all of the instructions that survive optimization went in as inline assembly.)
So while his main() is written in (unsafe) Rust, he's basically using it as a macroassembler.
As far as I know, Go statically links the runtime into the binary (including the garbage collector, the scheduling system and more)... so for a small program like this sample, it will appear to be abnormally bloated. If it were a larger, more complex example, then the binary size wouldn't change as drastically (and on a surface level might appear to be more justifiable).
http://forum.dlang.org/post/qcbicxrtmjmwiljsyhdf@forum.dlang...
The PE format is rather bulkier than ELF, though.
On Linux, with dynamic linking:
rustc: 8656 bytes
clang: 6960 bytes
gcc: 6688 bytes