-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Fix backtraces with -C panic=abort
on linux; emit unwind tables by default
#143613
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
base: master
Are you sure you want to change the base?
Conversation
Otherwise backtraces (in e.g. the default panic hook) are incomplete. More details The linux backtrace unwinder relies on unwind tables to work properly. The default panic hook prints backtraces. Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C panic=abort` (see 24cc38e). In 1.45 (see cda9946) a workaround in the form of `-C force-unwind-tables=yes` was added. More history `-C panic=abort` was added in [Rust 1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable) and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimzation opt-in with `-C force-unwind-tables=no` rather than default since the current default breaks backtraces. Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact. TODO: - [ ] better commit message - [ ] more tests? - [ ] figure out how to present this in release notes - [ ] check if all tests pass
rustbot has assigned @petrochenkov. Use |
These commits modify compiler targets. This PR modifies cc @jieyouxu |
|| self.opts.cg.force_unwind_tables.unwrap_or( | ||
self.panic_strategy() == PanicStrategy::Unwind || self.target.default_uwtable, | ||
) | ||
|| self.opts.cg.force_unwind_tables.unwrap_or(self.target.default_uwtable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the panic=unwind check? This will cause unwind tables to be disabled on some targets where they were previously enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, leftover from early prototyping and I didn't realize earlier it now is the wrong thing to do, will fix in the next iteration, thank you.
-Cpanic=abort
on linux-C panic=abort
on linux; emit unwind tables by default
Note that it’s currently pretty tricky to change this setting from whatever the default is on a given target, since there’s no Cargo profile setting for it (unlike the panic strategy), cc rust-lang/cargo#15333 This observation can probably be used as argument for or against this change. |
If you don't want unwind tables to save space you probably want to strip it out after linking anyway. |
If there's a way to drop all unwind tables that can safely be dropped but no more, then that would be a nice new feature ( |
The linux backtrace unwinder relies on unwind tables to work properly. The default panic hook prints backtraces. Backtraces with
-C panic=abort
used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with-C panic=abort
(see #45031 and #81902 (comment)).In 1.45 (see #69984) a workaround in the form of
-C force-unwind-tables=yes
was added.More history
-C panic=abort
was added in Rust 1.10 and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimzation opt-in with-C force-unwind-tables=no
rather than default since the current default breaks backtraces.Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact.
TODO
must_emit_unwind_tables()
tests/run-make/panic-abort-eh_frame/rmake.rs
compiler/rustc_target/src/spec/base/linux.rs
?Closes
Closes #81902 which is regression-from-stable-to-stable
Closes #94815