ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.25k stars 2.57k forks source link

introduce the concept of conflicting CPU features #12227

Open andrewrk opened 2 years ago

andrewrk commented 2 years ago

Extracted from #12220.

$ stage3/bin/zig build-exe empty.zig -target x86_64-freestanding-none -mcpu=x86_64+soft_float
thread 427475 panic: Illegal instruction at address 0x5c6d154

As pointed out in https://github.com/llvm/llvm-project/issues/56351#issuecomment-1173063759, +x87 and +soft_float is a pair of contradictory options. However, Zig currently has no way to denote such contradictions, meaning that a user might easily run into that problem above, and not realize that they could do this:

$ stage3/bin/zig build-exe empty.zig -target x86_64-freestanding-none -mcpu=x86_64+soft_float-x87-sse2-sse
$

This issue is to introduce a field to std.Target.Cpu.Feature for storing conflicts with other features, and then do one of two things:

ominitay commented 2 years ago

Perhaps we should do both? If a feature conflicts with a default feature, then we know to disable the default feature. If two explicitly-provided features are passed, then we throw an error, since we can't know which feature the user actually intends.