authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-18 15:52:02+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:55+01:00
log084e92879a1732374fac5f1a05a27f42b9306d22
tree59d416eec4b409c74aa2c0b95781e418d5cd2c7a
parentdae703d3c028eab3bf98d89d2bca1abc75f864fa
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 9 insertions(+), 3 deletions(-)

lib/std/debug.zig+7-1
......@@ -756,7 +756,13 @@ const StackIterator = union(enum) {
756756 // Use `di_first` here so we report the PC in the context before unwinding any further.
757757 return .{ .di_first = .init(context_ptr) };
758758 }
759 if (SelfInfo.supports_unwinding and cpu_context.Native != noreturn) {
759 // Workaround the C backend being unable to use inline assembly on MSVC by disabling the
760 // call to `current`. This effectively constrains stack trace collection and dumping to FP
761 // unwinding when building with CBE for MSVC.
762 if (!(builtin.zig_backend == .stage2_c and builtin.target.abi == .msvc) and
763 SelfInfo.supports_unwinding and
764 cpu_context.Native != noreturn)
765 {
760766 // We don't need `di_first` here, because our PC is in `std.debug`; we're only interested
761767 // in our caller's frame and above.
762768 return .{ .di = .init(&.current()) };
lib/std/debug/cpu_context.zig+2-2
......@@ -316,7 +316,7 @@ pub const X86_64 = struct {
316316 \\movq %%r15, 0x78(%%rdi)
317317 \\leaq (%%rip), %%rax
318318 \\movq %%rax, 0x80(%%rdi)
319 \\movq 0x00(%%rdi), %%rax // restore saved rax
319 \\movq 0x00(%%rdi), %%rax
320320 :
321321 : [gprs] "{rdi}" (&ctx.gprs.values),
322322 : .{ .memory = true });
......@@ -431,7 +431,7 @@ pub const Aarch64 = extern struct {
431431 \\str x1, [x0, #0x0f8]
432432 \\adr x1, .
433433 \\str x1, [x0, #0x100]
434 \\ldr x1, [x0, #0x008] // restore saved x1
434 \\ldr x1, [x0, #0x008]
435435 :
436436 : [gprs] "{x0}" (&ctx),
437437 : .{ .memory = true });