Skip to content

Panic backtrace on Arm64 Windows is truncated #140489

Closed

Description

@dpaoliello

When running the tests\ui\runtime\backtrace-debuginfo.rs test again aarch64-pc-windows-msvc, the test fails because the backtrace has been truncated:

thread 'main' panicked at C:\repos\rust\tests\ui\runtime\backtrace-debuginfo.rs:114:9:
explicit panic
stack backtrace:
   0:     0x7ff91fe0d544 - std::backtrace_rs::backtrace::win64::trace
                               at C:\repos\rust\library\backtrace\src\backtrace\win64.rs:85
   1:     0x7ff91fe0d544 - std::backtrace_rs::backtrace::trace_unsynchronized<std::sys::backtrace::_print_fmt::closure_env$1>
                               at C:\repos\rust\library\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff91fde5510 - std::sys::backtrace::_print_fmt
                               at C:\repos\rust\library\std\src\sys\backtrace.rs:66
   3:     0x7ff91fde5510 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at C:\repos\rust\library\std\src\sys\backtrace.rs:39
   4:     0x7ff91fe2264c - core::fmt::write
                               at C:\repos\rust\library\core\src\fmt\mod.rs:1481
   5:     0x7ff91fddbeac - std::io::default_write_fmt<std::sys::stdio::windows::Stderr>
                               at C:\repos\rust\library\std\src\io\mod.rs:639
   6:     0x7ff91fdcf11c - std::io::Write::write_fmt<std::sys::stdio::windows::Stderr>
                               at C:\repos\rust\library\std\src\io\mod.rs:1914
   7:     0x7ff91fde540c - std::sys::backtrace::BacktraceLock::print
                               at C:\repos\rust\library\std\src\sys\backtrace.rs:42
   8:     0x7ff91fe04364 - std::panicking::default_hook::closure$0
                               at C:\repos\rust\library\std\src\panicking.rs:300
   9:     0x7ff91fe04184 - std::panicking::default_hook
                               at C:\repos\rust\library\std\src\panicking.rs:327
  10:     0x7ff91fe04b5c - std::panicking::rust_panic_with_hook
                               at C:\repos\rust\library\std\src\panicking.rs:833
  11:     0x7ff91fde5bf4 - std::panicking::begin_panic::closure$0<ref$<str$> >
                               at C:\repos\rust\library\std\src\panicking.rs:770

Digging into this further, the issue appears to be that the call to RtlVirtualUnwind stops after unwinding after std::panicking::begin_panic::closure$0<ref$<str$> > because the function reported by RtlLookupFunctionEntry is incorrect.

RtlLookupFunctionEntry seems to be getting confused as std::panicking::begin_panic::closure$0<ref$<str$> > is a non-returning function where its last instruction is to branch to another non-returning function. Thus, the return address reported from rust_panic_with_hook is actually after the end of std::panicking::begin_panic::closure$0<ref$<str$> >:

0:000> u 0x7ff91fde5bf0
std_b6e0767fb633a355!std::panicking::begin_panic::closure$0<ref$<str$> >+0x2c [C:\repos\rust\library\std\src\panicking.rs @ 770]:
00007ff9`1fde5bf0 94007ba1 bl          std_b6e0767fb633a355!std::panicking::rust_panic_with_hook (00007ff9`1fe04a74)
std_b6e0767fb633a355!std::sys::pal::windows::pipe::anon_pipe [C:\repos\rust\library\std\src\sys\pal\windows\pipe.rs @ 59]:
00007ff`91fde5bf0 d10583ff sub         sp,sp,#0x160

We might need to, somehow, get LLVM to add some padding for this case.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 29, 2025
  2. added
    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
    O-windowsOperating system: Windows
    on Apr 30, 2025
  3. added
    O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state
    A-panicArea: Panicking machinery
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 30, 2025
  4. bjorn3 commented on Apr 30, 2025

    @bjorn3
    Member

    Is rust responsible for calling RtlLookupFunctionEntry? If so can we subtract 1 from the return address before doing the lookup? That is what we do for looking up the function name with DWARF: https://github.com/rust-lang/backtrace-rs/blob/903c10db222c24b3e0fd085dfb0523abff192c5c/src/symbolize/mod.rs#L123-L147

  5. ChrisDenton commented on Apr 30, 2025

    @ChrisDenton
    Member

    Is rust responsible for calling RtlLookupFunctionEntry?

    Yes.

  6. dpaoliello commented on Apr 30, 2025

    @dpaoliello
    ContributorAuthor

    I'll do some experiments with this later, for now I'm documenting it as I try to stand up the Arm64 Windows runner.

    @rustbot claim

  7. added a commit that references this issue on May 8, 2025
  8. added 2 commits that reference this issue on May 8, 2025
  9. added a commit that references this issue on May 8, 2025
  10. dpaoliello commented on Oct 28, 2025

    @dpaoliello
    ContributorAuthor

    Digging into this further, the issue appears to be that the call to RtlVirtualUnwind stops after unwinding after std::panicking::begin_panic::closure$0<ref$<str$> > because the function reported by RtlLookupFunctionEntry is incorrect.

    RtlLookupFunctionEntry seems to be getting confused as std::panicking::begin_panic::closure$0<ref$<str$> > is a non-returning function where its last instruction is to branch to another non-returning function. Thus, the return address reported from rust_panic_with_hook is actually after the end of std::panicking::begin_panic::closure$0<ref$<str$> >:

    FYI, looks like the correct thing to do here is for LLVM to generate MSFT_OP_CLEAR_UNWOUND_TO_CALL unwind codes for these cases: this will instruct RtlVirtualUnwind to look at the previous instruction. Not sure when I'll get around to implementing this...

  11. dpaoliello commented on Feb 26, 2026

    @dpaoliello
    ContributorAuthor

    Talked to other folks at Microsoft: MSFT_OP_CLEAR_UNWOUND_TO_CALL is the wrong solution to this. Their guess is that LLVM isn't generating a brk after the call to the noreturn function, which is required both to make unwinding work and for security.

  12. added a commit that references this issue on Mar 7, 2026
    395c84c
  13. added a commit that references this issue on Mar 8, 2026
    4400f2f
  14. added a commit that references this issue on Mar 8, 2026
    117729d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-backtraceArea: BacktracesA-panicArea: Panicking machineryA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsC-bugCategory: This is a bug.O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 stateO-windowsOperating system: Windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions