Skip to content

Commit dc3ca0f

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 fc3e911 + 83e6c0e commit dc3ca0f

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
@@ -463,7 +463,6 @@ fn test_debugging_options_tracking_hash() {
463463
untracked!(ast_json_noexpand, true);
464464
untracked!(borrowck, String::from("other"));
465465
untracked!(borrowck_stats, true);
466-
untracked!(control_flow_guard, CFGuard::Checks);
467466
untracked!(deduplicate_diagnostics, true);
468467
untracked!(dep_tasks, true);
469468
untracked!(dont_buffer_diagnostics, true);
@@ -537,6 +536,7 @@ fn test_debugging_options_tracking_hash() {
537536
tracked!(binary_dep_depinfo, true);
538537
tracked!(chalk, true);
539538
tracked!(codegen_backend, Some("abc".to_string()));
539+
tracked!(control_flow_guard, CFGuard::Checks);
540540
tracked!(crate_attr, vec!["abc".to_string()]);
541541
tracked!(debug_macros, true);
542542
tracked!(dep_info_omit_d_target, true);

src/librustc_session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub enum Strip {
8282
Symbols,
8383
}
8484

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

src/librustc_session/options.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ macro_rules! options {
251251
pub const parse_sanitizer: &str = "one of: `address`, `leak`, `memory` or `thread`";
252252
pub const parse_sanitizer_list: &str = "comma separated list of sanitizers";
253253
pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
254-
pub const parse_cfguard: &str = "either `disabled`, `nochecks`, or `checks`";
254+
pub const parse_cfguard: &str =
255+
"either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
255256
pub const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
256257
pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavor::one_of();
257258
pub const parse_optimization_fuel: &str = "crate=integer";
@@ -505,12 +506,24 @@ macro_rules! options {
505506
}
506507

507508
fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
508-
match v {
509-
Some("disabled") => *slot = CFGuard::Disabled,
510-
Some("nochecks") => *slot = CFGuard::NoChecks,
511-
Some("checks") => *slot = CFGuard::Checks,
512-
_ => return false,
509+
if v.is_some() {
510+
let mut bool_arg = None;
511+
if parse_opt_bool(&mut bool_arg, v) {
512+
*slot = if bool_arg.unwrap() {
513+
CFGuard::Checks
514+
} else {
515+
CFGuard::Disabled
516+
};
517+
return true
518+
}
513519
}
520+
521+
*slot = match v {
522+
None => CFGuard::Checks,
523+
Some("checks") => CFGuard::Checks,
524+
Some("nochecks") => CFGuard::NoChecks,
525+
Some(_) => return false,
526+
};
514527
true
515528
}
516529

@@ -806,8 +819,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
806819
"enable the experimental Chalk-based trait solving engine"),
807820
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
808821
"the backend to use"),
809-
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [UNTRACKED],
810-
"use Windows Control Flow Guard (`disabled`, `nochecks` or `checks`)"),
822+
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
823+
"use Windows Control Flow Guard (default: no)"),
811824
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
812825
"inject the given attribute in the crate"),
813826
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)