Skip to content

Commit d113be9

Browse files
committed
Emit unwind tables by default with -Cpanic=abort on linux
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
1 parent 1b0bc59 commit d113be9

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

compiler/rustc_session/src/session.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,10 @@ impl Session {
802802
// If a target requires unwind tables, then they must be emitted.
803803
// Otherwise, we can defer to the `-C force-unwind-tables=<yes/no>`
804804
// value, if it is provided, or disable them, if not.
805+
//
806+
// FIXME: Update the above comment
805807
self.target.requires_uwtable
806-
|| self.opts.cg.force_unwind_tables.unwrap_or(
807-
self.panic_strategy() == PanicStrategy::Unwind || self.target.default_uwtable,
808-
)
808+
|| self.opts.cg.force_unwind_tables.unwrap_or(self.target.default_uwtable)
809809
}
810810

811811
/// Returns the number of query threads that should be used for this

compiler/rustc_target/src/spec/base/android.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ pub(crate) fn opts() -> TargetOptions {
88
base.tls_model = TlsModel::Emulated;
99
base.has_thread_local = false;
1010
base.supported_sanitizers = SanitizerSet::ADDRESS;
11-
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
12-
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
13-
// was to always emit `uwtable`).
14-
base.default_uwtable = true;
1511
base.crt_static_respected = true;
1612
base
1713
}

compiler/rustc_target/src/spec/base/linux.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub(crate) fn opts() -> TargetOptions {
1212
relro_level: RelroLevel::Full,
1313
has_thread_local: true,
1414
crt_static_respected: true,
15+
// We want backtraces to work by default and they rely on unwind tables
16+
// (regardless of `-C panic` strategy).
17+
default_uwtable: true,
1518
supported_split_debuginfo: Cow::Borrowed(&[
1619
SplitDebuginfo::Packed,
1720
SplitDebuginfo::Unpacked,

tests/run-make/panic-abort-eh_frame/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ fn main() {
2020
.edition("2021")
2121
.arg("-Zvalidate-mir")
2222
.run();
23-
llvm_objdump().arg("--dwarf=frames").input("foo.o").run().assert_stdout_not_contains("DW_CFA");
23+
llvm_objdump().arg("--dwarf=frames").input("foo.o").run().assert_stdout_contains("DW_CFA");
2424
}

0 commit comments

Comments
 (0)