Repository: rust
Issue: RUST_BACKTRACE truncated with -Cpanic=abort
Labels: A-runtime,C-bug,T-libs

When using `-Cpanic=abort`, the resulting panic backtrace is being truncated.

Interestingly, when wrapping with a custom panic hook, this problem is even worse.

```rust
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.

<details><summary>RUST_BACKTRACE=full with -Cpanic=unwind</summary>
<p>

```
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>
```

</p>
</details>

<details><summary>RUST_BACKTRACE=full with -Cpanic=abort</summary>
<p>

```
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
```

</p>
</details>

Using only `RUST_BACKTRACE=1` in that case will not print any backtrace at all.