authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-16 07:25:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-16 07:25:03+02:00
log5ee0c6422399b5219dbc06a3d7bb9f59f20cf7ef
treef0fabb2d46dae381c5957d41e98fee66e7a454ed
parent18c87599b157510cec757e69d09a78c5201882df
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.zig.system.x86: deal with lying hypervisors

closes https://codeberg.org/ziglang/zig/issues/36515

1 files changed, 7 insertions(+), 1 deletions(-)

lib/std/zig/system/x86.zig+7-1
...@@ -76,7 +76,13 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T...@@ -76,7 +76,13 @@ pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: T
76 0x756e6547 => detectIntelProcessor(&cpu, family, model, brand_id),76 0x756e6547 => detectIntelProcessor(&cpu, family, model, brand_id),
77 0x68747541 => detectAmdProcessor(&cpu, family, model),77 0x68747541 => detectAmdProcessor(&cpu, family, model),
78 else => null,78 else => null,
79 }) |m| {79 }) |m| b: {
80 // Some hypervisors are evil liars and will operate in long mode while identifying as a
81 // CPU model that never had long mode in reality. We've seen this in practice with
82 // athlon_xp (AMD K7). Catch this contradiction and fall back to using a generic CPU
83 // model with the features we detected earlier.
84 if (cpu.has(.x86, .@"64bit") and !Target.x86.featureSetHas(m.features, .@"64bit")) break :b;
85
80 cpu.model = m;86 cpu.model = m;
81 }87 }
82 }88 }