Skip to content

RUST_BACKTRACE truncated with -Cpanic=abort #81902

Closed

Description

@Swatinem

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.

Activity

  1. added
    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Feb 8, 2021
  2. bjorn3 commented on Feb 9, 2021

    @bjorn3
    Member

    This happens because -Cpanic=abort omits the unwinding tables necessary for unwinding. You can use -Cforce-unwind-tables=yes to 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=unwind and as such does have unwinding tables available.

    See rust-lang/backtrace-rs#397 for more information.

  3. m-ou-se commented on Mar 27, 2021

    @m-ou-se
    Member

    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.

  4. bjorn3 commented on Mar 27, 2021

    @bjorn3
    Member

    How would that work? Plain checking for .eh_frame would 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".

  5. Swatinem commented on Apr 22, 2021

    @Swatinem
    ContributorAuthor

    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.

  6. martin-t commented on Nov 14, 2021

    @martin-t
    Contributor

    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.toml is 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-tables from Cargo.toml.

    I also think the behavior and the solution should be documented here.

  7. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    and removed
    C-bugCategory: This is a bug.
    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
    on Jun 30, 2025
  8. Enselic commented on Jul 7, 2025

    @Enselic
    Member

    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)

    for toolchain in 1.22 \
                     1.23 \
                     nightly-2017-10-13 \
                     nightly-2017-10-14; do
        echo -e "\n$toolchain:"
        echo 'fn main() { part_of_backtrace(); } fn part_of_backtrace() { panic!("boom"); }' |
            rustc +$toolchain -Cpanic=abort - && \
            RUST_BACKTRACE=full ./rust_out 2>&1 | grep -q part_of_backtrace && echo OK backtrace || echo BROKEN backtrace
    done
    1.22:
    OK backtrace
    
    1.23:
    BROKEN backtrace
    
    nightly-2017-10-13:
    OK backtrace
    
    nightly-2017-10-14:
    BROKEN backtrace
    

    Note that -C panic=abort was introduced already in Rust 1.10.

    IMHO this lowers the barrier of changing the default of -C force-unwind-tables for 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.

  9. 7 remaining items

  10. added a commit that references this issue on Sep 22, 2025
  11. added a commit that references this issue on Sep 29, 2025
  12. added a commit that references this issue on Oct 3, 2025
  13. added 3 commits that reference this issue on Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backtraceArea: BacktracesA-docsArea: 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.T-libsRelevant 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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions