-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Is unwinding from lang_start
really UB?
#107381
Comments
cc: @rust-lang/wg-unsafe-code-guidelines I think? |
Additionally, I believe there is some benefit to making unhandled panics call |
At least before the Even if it's not UB to unwind out of the start function, we still want to set our own catch, as an uncaught C++ unwind will terminate without running destructors, which we want to do. Additionally, the unwind failing to start will cause an There's essentially three options:
... or for My initial bias is that it should be
Any debugger somewhat aware of Rust should probably have a default breakpoint on Footnotes
|
For context, this came up when looking at #34502 (a Windows issue from 2016). |
Panics escaping main are well-defined in Rust, too. So Rust works like C++ here. Rust's lang_start corresponds to the hidden start item in a C++ runtime, not to C++ main. |
The goal here is to be able to detect, before throwing an exception, that there are no exception handlers on the stack. This enables the following:
This is a good point, and may have visible consequence such as skipping the cleanup of temporary files & directories. We should take this trade-off into account when making a decision.
This is something that we can easily change since it's an implementation detail of the panic machinery. |
If this is a case we want to have different behavior for, then it should probably be exposed to the panic handler as well. Ideally, giving the handler the power to choose between unwinding or not1. Independent of unwinding ABI, this could be accomplished by a thread-local count2 of how many Changing from a clean exit with failing exit code to a signal exit on unixes AIUI is a fairly small change in behavior, all other things being equal. On Windows, it's a much larger change, being the difference between the program exiting or a pop-up saying the program crashed. The main question is thus: is a panic unwinding from Rust Once those questions are answered, the implementation details (i.e. what it means to unwind from My initial bias is that it should have the same behavior as Footnotes
|
When using a crate which enables raw mode and disables it again in a drop function, turning panics on the main thread from unwinding to an immediate abort will mess up the terminal in such a way that you have to blindly type the command to reset the terminal state back to cooked mode. |
So the answer to the question is yes, this is really UB. I'll close the issue as I don't think we have a lot of choice here; we can't let unwinding escape beyond the start item as we cannot rely on the surrounding context supporting unwinding. If someone wants to change this, please open a new issue with rationale and explaining how it could be achieved. |
A comment in the std claims that unwinding past
lang_start
is UB:rust/library/std/src/rt.rs
Lines 136 to 145 in 6874f4e
See: #86034, #86030, #86027.
This is surprising because C++ panics escaping main is well defined to terminate (and will trigger an attached debugger, which is useful).
cc @Amanieu, who questioned this assertion.
The text was updated successfully, but these errors were encountered: