RUST_BACKTRACE truncated with -Cpanic=abort #81902
Copy link
Copy link
Closed
Labels
A-backtraceArea: BacktracesArea: BacktracesA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
When using -Cpanic=abort, the resulting panic backtrace is being truncated.
Interestingly, when wrapping with a custom panic hook, this problem is even worse.
fn main() {
let next = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| next(info)));
panic!("oh no! anyway...");
}Tested on nightly and stable. Only seems to be a problem on mac and linux, windows does not seem to be effected.
RUST_BACKTRACE=full with -Cpanic=unwind
thread 'main' panicked at 'oh no! anyway...', panic-backtrace.rs:5:5
stack backtrace:
0: 0x5641e75c2937 - std::backtrace_rs::backtrace::libunwind::trace::h8bc78f7bc1f75bdb
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
1: 0x5641e75c2937 - std::backtrace_rs::backtrace::trace_unsynchronized::ha4c961c9576f95ba
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x5641e75c2937 - std::sys_common::backtrace::_print_fmt::hc20cfdc233d6eb02
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:67:5
3: 0x5641e75c2937 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h04bea14549780a0f
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:46:22
4: 0x5641e75d94dc - core::fmt::write::h3868db8542c90941
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/fmt/mod.rs:1096:17
5: 0x5641e75c0b22 - std::io::Write::write_fmt::h55dd75636eef6a5c
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/io/mod.rs:1568:15
6: 0x5641e75c47f5 - std::sys_common::backtrace::_print::h6439e8525077c7da
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:49:5
7: 0x5641e75c47f5 - std::sys_common::backtrace::print::h02b685f728ce3931
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:36:9
8: 0x5641e75c47f5 - std::panicking::default_hook::{{closure}}::h7c29625065fafae1
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:208:50
9: 0x5641e75c4353 - std::panicking::default_hook::hba441710bb71f4d5
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:225:9
10: 0x5641e75ac41f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h96c2c6718f794857
11: 0x5641e75abc34 - panic_backtrace::main::{{closure}}::hce20eff12a892edc
12: 0x5641e75c4fb6 - std::panicking::rust_panic_with_hook::ha936eb00e51bc4d9
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:595:17
13: 0x5641e75ac0da - std::panicking::begin_panic::{{closure}}::h7a9154edebf9ece3
14: 0x5641e75abc85 - std::sys_common::backtrace::__rust_end_short_backtrace::h1e2014397c41a685
15: 0x5641e75ac026 - std::panicking::begin_panic::h53c35f27b097d4f4
16: 0x5641e75abc16 - panic_backtrace::main::h5ef5bf96a2375ff6
17: 0x5641e75abeb6 - core::ops::function::FnOnce::call_once::hc2eccc5827063ab0
18: 0x5641e75abcb9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2e49d68cd7dda505
19: 0x5641e75ac91c - std::rt::lang_start::{{closure}}::he479198adea7d32d
20: 0x5641e75c53b7 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h7c92107c3c98a949
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/ops/function.rs:259:13
21: 0x5641e75c53b7 - std::panicking::try::do_call::h7454c57e8fbf0cc1
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:379:40
22: 0x5641e75c53b7 - std::panicking::try::he71cdc15ed83b5ec
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:343:19
23: 0x5641e75c53b7 - std::panic::catch_unwind::hfc08ddb043e6e18c
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panic.rs:410:14
24: 0x5641e75c53b7 - std::rt::lang_start_internal::he4958117ec6901fd
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/rt.rs:51:25
25: 0x5641e75ac8f8 - std::rt::lang_start::hdc838a40e951ed3a
26: 0x5641e75abc5b - main
27: 0x7f1653f01152 - __libc_start_main
28: 0x5641e75ab09e - _start
29: 0x0 - <unknown>
RUST_BACKTRACE=full with -Cpanic=abort
thread 'main' panicked at 'oh no! anyway...', panic-backtrace.rs:5:5
stack backtrace:
0: 0x55bf3d3dc5a7 - std::backtrace_rs::backtrace::libunwind::trace::h8bc78f7bc1f75bdb
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
1: 0x55bf3d3dc5a7 - std::backtrace_rs::backtrace::trace_unsynchronized::ha4c961c9576f95ba
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x55bf3d3dc5a7 - std::sys_common::backtrace::_print_fmt::hc20cfdc233d6eb02
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:67:5
3: 0x55bf3d3dc5a7 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h04bea14549780a0f
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:46:22
4: 0x55bf3d3f2a3c - core::fmt::write::h3868db8542c90941
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/fmt/mod.rs:1096:17
5: 0x55bf3d3da792 - std::io::Write::write_fmt::h55dd75636eef6a5c
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/io/mod.rs:1568:15
6: 0x55bf3d3de3c5 - std::sys_common::backtrace::_print::h6439e8525077c7da
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:49:5
7: 0x55bf3d3de3c5 - std::sys_common::backtrace::print::h02b685f728ce3931
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/sys_common/backtrace.rs:36:9
8: 0x55bf3d3de3c5 - std::panicking::default_hook::{{closure}}::h7c29625065fafae1
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:208:50
9: 0x55bf3d3ddf23 - std::panicking::default_hook::hba441710bb71f4d5
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:225:9
10: 0x55bf3d3c610f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h96c2c6718f794857
[1] 488156 abort (core dumped) RUST_BACKTRACE=full ./panic-backtrace
Using only RUST_BACKTRACE=1 in that case will not print any backtrace at all.
Reacted by Anders Musikka, Martin Taibr and Jaka Jančar
Metadata
Metadata
Assignees
Labels
A-backtraceArea: BacktracesArea: BacktracesA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Activity
bjorn3 commentedon Feb 9, 2021
This happens because
-Cpanic=abortomits the unwinding tables necessary for unwinding. You can use-Cforce-unwind-tables=yesto add them back at the cost of an increased binary. The fact that you have part of a backtrace at all is because libstd is compiled with-Cpanic=unwindand as such does have unwinding tables available.See rust-lang/backtrace-rs#397 for more information.
m-ou-se commentedon Mar 27, 2021
Maybe we should find a way to remove the
run with `RUST_BACKTRACE=1`suggestion from the panic message when unwind tables are not available.bjorn3 commentedon Mar 27, 2021
How would that work? Plain checking for
.eh_framewould almost always result in unwind tables for linked in native dependencies. And when one rust dependency doesn't have unwind tables, another may have. A better solution would be I think to handle this case more gracefully during unwinding by printing something like "unwind info unavailable for the next function; aborting".Swatinem commentedon Apr 22, 2021
Thinking a bit more about this, I think linking the creation of unwind tables to the panic method is not a sensible thing.
"catching panics" and "creating stack traces" are two different concerns.
martin-t commentedon Nov 14, 2021
I second this, I started using
panic = "abort"after reading this article because my code is not written to handle random threads unwinding. I, however, still do want backtraces.Having to add
rustflags = ["-Cforce-unwind-tables=y"]to.cargo/config.tomlis a bit unwieldy, especially when trying to be careful not to override other rustflags set somewhere else. Is there a better place?Is it still possible to change the behavior of
panic = "abort"to keep unwind tables? If not, then there should at least be a way to set-Cforce-unwind-tablesfromCargo.toml.I also think the behavior and the solution should be documented here.
Enselic commentedon Jul 7, 2025
This is actually a regression-from-stable-to-stable, namely 1.22 to 1.23. More specifically from nightly-2017-10-13 to nightly-2017-10-14 (very likely #45031)
Note that
-C panic=abortwas introduced already in Rust 1.10.IMHO this lowers the barrier of changing the default of
-C force-unwind-tablesfor Linux (#94815). And among all issues regarding this I have browsed I have yet to see anyone being against changing that default.Edit: See #143613 for a PR to change the default.
7 remaining items
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Rollup merge of rust-lang#143613 - Enselic:panic-abort-uwtables, r=pe…
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of rust-lang#143613 - Enselic:panic-abort-uwtables, r=petr…
Auto merge of rust-lang#143613 - Enselic:panic-abort-uwtables, r=petr…
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov
Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkov