Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-C self-contained=yes creates programs that crash on startup (on linux-gnu targets) #103576

Closed
uweigand opened this issue Oct 26, 2022 · 1 comment · Fixed by #104137
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@uweigand
Copy link
Contributor

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.

@jyn514 jyn514 added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 27, 2022
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 11, 2022
…d, r=petrochenkov

Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes rust-lang#103576
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 11, 2022
…d, r=petrochenkov

Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes rust-lang#103576
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 11, 2022
…d, r=petrochenkov

Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes rust-lang#103576
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2022
…d, r=bjorn3

Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes rust-lang#103576
@bors bors closed this as completed in fbcd751 Nov 16, 2022
@uweigand
Copy link
Contributor Author

Thanks for fixing this, @StackDoubleFlow !

Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…d, r=bjorn3

Issue error when -C link-self-contained option is used on unsupported platforms

The documentation was also updated to reflect this.

I'm assuming the supported platforms are the same as initially written in [RELEASES.md](https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler-17).

Fixes rust-lang#103576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants