rust icon indicating copy to clipboard operation
rust copied to clipboard

Implement `-Z allow-partial-mitigations` (RFC 3855)

Open arielb1 opened this issue 1 month ago • 6 comments

This implements -Z allow-partial-mitigations as an unstable option, currently with support for control-flow-guard and stack-protector.

As a difference from the RFC, we have -Z allow-partial-mitigations=!foo rather than -Z deny-partial-mitigations=foo, since I couldn't find an easy way to have an allow/deny pair of flags where the latter flag wins.

To allow for stabilization, this is only enabled starting from the next edition. Maybe a better policy is possible (bikeshed).

r? @rcvalle

arielb1 avatar Nov 26 '25 18:11 arielb1

These commits modify compiler targets. (See the Target Tier Policy.)

rustbot avatar Nov 26 '25 18:11 rustbot

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
checking C++ file formatting
spellchecking files
building external tool typos from package [email protected]
finished building tool typos
error: `heirarchy` should be `hierarchy`
   ╭▸ compiler/rustc_session/src/options.rs:88:55
   │
88 │     // Enabled(false) should be the bottom of the Ord heirarchy
   ╰╴                                                      ━━━━━━━━━
rerun tidy with `--extra-checks=spellcheck --bless` to fix typos
tidy [extra_checks]: checks with external tool 'typos' failed
tidy [extra_checks]: FAIL
tidy: The following check failed: extra_checks
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/yarn --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1599:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1285:29

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:02:39
  local time: Wed Nov 26 18:56:32 UTC 2025
  network time: Wed, 26 Nov 2025 18:56:32 GMT
##[error]Process completed with exit code 1.

rust-log-analyzer avatar Nov 26 '25 18:11 rust-log-analyzer

To allow for stabilization, this is only enabled starting from the next edition. Maybe a better policy is possible (bikeshed).

I don't think we currently have any command line arguments who is edition depended, that would be a first.

Urgau avatar Nov 26 '25 19:11 Urgau

I don't think we currently have any command line arguments who is edition depended, that would be a first.

The behavior for -C control-flow-guard is in the RFC. Tho that RFC is not approved yet.

I do think we want to eventually make -C control-flow-guard enforcing, and I think we have to do that across an edition boundary.

arielb1 avatar Nov 26 '25 19:11 arielb1

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Nov 27 '25 16:11 rustbot

Reminder, once the PR becomes ready for a review, use @rustbot ready.

rustbot avatar Dec 05 '25 22:12 rustbot

Found a way to make -Z deny-partial-mitigations=foo work

@rustbot ready

arielb1 avatar Dec 10 '25 19:12 arielb1

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
finished building tool typos
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_metadata/src/creader.rs:28:28
   │
28 │ use rustc_session::config::enforcable_mitigations::DeniedPartialMitigationLevel;
   ╰╴                           ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_metadata/src/rmeta/encoder.rs:30:28
   │
30 │ use rustc_session::config::enforcable_mitigations::DeniedPartialMitigation;
   ╰╴                           ━━━━━━━━━━
error: `enforcable` should be `enforceable`
    ╭▸ compiler/rustc_metadata/src/rmeta/parameterized.rs:121:28
    │
121 │     rustc_session::config::enforcable_mitigations::DeniedPartialMitigation,
    ╰╴                           ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_metadata/src/rmeta/mod.rs:37:28
   │
37 │ use rustc_session::config::enforcable_mitigations::DeniedPartialMitigation;
   ╰╴                           ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_metadata/src/rmeta/decoder.rs:33:28
   │
33 │ use rustc_session::config::enforcable_mitigations::DeniedPartialMitigation;
   ╰╴                           ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_metadata/src/rmeta/decoder.rs:84:16
   │
84 │ /// The set of enforcable mitigations (RFC 3855) that are currently enabled for this crate
   ╰╴               ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_session/src/options.rs:22:20
   │
22 │ use crate::config::enforcable_mitigations::MitigationEnablement;
   ╰╴                   ━━━━━━━━━━
error: `enforcable` should be `enforceable`
   ╭▸ compiler/rustc_session/src/options.rs:87:9
   │
87 │ pub mod enforcable_mitigations;
   ╰╴        ━━━━━━━━━━
error: `enforcable` should be `enforceable`
    ╭▸ compiler/rustc_session/src/options.rs:889:16
    │
889 │         super::enforcable_mitigations::DeniedPartialMitigationKind::KINDS;
    ╰╴               ━━━━━━━━━━
error: `enforcable` should be `enforceable`
    ╭▸ compiler/rustc_session/src/options.rs:891:16
    │
891 │         super::enforcable_mitigations::DeniedPartialMitigationKind::KINDS;
    ╰╴               ━━━━━━━━━━
error: `enforcable` should be `enforceable`
    ╭▸ compiler/rustc_session/src/options.rs:898:24
    │
898 │     use crate::config::enforcable_mitigations::MitigationEnablement;
    ╰╴                       ━━━━━━━━━━
error: `enforcable` should be `enforceable`
  ╭▸ 
1 │ compiler/rustc_session/src/options/enforcable_mitigations.rs
  ╰╴                                   ━━━━━━━━━━
rerun tidy with `--extra-checks=spellcheck --bless` to fix typos
tidy [extra_checks]: checks with external tool 'typos' failed
tidy [extra_checks]: FAIL
tidy: The following check failed: extra_checks
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy /checkout /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo /checkout/obj/build 4 /node/bin/yarn --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1612:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1320:29

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:02:39
  local time: Wed Dec 10 19:19:35 UTC 2025
  network time: Wed, 10 Dec 2025 19:19:35 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

rust-log-analyzer avatar Dec 10 '25 19:12 rust-log-analyzer

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   --> compiler/rustc_metadata/src/rmeta/decoder.rs:165:1
    |
165 | pub(super) struct BlobDecodeContext<'a> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: the following other types implement trait `SpanDecoder`:
              CacheDecoder<'a, 'tcx>
              MemDecoder<'_>
              rmeta::decoder::MetadataDecodeContext<'a, 'tcx>
    = note: required for `DeniedPartialMitigation` to implement `rustc_serialize::Decodable<rmeta::decoder::BlobDecodeContext<'_>>`
note: required by a bound in `rmeta::decoder::<impl rmeta::LazyArray<T>>::decode`
   --> compiler/rustc_metadata/src/rmeta/decoder.rs:350:25
    |
345 |     fn decode<'a, 'tcx, M: Metadata<'a>>(
    |        ------ required by a bound in this associated function
...
350 |         T::Value<'tcx>: Decodable<M::Context>,
    |                         ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `rmeta::decoder::<impl LazyArray<T>>::decode`

error[E0277]: the trait bound `rmeta::decoder::BlobDecodeContext<'_>: SpanDecoder` is not satisfied
   --> compiler/rustc_metadata/src/rmeta/decoder.rs:971:10
    |
971 |     ) -> impl ExactSizeIterator<Item = DeniedPartialMitigation> {
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
972 |         self.denied_partial_mitigations.decode(metadata)
    |         ------------------------------------------------ return type was inferred to be `DecodeIterator<DeniedPartialMitigation, rmeta::decoder::BlobDecodeContext<'_>>` here
    |
help: the trait `SpanDecoder` is not implemented for `rmeta::decoder::BlobDecodeContext<'_>`
   --> compiler/rustc_metadata/src/rmeta/decoder.rs:165:1
    |
165 | pub(super) struct BlobDecodeContext<'a> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: the following other types implement trait `SpanDecoder`:
              CacheDecoder<'a, 'tcx>
              MemDecoder<'_>
              rmeta::decoder::MetadataDecodeContext<'a, 'tcx>
    = note: required for `DeniedPartialMitigation` to implement `rustc_serialize::Decodable<rmeta::decoder::BlobDecodeContext<'_>>`
note: required for `DecodeIterator<DeniedPartialMitigation, rmeta::decoder::BlobDecodeContext<'_>>` to implement `ExactSizeIterator`
   --> compiler/rustc_metadata/src/rmeta/decoder.rs:335:35
    |
335 | impl<D: Decoder, T: Decodable<D>> ExactSizeIterator for DecodeIterator<T, D> {
    |                     ------------  ^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^
    |                     |
    |                     unsatisfied trait bound introduced here

For more information about this error, try `rustc --explain E0277`.

rust-log-analyzer avatar Dec 10 '25 20:12 rust-log-analyzer

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

rustbot avatar Dec 10 '25 21:12 rustbot

Addressed rebase problems

arielb1 avatar Dec 10 '25 21:12 arielb1