Sup every1 ! Once upon the time i thought it would be really interesting to use Tiny C Compiler (tcc) as Rust's backend cuz it may help us provide more optimised binaries i think. This may look not that clever but i've got no experience in interacting with LLVM and building PLs. Can anyone tell me how difficult it would be and will this be useful please?
The tiny C compiler is so tiny because it doesn't perform a lot of optimizations.
Anyway, if you want a faster/lighter-weight codegen backend, there is cranelift. Adding a whole new compiler backend is a massive amount of work, so if you have no experience with developing compilers, then you are very likely not up to the task.
I compiled this on Windows with gcc and tcc for C and rustc with target x86_64-pc-windows-msvc (panic = abort) for Rust. GCC gave 84 kb, rustc gave 12 kb, TCC gave 2 kb. Am i stupid and i could optimize Rust variant more? I know smaller binaries != greater speed so i meant optimization of binary size.
It's quite likely that you didn't account for the constant overhead of each language. If you write a much less trivial program, the differences will either dissappear completely or be very small. It's even possible that Rust outright wins at such scales, as at the language level it lends itself more to optimization than C or C++.
In general it's dangerous to assume that one language is less optimized than another only based on statistics of hello world programs.
Please search for "rust binary size static linking" or something along those lines. You are not the first one to discover that Rust links libraries statically by default. And 84 kb vs 12 kb hardly matters nowadays, because GB and TB-sized storage is commodity.
12 kB seems to be about as small as you can get this on x86_64-pc-windows-gnu, without dropping into assembly. That's about the size of MinGW's CRT glue, constructors, destructors, and PLT stubs.
@H2CO3, @jjpe, @LegionMammal978, @cole-miller, thanks everyone. Optimizing binary size wasn't the theme tho, i just wanted to know how possible doing this, in my opinion interesting, thing can be.