Repository navigation
cpu_guard: build-time warning when a target feature has no guard row - #360
Conversation
build.rs compares CARGO_CFG_TARGET_FEATURE with the feature names in cpu_guard's x86_64 table and emits cargo:warning for any enabled feature the guard cannot check (baseline sse/sse2/x87 excluded). Such a feature is compiled in but never compared with the running CPU, so the guard passes a binary that can still die with SIGILL. The parser and filter live in src/cpu_guard_drift.rs, included by build.rs and by three tests: the parser reads exactly the 54 FEATURES rows, an avx10.1 input is reported, and table plus baseline reports nothing. Limits: stable rustc omits unstable features (avx10.x, amx-*) from the cfg, for the guard and the build script alike; cargo hides build-script warnings from git and registry dependencies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
|
Warning Review limit reachedYour organization has reached its usage spending cap. Adjust your spending cap in the billing tab. Next included review available in 47 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8f830597d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // toolchain bump lets LLVM enable a feature the table predates. | ||
|
|
||
| /// Features every x86_64 CPU has; the guard does not need rows for them. | ||
| const X86_64_BASELINE: &[&str] = &["sse", "sse2", "x87"]; |
There was a problem hiding this comment.
Exclude
crt-static from the CPU feature warning
On targets such as x86_64-unknown-linux-musl, CARGO_CFG_TARGET_FEATURE includes crt-static by default, even though it describes the C runtime linkage rather than a CPU capability. Because it is neither in the guard table nor this exclusion list, every such build warns that the CPU guard cannot detect a CPU lacking crt-static and asks for an impossible guard row. Add it to the non-checkable exclusions so static x86_64 targets do not receive this false warning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. rustc --print cfg --target x86_64-unknown-linux-musl lists crt-static, and of the default x86_64 sets (gnu, musl, msvc, darwin) it was the only feature that does not describe the CPU. Fixed in 9869e02 (not yet pushed): it is excluded alongside the baseline. The new test crt_static_is_not_a_cpu_feature was red before the exclusion (6ace106) and checks that a real missing row next to crt-static is still reported.
Generated by Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
…drift warning On musl targets crt-static is a default target feature (C-runtime linkage), so every musl build warned about it. It is now excluded; a feature without a row beside it is still reported. (codex P2) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
What
build.rscomparesCARGO_CFG_TARGET_FEATUREwith the feature names incpu_guard's x86_64FEATUREStable. If the build enables a feature that has no row, it emits acargo:warning. The x86_64 baseline (sse,sse2,x87) is excluded.Why
The guard checks each row with
cfg!(target_feature = ...). A feature that is compiled in but has no row is never compared with the running CPU, so the guard lets the binary through and it can still die with SIGILL. This happens when a toolchain bump lets LLVM enable a feature the table predates. The existingthe_table_covers_every_feature_a_cpu_model_can_enabletest checks a hand-copied list. This check reads the features the actual build enabled.Shape
src/cpu_guard_drift.rsholds the pure parser and filter.build.rsand a test module incpu_guard.rsboth include it withinclude!.build.rsis added to theCargo.tomlincludelist so it is packaged.Evidence
FEATURESrows, in order;avx10.1reports onlyavx10.1;=>check fails the parser test.-Ctarget-cpu=sapphirerapidsit stays silent.-Ctarget-cpu=sapphirerapidsit warns:cpu_guard has no row for enabled target features: amx-bf16, amx-int8, amx-tile, clflushopt, ermsb, lahfsahf, movdir64b, movdiri, prfchw.cargo clippy --lib --tests -- -D warningsandcargo fmt --checkare clean.Limits
CARGO_CFG_TARGET_FEATUREomits unstable features (avx10.x,amx-*). The guard'scfg!misses them the same way, so on stable the guard and this check are blind together.Open
The nightly output lists the features the guard cannot see. Adding rows for them (AMX needs XCR0 tile-state gating) is a separate change.
🤖 Generated with Claude Code
https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
Generated by Claude Code
Summary by CodeRabbit