From 5ee0c6422399b5219dbc06a3d7bb9f59f20cf7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 16 Aug 2026 07:25:03 +0200 Subject: [PATCH] std.zig.system.x86: deal with lying hypervisors closes https://codeberg.org/ziglang/zig/issues/36515 --- lib/std/zig/system/x86.zig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig index e4fa035747ce7195a1401722d1a9aa366dfd9698..23687255a5be522c3c0f5bb7579df484e7e45277 100644 --- a/lib/std/zig/system/x86.zig +++ b/lib/std/zig/system/x86.zig @@ -76,7 +76,13 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T 0x756e6547 => detectIntelProcessor(&cpu, family, model, brand_id), 0x68747541 => detectAmdProcessor(&cpu, family, model), else => null, - }) |m| { + }) |m| b: { + // Some hypervisors are evil liars and will operate in long mode while identifying as a + // CPU model that never had long mode in reality. We've seen this in practice with + // athlon_xp (AMD K7). Catch this contradiction and fall back to using a generic CPU + // model with the features we detected earlier. + if (cpu.has(.x86, .@"64bit") and !Target.x86.featureSetHas(m.features, .@"64bit")) break :b; + cpu.model = m; } } -- 2.54.0