diff options
| author | Arlie Davis <ardavis@microsoft.com> | 2023-11-17 10:05:38 -0800 |
|---|---|---|
| committer | Arlie Davis <ardavis@microsoft.com> | 2023-11-21 13:41:23 -0800 |
| commit | e11d8d147b94043d54d0a6c8ff0bdb0568b794ca (patch) | |
| tree | 8d209b5b6c776646a481e11225ccf41cf314ecbf /src/bootstrap | |
| parent | 2f8d81f9dbac6b8df982199f69da04a4c8357227 (diff) | |
Add support for generating the EHCont section
In the future Windows will enable Control-flow Enforcement Technology (CET aka Shadow Stacks). To protect the path where the context is updated during exception handling, the binary is required to enumerate valid unwind entrypoints in a dedicated section which is validated when the context is being set during exception handling. The required support for EHCONT has already been merged into LLVM, long ago. This change adds the Rust codegen option to enable it. Reference: * https://reviews.llvm.org/D40223 This also adds a new `ehcont-guard` option to the bootstrap config which enables EHCont Guard when building std.
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/core/builder.rs | 12 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 3 | ||||
| -rw-r--r-- | src/bootstrap/src/tests/builder.rs | 2 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index c755324df1a..de35e97848a 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1964,6 +1964,12 @@ impl<'a> Builder<'a> { rustflags.arg("-Ccontrol-flow-guard"); } + // Same for EHCont Guard (this is not combined with the previous if-statement to make + // merges with upstream easier). + if cfg!(windows) && mode == Mode::Std && self.config.ehcont_guard && compiler.stage >= 1 { + rustflags.arg("-Cehcont-guard"); + } + // For `cargo doc` invocations, make rustdoc print the Rust version into the docs // This replaces spaces with tabs because RUSTDOCFLAGS does not // support arguments with regular spaces. Hopefully someday Cargo will @@ -2172,7 +2178,11 @@ impl<'a> Builder<'a> { } // Only execute if it's supposed to run as default - if desc.default && should_run.is_really_default() { self.ensure(step) } else { None } + if desc.default && should_run.is_really_default() { + self.ensure(step) + } else { + None + } } /// Checks if any of the "should_run" paths is in the `Builder` paths. diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index fa8b0b20cec..9ef90798590 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -248,6 +248,7 @@ pub struct Config { pub local_rebuild: bool, pub jemalloc: bool, pub control_flow_guard: bool, + pub ehcont_guard: bool, // dist misc pub dist_sign_folder: Option<PathBuf>, @@ -1019,6 +1020,7 @@ define_config! { test_compare_mode: Option<bool> = "test-compare-mode", llvm_libunwind: Option<String> = "llvm-libunwind", control_flow_guard: Option<bool> = "control-flow-guard", + ehcont_guard: Option<bool> = "ehcont-guard", new_symbol_mangling: Option<bool> = "new-symbol-mangling", profile_generate: Option<String> = "profile-generate", profile_use: Option<String> = "profile-use", @@ -1452,6 +1454,7 @@ impl Config { config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit; set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); set(&mut config.control_flow_guard, rust.control_flow_guard); + set(&mut config.ehcont_guard, rust.ehcont_guard); config.llvm_libunwind_default = rust .llvm_libunwind .map(|v| v.parse().expect("failed to parse rust.llvm-libunwind")); diff --git a/src/bootstrap/src/tests/builder.rs b/src/bootstrap/src/tests/builder.rs index 96139f7b099..744015e8e82 100644 --- a/src/bootstrap/src/tests/builder.rs +++ b/src/bootstrap/src/tests/builder.rs @@ -1,6 +1,6 @@ use super::*; -use crate::core::config::{Config, DryRun, TargetSelection}; use crate::core::build_steps::doc::DocumentationFormat; +use crate::core::config::{Config, DryRun, TargetSelection}; use std::thread; fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config { |
