authorgravatar for jsistsir@gmail.comAyoctl <jsistsir@gmail.com> 2026-10-17 06:47:35+09:00
committergravatar for jsistsir@gmail.comAyoctl <jsistsir@gmail.com> 2026-10-17 07:32:55+09:00
log588aa35b3a83bf7d3db17db8187d82257bdea2c9
tree267352f22584460aec135331eb7a3b16b767fc3e
parentf5c77d3145d975d46c832390758f679c1f382b1a

Workaround miscompilation on Apple Silicon CPUs

As of 9cf3a2b7f8dbb, a handful of CPU features were added to Apple Silicon CPU models. This results in a broken compiler reporting `error.OutOfMemory` when it is compiled against those targets in release mode. A compiler built with `-DZIG_TARGET_MCPU=baseline` doesn't crash, and neither does one built after the LLVM 23 update, so it is likely that the LLVM 22 backend is mishandling these new features. Considering that this has already been fixed in LLVM 23, it is reasonable to introduce a workaround that gates a feature that a) fixes the problem and b) has less impact overall, hence this fix for 0.17.1.

1 files changed, 15 insertions(+), 0 deletions(-)

lib/std/zig/system.zig+15
......@@ -453,6 +453,21 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
453453 if (result.cpu.arch.isXtensa() and result.abi == .call0) {
454454 result.cpu.features.removeFeature(@backingInt(Target.xtensa.Feature.windowed));
455455 }
456
457 // A workaround for https://codeberg.org/ziglang/zig/issues/37215.
458 const apple_silicon_models = [_]*const Target.Cpu.Model{
459 &Target.aarch64.cpu.apple_m1,
460 &Target.aarch64.cpu.apple_m2,
461 &Target.aarch64.cpu.apple_m3,
462 &Target.aarch64.cpu.apple_m4,
463 &Target.aarch64.cpu.apple_m5,
464 };
465 for (apple_silicon_models) |model| {
466 if (result.cpu.model == model) {
467 result.cpu.features.removeFeature(@backingInt(Target.aarch64.Feature.fuse_aes));
468 break;
469 }
470 }
456471 }
457472
458473 // It's possible that we detect the native ABI, but fail to detect the OS version or were told