Skip to content

Commit e561031

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

12 files changed

Lines changed: 104 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: 21 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
};
@@ -2071,15 +2074,14 @@ pub mod parse {
20712074
true
20722075
}
20732076

2074-
pub(crate) fn parse_allow_partial_mitigations(
2077+
fn parse_partial_mitigations(
20752078
slot: &mut Vec<MitigationEnablement>,
20762079
v: Option<&str>,
2080+
enabled: bool,
20772081
) -> bool {
20782082
match v {
20792083
Some(s) => {
20802084
for sub in s.split(',') {
2081-
let (sub, enabled) =
2082-
if sub.starts_with('!') { (&sub[1..], false) } else { (sub, true) };
20832085
match sub.parse() {
20842086
Ok(kind) => slot.push(MitigationEnablement { kind, enabled }),
20852087
Err(_) => return false,
@@ -2090,6 +2092,20 @@ pub mod parse {
20902092
None => false,
20912093
}
20922094
}
2095+
2096+
pub(crate) fn parse_allow_partial_mitigations(
2097+
slot: &mut Vec<MitigationEnablement>,
2098+
v: Option<&str>,
2099+
) -> bool {
2100+
parse_partial_mitigations(slot, v, true)
2101+
}
2102+
2103+
pub(crate) fn parse_deny_partial_mitigations(
2104+
slot: &mut Vec<MitigationEnablement>,
2105+
v: Option<&str>,
2106+
) -> bool {
2107+
parse_partial_mitigations(slot, v, false)
2108+
}
20932109
}
20942110

20952111
options! {
@@ -2317,6 +2333,8 @@ options! {
23172333
"deduplicate identical diagnostics (default: yes)"),
23182334
default_visibility: Option<SymbolVisibility> = (None, parse_opt_symbol_visibility, [TRACKED],
23192335
"overrides the `default_visibility` setting of the target"),
2336+
deny_partial_mitigations: Vec<MitigationEnablement> = (Vec::new(), parse_deny_partial_mitigations, [UNTRACKED],
2337+
"Deny mitigations not enabled for all dependency crates (comma separated list)"),
23202338
dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
23212339
"in dep-info output, omit targets for tracking dependencies of the dep-info files \
23222340
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)