Skip to content

Commit 8afb305

Browse files
authored
Rollup merge of rust-lang#73893 - ajpaverd:cfguard-stabilize, r=nikomatsakis
Stabilize control-flow-guard codegen option This is the stabilization PR discussed in rust-lang#68793. It converts the `-Z control-flow-guard` debugging option into a codegen option (`-C control-flow-guard`), and changes the associated tests.
2 parents dade0f1 + 31c7aae commit 8afb305

File tree

12 files changed

+24
-12
lines changed

12 files changed

+24
-12
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ impl<'a> Builder<'a> {
12391239
&& self.config.control_flow_guard
12401240
&& compiler.stage >= 1
12411241
{
1242-
rustflags.arg("-Zcontrol-flow-guard");
1242+
rustflags.arg("-Ccontrol-flow-guard");
12431243
}
12441244

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

src/doc/rustc/src/codegen-options/index.md

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ generated code, but may be slower to compile.
4242
The default value, if not specified, is 16 for non-incremental builds. For
4343
incremental builds the default is 256 which allows caching to be more granular.
4444

45+
## control-flow-guard
46+
47+
This flag controls whether LLVM enables the Windows [Control Flow
48+
Guard](https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard)
49+
platform security feature. This flag is currently ignored for non-Windows targets.
50+
It takes one of the following values:
51+
52+
* `y`, `yes`, `on`, `checks`, or no value: enable Control Flow Guard.
53+
* `nochecks`: emit Control Flow Guard metadata without runtime enforcement checks (this
54+
should only be used for testing purposes as it does not provide security enforcement).
55+
* `n`, `no`, `off`: do not enable Control Flow Guard (the default).
56+
4557
## debug-assertions
4658

4759
This flag lets you turn `cfg(debug_assertions)` [conditional

src/librustc_codegen_llvm/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub unsafe fn create_module(
190190

191191
// Control Flow Guard is currently only supported by the MSVC linker on Windows.
192192
if sess.target.target.options.is_like_msvc {
193-
match sess.opts.debugging_opts.control_flow_guard {
193+
match sess.opts.cg.control_flow_guard {
194194
CFGuard::Disabled => {}
195195
CFGuard::NoChecks => {
196196
// Set `cfguard=1` module flag to emit metadata only.

src/librustc_codegen_ssa/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
17001700
}
17011701

17021702
// OBJECT-FILES-NO, AUDIT-ORDER
1703-
if sess.opts.debugging_opts.control_flow_guard != CFGuard::Disabled {
1703+
if sess.opts.cg.control_flow_guard != CFGuard::Disabled {
17041704
cmd.control_flow_guard();
17051705
}
17061706

src/librustc_interface/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ fn test_codegen_options_tracking_hash() {
420420
// Make sure that changing a [TRACKED] option changes the hash.
421421
// This list is in alphabetical order.
422422
tracked!(code_model, Some(CodeModel::Large));
423+
tracked!(control_flow_guard, CFGuard::Checks);
423424
tracked!(debug_assertions, Some(true));
424425
tracked!(debuginfo, 0xdeadbeef);
425426
tracked!(embed_bitcode, false);
@@ -537,7 +538,6 @@ fn test_debugging_options_tracking_hash() {
537538
tracked!(binary_dep_depinfo, true);
538539
tracked!(chalk, true);
539540
tracked!(codegen_backend, Some("abc".to_string()));
540-
tracked!(control_flow_guard, CFGuard::Checks);
541541
tracked!(crate_attr, vec!["abc".to_string()]);
542542
tracked!(debug_macros, true);
543543
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 `-C 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

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
692692
"choose the code model to use (`rustc --print code-models` for details)"),
693693
codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
694694
"divide crate into N units to optimize in parallel"),
695+
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
696+
"use Windows Control Flow Guard (default: no)"),
695697
debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
696698
"explicitly enable the `cfg(debug_assertions)` directive"),
697699
debuginfo: usize = (0, parse_uint, [TRACKED],
@@ -809,8 +811,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
809811
"enable the experimental Chalk-based trait solving engine"),
810812
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
811813
"the backend to use"),
812-
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
813-
"use Windows Control Flow Guard (default: no)"),
814814
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
815815
"inject the given attribute in the crate"),
816816
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: -C control-flow-guard=checks
22
// only-msvc
33

44
#![crate_type = "lib"]

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=no
1+
// compile-flags: -C control-flow-guard=no
22
// only-msvc
33

44
#![crate_type = "lib"]

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: -C control-flow-guard=nochecks
22
// only-msvc
33

44
#![crate_type = "lib"]

src/test/codegen/cfguard-non-msvc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z control-flow-guard
1+
// compile-flags: -C control-flow-guard
22
// ignore-msvc
33

44
#![crate_type = "lib"]

src/test/ui/cfguard-run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// compile-flags: -Z control-flow-guard
2+
// compile-flags: -C control-flow-guard
33

44
pub fn main() {
55
println!("hello, world");

0 commit comments

Comments
 (0)