Open gui2maraes opened 3 years ago
The standard library is probably not being compiled with optimizations. I think ./build.sh --release
will compile both cg_gcc and the standard library with optimizations. cg_clif for example which doesn't do optimizations like inlining, but does take much care to produce locally efficient code, has a hello world of 12MB. The cg_ssa backend framework produces less efficient code and instead requires an optimizer to run to eliminate those inefficiencies.
As for the LTO crash adding the following to the Cargo.toml
of your hello world project will likely fix it:
[profile.release]
lto = false
It may be necessary to add lto = false
here to make ./build.sh --release
work. I haven't tried though.
I'm kind of lost here. How is the standard library linked? I only found libstd.so files, and I don't think rustc recompiles the stdlib for every binary. Is it stored as separate components?
Also, what is sysroot, and why does it need to be patched and recompiled?
The standard library is statically linked by default and not dynamically linked. See the *.rlib files. The sysroot is the collection of all the crates that form the standard library and various supporting crates like compiler_builtins or profiler_runtime. It needs to be recompiled by cg_gcc as cg_gcc is not abi compatible with cg_llvm and thus trying to link to the cg_llvm built standard library would cause a crash.
Ok, think I understand now. Should I close the issue?
To be honest, I've seen those huge binaries as well. So, let's keep this issue open for now.
I tried compiling the default "Hello, world!" program with rustc_codegen_gcc, and noticed the resulting binary has a size of ~20MB, opposed to the default rustc ~3MB binary. I don't know if it has something to do with optimization, or static libraries.
I also tried building the binary with --release, and got an ICE due to LTO not being implemented. Are these two things related?