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) {...@@ -756,7 +756,13 @@ const StackIterator = union(enum) {
756 // Use `di_first` here so we report the PC in the context before unwinding any further.756 // Use `di_first` here so we report the PC in the context before unwinding any further.
757 return .{ .di_first = .init(context_ptr) };757 return .{ .di_first = .init(context_ptr) };
758 }758 }
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 {
760 // We don't need `di_first` here, because our PC is in `std.debug`; we're only interested766 // We don't need `di_first` here, because our PC is in `std.debug`; we're only interested
761 // in our caller's frame and above.767 // in our caller's frame and above.
762 return .{ .di = .init(&.current()) };768 return .{ .di = .init(&.current()) };
lib/std/debug/cpu_context.zig+2-2
...@@ -316,7 +316,7 @@ pub const X86_64 = struct {...@@ -316,7 +316,7 @@ pub const X86_64 = struct {
316 \\movq %%r15, 0x78(%%rdi)316 \\movq %%r15, 0x78(%%rdi)
317 \\leaq (%%rip), %%rax317 \\leaq (%%rip), %%rax
318 \\movq %%rax, 0x80(%%rdi)318 \\movq %%rax, 0x80(%%rdi)
319 \\movq 0x00(%%rdi), %%rax // restore saved rax319 \\movq 0x00(%%rdi), %%rax
320 :320 :
321 : [gprs] "{rdi}" (&ctx.gprs.values),321 : [gprs] "{rdi}" (&ctx.gprs.values),
322 : .{ .memory = true });322 : .{ .memory = true });
...@@ -431,7 +431,7 @@ pub const Aarch64 = extern struct {...@@ -431,7 +431,7 @@ pub const Aarch64 = extern struct {
431 \\str x1, [x0, #0x0f8]431 \\str x1, [x0, #0x0f8]
432 \\adr x1, .432 \\adr x1, .
433 \\str x1, [x0, #0x100]433 \\str x1, [x0, #0x100]
434 \\ldr x1, [x0, #0x008] // restore saved x1434 \\ldr x1, [x0, #0x008]
435 :435 :
436 : [gprs] "{x0}" (&ctx),436 : [gprs] "{x0}" (&ctx),
437 : .{ .memory = true });437 : .{ .memory = true });