about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Paverd <andrew.paverd@microsoft.com>2020-07-14 15:27:42 +0100
committerAndrew Paverd <andrew.paverd@microsoft.com>2020-07-14 15:27:42 +0100
commit31c7aae1136b4d80f0256e269ca8086fd3fbdddd (patch)
tree1cad41bdc1b23ac926a9ee9621e562dac3ea39f8
parentc724b67e1b474262917a5154d74e7072267593fe (diff)
downloadrust-31c7aae1136b4d80f0256e269ca8086fd3fbdddd.tar.gz
rust-31c7aae1136b4d80f0256e269ca8086fd3fbdddd.zip
Stabilize control-flow-guard codegen option
-rw-r--r--src/bootstrap/builder.rs2
-rw-r--r--src/doc/rustc/src/codegen-options/index.md12
-rw-r--r--src/librustc_codegen_llvm/context.rs2
-rw-r--r--src/librustc_codegen_ssa/back/link.rs2
-rw-r--r--src/librustc_interface/tests.rs2
-rw-r--r--src/librustc_session/config.rs2
-rw-r--r--src/librustc_session/options.rs4
-rw-r--r--src/test/codegen/cfguard-checks.rs2
-rw-r--r--src/test/codegen/cfguard-disabled.rs2
-rw-r--r--src/test/codegen/cfguard-nochecks.rs2
-rw-r--r--src/test/codegen/cfguard-non-msvc.rs2
-rw-r--r--src/test/ui/cfguard-run.rs2
12 files changed, 24 insertions, 12 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 557fb1aa550..276e7ac558e 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -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
diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md
index 0b4bb05c1db..35904e15d3f 100644
--- a/src/doc/rustc/src/codegen-options/index.md
+++ b/src/doc/rustc/src/codegen-options/index.md
@@ -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
diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs
index 21ba97d15a4..a07f6c64edc 100644
--- a/src/librustc_codegen_llvm/context.rs
+++ b/src/librustc_codegen_llvm/context.rs
@@ -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.
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs
index 3adaa07db91..7f3aa4be9fd 100644
--- a/src/librustc_codegen_ssa/back/link.rs
+++ b/src/librustc_codegen_ssa/back/link.rs
@@ -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();
     }
 
diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs
index 651a77912c6..dd09ce9e3dd 100644
--- a/src/librustc_interface/tests.rs
+++ b/src/librustc_interface/tests.rs
@@ -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);
diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs
index c5a866817cb..dbf5b7ece08 100644
--- a/src/librustc_session/config.rs
+++ b/src/librustc_session/config.rs
@@ -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.
diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs
index 2ad7d09cbf4..62f6fca9746 100644
--- a/src/librustc_session/options.rs
+++ b/src/librustc_session/options.rs
@@ -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],
diff --git a/src/test/codegen/cfguard-checks.rs b/src/test/codegen/cfguard-checks.rs
index 96a0a321199..571a2654bcb 100644
--- a/src/test/codegen/cfguard-checks.rs
+++ b/src/test/codegen/cfguard-checks.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Z control-flow-guard=checks
+// compile-flags: -C control-flow-guard=checks
 // only-msvc
 
 #![crate_type = "lib"]
diff --git a/src/test/codegen/cfguard-disabled.rs b/src/test/codegen/cfguard-disabled.rs
index 925e4e8e2d1..c3f8f411681 100644
--- a/src/test/codegen/cfguard-disabled.rs
+++ b/src/test/codegen/cfguard-disabled.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Z control-flow-guard=no
+// compile-flags: -C control-flow-guard=no
 // only-msvc
 
 #![crate_type = "lib"]
diff --git a/src/test/codegen/cfguard-nochecks.rs b/src/test/codegen/cfguard-nochecks.rs
index d7dc3d7e89e..3847c3e81ed 100644
--- a/src/test/codegen/cfguard-nochecks.rs
+++ b/src/test/codegen/cfguard-nochecks.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Z control-flow-guard=nochecks
+// compile-flags: -C control-flow-guard=nochecks
 // only-msvc
 
 #![crate_type = "lib"]
diff --git a/src/test/codegen/cfguard-non-msvc.rs b/src/test/codegen/cfguard-non-msvc.rs
index 4008f0187a0..6278a951e35 100644
--- a/src/test/codegen/cfguard-non-msvc.rs
+++ b/src/test/codegen/cfguard-non-msvc.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Z control-flow-guard
+// compile-flags: -C control-flow-guard
 // ignore-msvc
 
 #![crate_type = "lib"]
diff --git a/src/test/ui/cfguard-run.rs b/src/test/ui/cfguard-run.rs
index 21368fad3b0..3c4f9a1f5ee 100644
--- a/src/test/ui/cfguard-run.rs
+++ b/src/test/ui/cfguard-run.rs
@@ -1,5 +1,5 @@
 // run-pass
-// compile-flags: -Z control-flow-guard
+// compile-flags: -C control-flow-guard
 
 pub fn main() {
     println!("hello, world");