std: don't get CPU context when using CBE targeting MSVC

Calling `current` here causes compilation failures as the C backend
currently does not emit valid MSVC inline assembly. This change means
that when building for MSVC with the self-hosted C backend, only FP
unwinding can be used.
This commit is contained in:
mlugg 2025-09-18 15:52:02 +01:00
parent dae703d3c0
commit 084e92879a
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 9 additions and 3 deletions

View File

@ -756,7 +756,13 @@ const StackIterator = union(enum) {
// Use `di_first` here so we report the PC in the context before unwinding any further.
return .{ .di_first = .init(context_ptr) };
}
if (SelfInfo.supports_unwinding and cpu_context.Native != noreturn) {
// Workaround the C backend being unable to use inline assembly on MSVC by disabling the
// call to `current`. This effectively constrains stack trace collection and dumping to FP
// unwinding when building with CBE for MSVC.
if (!(builtin.zig_backend == .stage2_c and builtin.target.abi == .msvc) and
SelfInfo.supports_unwinding and
cpu_context.Native != noreturn)
{
// We don't need `di_first` here, because our PC is in `std.debug`; we're only interested
// in our caller's frame and above.
return .{ .di = .init(&.current()) };

View File

@ -316,7 +316,7 @@ pub const X86_64 = struct {
\\movq %%r15, 0x78(%%rdi)
\\leaq (%%rip), %%rax
\\movq %%rax, 0x80(%%rdi)
\\movq 0x00(%%rdi), %%rax // restore saved rax
\\movq 0x00(%%rdi), %%rax
:
: [gprs] "{rdi}" (&ctx.gprs.values),
: .{ .memory = true });
@ -431,7 +431,7 @@ pub const Aarch64 = extern struct {
\\str x1, [x0, #0x0f8]
\\adr x1, .
\\str x1, [x0, #0x100]
\\ldr x1, [x0, #0x008] // restore saved x1
\\ldr x1, [x0, #0x008]
:
: [gprs] "{x0}" (&ctx),
: .{ .memory = true });