Skip to content

Commit 117729d

Browse files
authored
Unrolled build for #153202
Rollup merge of #153202 - dpaoliello:arm64unwind, r=cuviper [win] Fix truncated unwinds for Arm64 Windows Panic backtraces on ARM64 Windows are truncated because Rust's LLVM configuration sets `NoTrapAfterNoreturn = true`, which suppresses the generation of `brk #0x1` (trap) instructions after calls to `noreturn` functions. Without this trap instruction, the return address from a `noreturn` call points past the end of the calling function into an unrelated function, causing `RtlLookupFunctionEntry` to return the wrong unwind information, which terminates the stack walk prematurely. In general, `NoTrapAfterNoreturn = true` is recommended against for Windows, since we have seen security vulnerabilities in the past where an attacker has managed to return from a noreturn function, or the function wasn't actually noereturn, resulting in executing whatever was after the call. This change disables setting `NoTrapAfterNoreturn = true` for Windows. Fixes #140489
2 parents 052b9c2 + 614bac5 commit 117729d

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
347347
// option causes bugs in the LLVM WebAssembly backend. You should be able to
348348
// remove this check when Rust's minimum supported LLVM version is >= 18
349349
// https://github.com/llvm/llvm-project/pull/65876
350-
if (!Trip.isWasm()) {
350+
//
351+
// Also keep traps after noreturn calls on Windows, because the trap is
352+
// needed to keep the return address within the calling function's
353+
// .pdata range. Without it, RtlLookupFunctionEntry resolves the wrong
354+
// function and SEH unwinding (used for backtraces) terminates early.
355+
// See https://github.com/rust-lang/rust/issues/140489
356+
if (!Trip.isWasm() && !Trip.isOSWindows()) {
351357
Options.NoTrapAfterNoreturn = true;
352358
}
353359
}

tests/ui/runtime/backtrace-debuginfo.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,9 @@ macro_rules! dump_and_die {
4747
// there, even on i686-pc-windows-msvc. We do the best we can in
4848
// rust-lang/rust to test it as well, but sometimes we just gotta keep
4949
// landing PRs.
50-
//
51-
// aarch64-msvc/arm64ec-msvc is broken as its backtraces are truncated.
52-
// See https://github.com/rust-lang/rust/issues/140489
5350
if cfg!(any(target_os = "android",
5451
all(target_os = "linux", target_arch = "arm"),
5552
all(target_env = "msvc", target_arch = "x86"),
56-
all(target_env = "msvc", target_arch = "aarch64"),
57-
all(target_env = "msvc", target_arch = "arm64ec"),
5853
target_os = "freebsd",
5954
target_os = "dragonfly",
6055
target_os = "openbsd")) {

0 commit comments

Comments
 (0)