I added a very basic transformation pass operating on MIR level (just add an instruction on the beginning of every basic block) to the rustc compiler.
I build the rustc compiler with
x.py build --stage 2, and linked the result with rustup.
To test my toolchain I compiled a target program first using the stable toolchain and then with my toolchain, i.e.
cargo build vs
cargo +myrustc build. However, my custom toolchain produces very, very tiny programs compared to the default toolchain, like.. the binary shrinks to 1/7 of the original size.
Applying the art of
println! debugging, it seems to me that the programs seem to do the same whatsoever.
Is this a known issue, i.e., is anyone experiencing the same?
If not, what can I investigate to find out why my binary is so small?
Thank you very much for reading this!
I appreciate any pointers.
Did you perhaps break monomorphization and/or inlining with your changes?
Or maybe you disabled debuginfo for the standard library?
For Linux and other ELF targets, you can use
readelf -WS to check the section sizes. I would also guess that it's debuginfo from the standard library. There's a recent cargo setting to automatically strip binaries for this reason.
Thank you for all your replies, all of which are really helpful!
I first started looking into monomorphization and inline parts, but I honestly don't know where to look exactly to figure this out.
Anyway, I too think that it's related to debuginfo, because I commented the lines calling my compiler pass and build everything from scratch. My custom toolchain still produces these tiny binaries without applying my pass.
Which leads me to the next question, how do I prevent stripping the debuginfo? Is there a line I can add to
config.toml in the compiler source tree? I found numerous settings in
config.toml.example but I cannot say for sure which one I should use.
edit: Thank you all for pointing me towards the right direction. Adding the following to the
config.toml did the trick, now the binary sizes are almost identical:
debuginfo-level-std = 1