-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Binary crashes when statically linked with LTO turned on #94564
Comments
I can reproduce this issue. |
I've kind of been hoping someone else will ask this: Are you sure this is a soundness bug? At a glance, this looks to me like a logic bug in an unfortunate location that double-panics. |
It shouldn't panic, so I would expect the panic is caused by corruption. Also if it was a double panic there should at least be a panic message for the first panic. |
Reproducable with 1.59.0, 1.60.0-beta.2 and current nightly (c274e49 2022-03-05). Stacktrace with current nightly:
|
It seems that static RWLocks are not working properly for some reason leading to the double panic, because RWLock are also used in the central panic dispatcher. For the first panic there is no message displayed because the actual panic handler is never called. Minimum rustc invocation to trigger it: It was working with Rust 1.51, regressed in nightly-2021-02-14.
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-critical |
Quick note from Zulip discussion: We are seeing evidence that the ability to reproduce this issue is somewhat coupled with the version of glibc that one is using. Specifically, people who have been able to reproduce the issue did so atop glibc versions 2.31 and 2.33. People who have not been able to reproduce the issue were running atop glibc versions 2.34 and 2.35. |
Just to repeat what I found in the Zulip thread: I think what's happening is with LTO, enough dead code elimination runs that only some object files from This is an old glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=5784. In fact, on the same container I reproduced the Rust issue in, I can just as easily reproduce it in C:
The usual workaround is to pass
but I don't know how to convince I believe this stopped reproducing with glibc 2.34 because libpthread was merged into libc. |
Some thoughts: assuming this is indeed a glibc bug, then that strikes me as an argument that we should not be bending over backwards to fix this. The main mitigations I can imagine here:
|
Can this be closed now that (thanks to @m-ou-se) libstd uses its own locking implementation instead of using the buggy glibc rwlocks? |
Oh did I accidentally fix this bug? Nice :) Can someone confirm that the issue is gone on the latest nightly Rust? |
I gave a quick spin with
|
Looks like it's still segfaulting in CI: #96208 (comment) |
It fails with a different stack trace now:
|
I've tried with the latest nightly on a Debian/bookworm with libc
But is my test relevant? I also mention the libc version since in the Zulip thread I understood that it was somehow related |
@apiraino That works fine here too (glibc 2.35), but running |
It breaks only with |
Looks like there's simply an
|
I've updated #96208 to include |
Is there a reason that we're not statically forbidding (or at least linting?) on such a configuration? It seems like if it's going to (likely) lead to an assertion at runtime, it'd be better for rustc to avoid letting you compile in such a mode, rather than accepting it. In general I think we try to hide this kind of sharp edge from users with better compiler error messages. |
This seems like a plain bug in glibc. At the very least it should not be segfaulting trying to print an assertion failure message. |
I tried this code:
Compiled with :
RUSTFLAGS="-C target-feature=+crt-static" cargo run --release
I expected to see this happen: Spawn & get output of child
ls
processInstead, this happened: Program crashes with :
Disabling LTO or static linking removes the issue without any code changes.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: