Skip to content

Commit 763f969

Browse files
authored
Rollup merge of rust-lang#73404 - ajpaverd:cfguard_syntax, r=Mark-Simulacrum
Update CFGuard syntax Update the naming and syntax of the control-flow-guard option, as discussed in rust-lang#68793. r? @Mark-Simulacrum
2 parents 7951305 + 83e6c0e commit 763f969

File tree

8 files changed

+33
-20
lines changed

8 files changed

+33
-20
lines changed

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ impl<'a> Builder<'a> {
12061206
);
12071207
}
12081208

1209-
// If Control Flow Guard is enabled, pass the `control_flow_guard=checks` flag to rustc
1209+
// If Control Flow Guard is enabled, pass the `control-flow-guard` flag to rustc
12101210
// when compiling the standard library, since this might be linked into the final outputs
12111211
// produced by rustc. Since this mitigation is only available on Windows, only enable it
12121212
// for the standard library in case the compiler is run on a non-Windows platform.
@@ -1217,7 +1217,7 @@ impl<'a> Builder<'a> {
12171217
&& self.config.control_flow_guard
12181218
&& compiler.stage >= 1
12191219
{
1220-
rustflags.arg("-Zcontrol_flow_guard=checks");
1220+
rustflags.arg("-Zcontrol-flow-guard");
12211221
}
12221222

12231223
// For `cargo doc` invocations, make rustdoc print the Rust version into the docs

src/doc/unstable-book/src/compiler-flags/control-flow-guard.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# `control_flow_guard`
1+
# `control-flow-guard`
22

33
The tracking issue for this feature is: [#68793](https://github.com/rust-lang/rust/issues/68793).
44

55
------------------------
66

7-
The rustc flag `-Z control_flow_guard=checks` enables the Windows [Control Flow Guard](https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard) (CFG) platform security feature.
7+
The rustc flag `-Z control-flow-guard` enables the Windows [Control Flow Guard](https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard) (CFG) platform security feature.
88

99
CFG is an exploit mitigation designed to enforce control-flow integrity for software running on supported Windows platforms (Windows 8.1 onwards). Specifically, CFG uses runtime checks to validate the target address of every indirect call/jump before allowing the call to complete.
1010

@@ -29,7 +29,7 @@ The CFG checks and metadata can potentially increase binary size and runtime ove
2929

3030
## Testing Control Flow Guard
3131

32-
The rustc flag `-Z control_flow_guard=nochecks` instructs LLVM to emit the list of valid call targets without inserting runtime checks. This flag should only be used for testing purposes as it does not provide security enforcement.
32+
The rustc flag `-Z control-flow-guard=nochecks` instructs LLVM to emit the list of valid call targets without inserting runtime checks. This flag should only be used for testing purposes as it does not provide security enforcement.
3333

3434

3535
## Control Flow Guard in libraries
@@ -44,14 +44,14 @@ For example:
4444
```cmd
4545
rustup toolchain install --force nightly
4646
rustup component add rust-src
47-
SET RUSTFLAGS=-Z control_flow_guard=checks
47+
SET RUSTFLAGS=-Z control-flow-guard
4848
cargo +nightly build -Z build-std --target x86_64-pc-windows-msvc
4949
```
5050

5151
```PowerShell
5252
rustup toolchain install --force nightly
5353
rustup component add rust-src
54-
$Env:RUSTFLAGS = "-Z control_flow_guard=checks"
54+
$Env:RUSTFLAGS = "-Z control-flow-guard"
5555
cargo +nightly build -Z build-std --target x86_64-pc-windows-msvc
5656
```
5757

src/librustc_interface/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ fn test_debugging_options_tracking_hash() {
465465
untracked!(ast_json_noexpand, true);
466466
untracked!(borrowck, String::from("other"));
467467
untracked!(borrowck_stats, true);
468-
untracked!(control_flow_guard, CFGuard::Checks);
469468
untracked!(deduplicate_diagnostics, true);
470469
untracked!(dep_tasks, true);
471470
untracked!(dont_buffer_diagnostics, true);
@@ -539,6 +538,7 @@ fn test_debugging_options_tracking_hash() {
539538
tracked!(binary_dep_depinfo, true);
540539
tracked!(chalk, true);
541540
tracked!(codegen_backend, Some("abc".to_string()));
541+
tracked!(control_flow_guard, CFGuard::Checks);
542542
tracked!(crate_attr, vec!["abc".to_string()]);
543543
tracked!(debug_macros, true);
544544
tracked!(dep_info_omit_d_target, true);

src/librustc_session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub enum Strip {
103103
Symbols,
104104
}
105105

106-
/// The different settings that the `-Z control_flow_guard` flag can have.
106+
/// The different settings that the `-Z control-flow-guard` flag can have.
107107
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
108108
pub enum CFGuard {
109109
/// Do not emit Control Flow Guard metadata or checks.

src/librustc_session/options.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ macro_rules! options {
250250
pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
251251
pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `leak`, `memory` or `thread`";
252252
pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
253-
pub const parse_cfguard: &str = "either `disabled`, `nochecks`, or `checks`";
253+
pub const parse_cfguard: &str =
254+
"either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
254255
pub const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
255256
pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavor::one_of();
256257
pub const parse_optimization_fuel: &str = "crate=integer";
@@ -495,12 +496,24 @@ macro_rules! options {
495496
}
496497

497498
fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
498-
match v {
499-
Some("disabled") => *slot = CFGuard::Disabled,
500-
Some("nochecks") => *slot = CFGuard::NoChecks,
501-
Some("checks") => *slot = CFGuard::Checks,
502-
_ => return false,
499+
if v.is_some() {
500+
let mut bool_arg = None;
501+
if parse_opt_bool(&mut bool_arg, v) {
502+
*slot = if bool_arg.unwrap() {
503+
CFGuard::Checks
504+
} else {
505+
CFGuard::Disabled
506+
};
507+
return true
508+
}
503509
}
510+
511+
*slot = match v {
512+
None => CFGuard::Checks,
513+
Some("checks") => CFGuard::Checks,
514+
Some("nochecks") => CFGuard::NoChecks,
515+
Some(_) => return false,
516+
};
504517
true
505518
}
506519

@@ -796,8 +809,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
796809
"enable the experimental Chalk-based trait solving engine"),
797810
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
798811
"the backend to use"),
799-
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [UNTRACKED],
800-
"use Windows Control Flow Guard (`disabled`, `nochecks` or `checks`)"),
812+
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
813+
"use Windows Control Flow Guard (default: no)"),
801814
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
802815
"inject the given attribute in the crate"),
803816
debug_macros: bool = (false, parse_bool, [TRACKED],

src/test/codegen/cfguard_checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z control_flow_guard=checks
1+
// compile-flags: -Z control-flow-guard=checks
22

33
#![crate_type = "lib"]
44

src/test/codegen/cfguard_disabled.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z control_flow_guard=disabled
1+
// compile-flags: -Z control-flow-guard=no
22

33
#![crate_type = "lib"]
44

src/test/codegen/cfguard_nochecks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z control_flow_guard=nochecks
1+
// compile-flags: -Z control-flow-guard=nochecks
22

33
#![crate_type = "lib"]
44

0 commit comments

Comments
 (0)