Description
Compiling and running a "hello world" with the -C self-contained=yes
option on x64_64-unknown-linux-gnu
results in:
$ cat hello.rs
fn main() {
println!("Hello World!");
}
$ rustc hello.rs -C link-self-contained=yes
$ ./hello
Segmentation fault (core dumped)
This happens with any rust version I tried, in particular rustc 1.64.0 (a55dd71d5 2022-09-19)
.
Looking into more details reveals:
$ RUSTC_LOG=rustc_codegen_ssa::back::link=info rustc hello.rs -C link-self-contained=yes
[...]
INFO rustc_codegen_ssa::back::link linker stderr:
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000000320
So what appears to happen is that there are no startup objects available in self-contained mode for the target, therefore no startup objects participate in the link command, and therefore the entry point symbol in the final ELF executable is set to some random address, causing the crash on startup.
Now, the RELEASES.md file states that link-self-contained
is not supported on linux-gnu (glibc) targets. I assume this is still true (the "normal" documentation apparently doesn't say)?
Even so, I guess it would still be much preferable to issue an error (or even just ignore the option), rather than silently creating broken binaries.