Skip to content

Commit b833b59

Browse files
author
Ariel Ben-Yehuda
committed
use -Z deny-partial-mitigations instead of -Z allow-partial-mitigations=!
1 parent fc6f81c commit b833b59

13 files changed

Lines changed: 198 additions & 75 deletions

compiler/rustc_metadata/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ metadata_missing_native_library =
156156
metadata_mitigation_less_strict_in_dependency =
157157
your program uses the crate `{$extern_crate}`, that is not compiled with `{$mitigation_name}{$mitigation_level}` enabled
158158
.note = recompile `{$extern_crate}` with `{$mitigation_name}{$mitigation_level}` enabled, or use `-Z allow-partial-mitigations={$mitigation_name}` to allow creating an artifact that has the mitigation only partially enabled
159-
.help = it is possible to disable `-Z allow-partial-mitigations={$mitigation_name}` via `-Z allow-partial-mitigations=!{$mitigation_name}`
159+
.help = it is possible to disable `-Z allow-partial-mitigations={$mitigation_name}` via `-Z deny-partial-mitigations={$mitigation_name}`
160160
161161
metadata_multiple_candidates =
162162
multiple candidates for `{$flavor}` dependency `{$crate_name}` found

compiler/rustc_session/src/options.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,9 @@ impl CodegenOptions {
690690
// Sometimes different options need to build a common structure.
691691
// That structure can be kept in one of the options' fields, the others become dummy.
692692
macro_rules! redirect_field {
693+
($cg:ident.deny_partial_mitigations) => {
694+
$cg.allow_partial_mitigations
695+
};
693696
($cg:ident.link_arg) => {
694697
$cg.link_args
695698
};
@@ -884,6 +887,8 @@ mod desc {
884887
pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
885888
pub(crate) const parse_allow_partial_mitigations: &str =
886889
super::enforcable_mitigations::DeniedPartialMitigationKind::KINDS;
890+
pub(crate) const parse_deny_partial_mitigations: &str =
891+
super::enforcable_mitigations::DeniedPartialMitigationKind::KINDS;
887892
}
888893

889894
pub mod parse {
@@ -2059,15 +2064,14 @@ pub mod parse {
20592064
true
20602065
}
20612066

2062-
pub(crate) fn parse_allow_partial_mitigations(
2067+
fn parse_partial_mitigations(
20632068
slot: &mut Vec<MitigationEnablement>,
20642069
v: Option<&str>,
2070+
enabled: bool,
20652071
) -> bool {
20662072
match v {
20672073
Some(s) => {
20682074
for sub in s.split(',') {
2069-
let (sub, enabled) =
2070-
if sub.starts_with('!') { (&sub[1..], false) } else { (sub, true) };
20712075
match sub.parse() {
20722076
Ok(kind) => slot.push(MitigationEnablement { kind, enabled }),
20732077
Err(_) => return false,
@@ -2078,6 +2082,20 @@ pub mod parse {
20782082
None => false,
20792083
}
20802084
}
2085+
2086+
pub(crate) fn parse_allow_partial_mitigations(
2087+
slot: &mut Vec<MitigationEnablement>,
2088+
v: Option<&str>,
2089+
) -> bool {
2090+
parse_partial_mitigations(slot, v, true)
2091+
}
2092+
2093+
pub(crate) fn parse_deny_partial_mitigations(
2094+
slot: &mut Vec<MitigationEnablement>,
2095+
v: Option<&str>,
2096+
) -> bool {
2097+
parse_partial_mitigations(slot, v, false)
2098+
}
20812099
}
20822100

20832101
options! {
@@ -2305,6 +2323,8 @@ options! {
23052323
"deduplicate identical diagnostics (default: yes)"),
23062324
default_visibility: Option<SymbolVisibility> = (None, parse_opt_symbol_visibility, [TRACKED],
23072325
"overrides the `default_visibility` setting of the target"),
2326+
deny_partial_mitigations: Vec<MitigationEnablement> = (Vec::new(), parse_deny_partial_mitigations, [UNTRACKED],
2327+
"Deny mitigations not enabled for all dependency crates (comma separated list)"),
23082328
dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
23092329
"in dep-info output, omit targets for tracking dependencies of the dep-info files \
23102330
themselves (default: no)"),

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ ignore-nvptx64 stack protector is not supported
44
//@ ignore-wasm32-unknown-unknown stack protector is not supported
55
//@ edition: 2024
6-
//@ compile-flags: -Z allow-partial-mitigations=!control-flow-guard -C control-flow-guard=on
6+
//@ compile-flags: -Z deny-partial-mitigations=control-flow-guard -C control-flow-guard=on
77

88
// check that in edition 2024, it is still possible to explicitly
99
// disallow partial mitigations (in edition=future, they are

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations-current-edition.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: your program uses the crate `std`, that is not compiled with `control-flo
44
LL | fn main() {}
55
| ^
66
|
7-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
7+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
88
= note: recompile `std` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
99

1010
error: your program uses the crate `core`, that is not compiled with `control-flow-guard` enabled
@@ -13,7 +13,7 @@ error: your program uses the crate `core`, that is not compiled with `control-fl
1313
LL | fn main() {}
1414
| ^
1515
|
16-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
16+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
1717
= note: recompile `core` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
1818

1919
error: your program uses the crate `alloc`, that is not compiled with `control-flow-guard` enabled
@@ -22,7 +22,7 @@ error: your program uses the crate `alloc`, that is not compiled with `control-f
2222
LL | fn main() {}
2323
| ^
2424
|
25-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
25+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
2626
= note: recompile `alloc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
2727

2828
error: your program uses the crate `compiler_builtins`, that is not compiled with `control-flow-guard` enabled
@@ -31,7 +31,7 @@ error: your program uses the crate `compiler_builtins`, that is not compiled wit
3131
LL | fn main() {}
3232
| ^
3333
|
34-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
34+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
3535
= note: recompile `compiler_builtins` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
3636

3737
error: your program uses the crate `libc`, that is not compiled with `control-flow-guard` enabled
@@ -40,7 +40,7 @@ error: your program uses the crate `libc`, that is not compiled with `control-fl
4040
LL | fn main() {}
4141
| ^
4242
|
43-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
43+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
4444
= note: recompile `libc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
4545

4646
error: aborting due to 5 previous errors

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations.both.stderr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled
2-
--> $DIR/err-allow-partial-mitigations.rs:13:1
2+
--> $DIR/err-allow-partial-mitigations.rs:14:1
33
|
44
LL | fn main() {}
55
| ^
66
|
7-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
7+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
88
= note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
99

1010
error: your program uses the crate `std`, that is not compiled with `control-flow-guard` enabled
11-
--> $DIR/err-allow-partial-mitigations.rs:13:1
11+
--> $DIR/err-allow-partial-mitigations.rs:14:1
1212
|
1313
LL | fn main() {}
1414
| ^
1515
|
16-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
16+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
1717
= note: recompile `std` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
1818

1919
error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled
20-
--> $DIR/err-allow-partial-mitigations.rs:13:1
20+
--> $DIR/err-allow-partial-mitigations.rs:14:1
2121
|
2222
LL | fn main() {}
2323
| ^
2424
|
25-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
25+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
2626
= note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
2727

2828
error: your program uses the crate `core`, that is not compiled with `control-flow-guard` enabled
29-
--> $DIR/err-allow-partial-mitigations.rs:13:1
29+
--> $DIR/err-allow-partial-mitigations.rs:14:1
3030
|
3131
LL | fn main() {}
3232
| ^
3333
|
34-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
34+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
3535
= note: recompile `core` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
3636

3737
error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled
38-
--> $DIR/err-allow-partial-mitigations.rs:13:1
38+
--> $DIR/err-allow-partial-mitigations.rs:14:1
3939
|
4040
LL | fn main() {}
4141
| ^
4242
|
43-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
43+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
4444
= note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
4545

4646
error: your program uses the crate `alloc`, that is not compiled with `control-flow-guard` enabled
47-
--> $DIR/err-allow-partial-mitigations.rs:13:1
47+
--> $DIR/err-allow-partial-mitigations.rs:14:1
4848
|
4949
LL | fn main() {}
5050
| ^
5151
|
52-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
52+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
5353
= note: recompile `alloc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
5454

5555
error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled
56-
--> $DIR/err-allow-partial-mitigations.rs:13:1
56+
--> $DIR/err-allow-partial-mitigations.rs:14:1
5757
|
5858
LL | fn main() {}
5959
| ^
6060
|
61-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
61+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
6262
= note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
6363

6464
error: your program uses the crate `compiler_builtins`, that is not compiled with `control-flow-guard` enabled
65-
--> $DIR/err-allow-partial-mitigations.rs:13:1
65+
--> $DIR/err-allow-partial-mitigations.rs:14:1
6666
|
6767
LL | fn main() {}
6868
| ^
6969
|
70-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
70+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
7171
= note: recompile `compiler_builtins` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
7272

7373
error: your program uses the crate `libc`, that is not compiled with `stack-protector=all` enabled
74-
--> $DIR/err-allow-partial-mitigations.rs:13:1
74+
--> $DIR/err-allow-partial-mitigations.rs:14:1
7575
|
7676
LL | fn main() {}
7777
| ^
7878
|
79-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
79+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
8080
= note: recompile `libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
8181

8282
error: your program uses the crate `libc`, that is not compiled with `control-flow-guard` enabled
83-
--> $DIR/err-allow-partial-mitigations.rs:13:1
83+
--> $DIR/err-allow-partial-mitigations.rs:14:1
8484
|
8585
LL | fn main() {}
8686
| ^
8787
|
88-
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z allow-partial-mitigations=!control-flow-guard`
88+
= help: it is possible to disable `-Z allow-partial-mitigations=control-flow-guard` via `-Z deny-partial-mitigations=control-flow-guard`
8989
= note: recompile `libc` with `control-flow-guard` enabled, or use `-Z allow-partial-mitigations=control-flow-guard` to allow creating an artifact that has the mitigation only partially enabled
9090

9191
error: aborting due to 10 previous errors

tests/ui/allow-partial-mitigations/err-allow-partial-mitigations.disable.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
error: your program uses the crate `std`, that is not compiled with `stack-protector=all` enabled
2-
--> $DIR/err-allow-partial-mitigations.rs:13:1
2+
--> $DIR/err-allow-partial-mitigations.rs:14:1
33
|
44
LL | fn main() {}
55
| ^
66
|
7-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
7+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
88
= note: recompile `std` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
99

1010
error: your program uses the crate `core`, that is not compiled with `stack-protector=all` enabled
11-
--> $DIR/err-allow-partial-mitigations.rs:13:1
11+
--> $DIR/err-allow-partial-mitigations.rs:14:1
1212
|
1313
LL | fn main() {}
1414
| ^
1515
|
16-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
16+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
1717
= note: recompile `core` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
1818

1919
error: your program uses the crate `alloc`, that is not compiled with `stack-protector=all` enabled
20-
--> $DIR/err-allow-partial-mitigations.rs:13:1
20+
--> $DIR/err-allow-partial-mitigations.rs:14:1
2121
|
2222
LL | fn main() {}
2323
| ^
2424
|
25-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
25+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
2626
= note: recompile `alloc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
2727

2828
error: your program uses the crate `compiler_builtins`, that is not compiled with `stack-protector=all` enabled
29-
--> $DIR/err-allow-partial-mitigations.rs:13:1
29+
--> $DIR/err-allow-partial-mitigations.rs:14:1
3030
|
3131
LL | fn main() {}
3232
| ^
3333
|
34-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
34+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
3535
= note: recompile `compiler_builtins` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
3636

3737
error: your program uses the crate `libc`, that is not compiled with `stack-protector=all` enabled
38-
--> $DIR/err-allow-partial-mitigations.rs:13:1
38+
--> $DIR/err-allow-partial-mitigations.rs:14:1
3939
|
4040
LL | fn main() {}
4141
| ^
4242
|
43-
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z allow-partial-mitigations=!stack-protector`
43+
= help: it is possible to disable `-Z allow-partial-mitigations=stack-protector` via `-Z deny-partial-mitigations=stack-protector`
4444
= note: recompile `libc` with `stack-protector=all` enabled, or use `-Z allow-partial-mitigations=stack-protector` to allow creating an artifact that has the mitigation only partially enabled
4545

4646
error: aborting due to 5 previous errors

0 commit comments

Comments
 (0)