Skip to content

Stabilize control-flow-guard codegen option #73893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
@@ -1231,7 +1231,7 @@ impl<'a> Builder<'a> {
&& self.config.control_flow_guard
&& compiler.stage >= 1
{
rustflags.arg("-Zcontrol-flow-guard");
rustflags.arg("-Ccontrol-flow-guard");
}

// For `cargo doc` invocations, make rustdoc print the Rust version into the docs
12 changes: 12 additions & 0 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
@@ -42,6 +42,18 @@ generated code, but may be slower to compile.
The default value, if not specified, is 16 for non-incremental builds. For
incremental builds the default is 256 which allows caching to be more granular.

## control-flow-guard

This flag controls whether LLVM enables the Windows [Control Flow
Guard](https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard)
platform security feature. This flag is currently ignored for non-Windows targets.
It takes one of the following values:

* `y`, `yes`, `on`, `checks`, or no value: enable Control Flow Guard.
* `nochecks`: emit Control Flow Guard metadata without runtime enforcement checks (this
should only be used for testing purposes as it does not provide security enforcement).
* `n`, `no`, `off`: do not enable Control Flow Guard (the default).

## debug-assertions

This flag lets you turn `cfg(debug_assertions)` [conditional
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ pub unsafe fn create_module(

// Control Flow Guard is currently only supported by the MSVC linker on Windows.
if sess.target.target.options.is_like_msvc {
match sess.opts.debugging_opts.control_flow_guard {
match sess.opts.cg.control_flow_guard {
CFGuard::Disabled => {}
CFGuard::NoChecks => {
// Set `cfguard=1` module flag to emit metadata only.
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
@@ -1700,7 +1700,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
}

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

2 changes: 1 addition & 1 deletion src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
@@ -420,6 +420,7 @@ fn test_codegen_options_tracking_hash() {
// Make sure that changing a [TRACKED] option changes the hash.
// This list is in alphabetical order.
tracked!(code_model, Some(CodeModel::Large));
tracked!(control_flow_guard, CFGuard::Checks);
tracked!(debug_assertions, Some(true));
tracked!(debuginfo, 0xdeadbeef);
tracked!(embed_bitcode, false);
@@ -537,7 +538,6 @@ fn test_debugging_options_tracking_hash() {
tracked!(binary_dep_depinfo, true);
tracked!(chalk, true);
tracked!(codegen_backend, Some("abc".to_string()));
tracked!(control_flow_guard, CFGuard::Checks);
tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(debug_macros, true);
tracked!(dep_info_omit_d_target, true);
2 changes: 1 addition & 1 deletion src/librustc_session/config.rs
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ pub enum Strip {
Symbols,
}

/// The different settings that the `-Z control-flow-guard` flag can have.
/// The different settings that the `-C control-flow-guard` flag can have.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
pub enum CFGuard {
/// Do not emit Control Flow Guard metadata or checks.
4 changes: 2 additions & 2 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
@@ -692,6 +692,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"choose the code model to use (`rustc --print code-models` for details)"),
codegen_units: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
"divide crate into N units to optimize in parallel"),
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
"use Windows Control Flow Guard (default: no)"),
debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
"explicitly enable the `cfg(debug_assertions)` directive"),
debuginfo: usize = (0, parse_uint, [TRACKED],
@@ -809,8 +811,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"enable the experimental Chalk-based trait solving engine"),
codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
"the backend to use"),
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
"use Windows Control Flow Guard (default: no)"),
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
"inject the given attribute in the crate"),
debug_macros: bool = (false, parse_bool, [TRACKED],
2 changes: 1 addition & 1 deletion src/test/codegen/cfguard-checks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=checks
// compile-flags: -C control-flow-guard=checks
// only-msvc

#![crate_type = "lib"]
2 changes: 1 addition & 1 deletion src/test/codegen/cfguard-disabled.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=no
// compile-flags: -C control-flow-guard=no
// only-msvc

#![crate_type = "lib"]
2 changes: 1 addition & 1 deletion src/test/codegen/cfguard-nochecks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=nochecks
// compile-flags: -C control-flow-guard=nochecks
// only-msvc

#![crate_type = "lib"]
2 changes: 1 addition & 1 deletion src/test/codegen/cfguard-non-msvc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard
// compile-flags: -C control-flow-guard
// ignore-msvc

#![crate_type = "lib"]
2 changes: 1 addition & 1 deletion src/test/ui/cfguard-run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z control-flow-guard
// compile-flags: -C control-flow-guard

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