Rollup merge of #73893 - ajpaverd:cfguard-stabilize, r=nikomatsakis

Stabilize control-flow-guard codegen option

This is the stabilization PR discussed in #68793. It converts the `-Z control-flow-guard` debugging option into a codegen option (`-C control-flow-guard`), and changes the associated tests.
This commit is contained in:
Manish Goregaokar 2020-07-22 09:29:03 -07:00 committed by GitHub
commit 8afb305e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 24 additions and 12 deletions

View File

@ -1239,7 +1239,7 @@ pub fn cargo(
&& 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

View File

@ -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

View File

@ -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.

View File

@ -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();
}

View File

@ -420,6 +420,7 @@ macro_rules! tracked {
// 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 @@ macro_rules! tracked {
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);

View File

@ -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.

View File

@ -692,6 +692,8 @@ fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
"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 @@ fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
"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],

View File

@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=checks
// compile-flags: -C control-flow-guard=checks
// only-msvc
#![crate_type = "lib"]

View File

@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=no
// compile-flags: -C control-flow-guard=no
// only-msvc
#![crate_type = "lib"]

View File

@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard=nochecks
// compile-flags: -C control-flow-guard=nochecks
// only-msvc
#![crate_type = "lib"]

View File

@ -1,4 +1,4 @@
// compile-flags: -Z control-flow-guard
// compile-flags: -C control-flow-guard
// ignore-msvc
#![crate_type = "lib"]

View File

@ -1,5 +1,5 @@
// run-pass
// compile-flags: -Z control-flow-guard
// compile-flags: -C control-flow-guard
pub fn main() {
println!("hello, world");