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.
This commit is contained in:
Arlie Davis 2023-11-17 10:05:38 -08:00
parent 2f8d81f9db
commit e11d8d147b
10 changed files with 76 additions and 2 deletions

View file

@ -350,6 +350,15 @@ pub unsafe fn create_module<'ll>(
1,
);
}
// Set module flag to enable Windows EHCont Guard (/guard:ehcont).
if sess.opts.cg.ehcont_guard {
llvm::LLVMRustAddModuleFlag(
llmod,
llvm::LLVMModFlagBehavior::Warning,
"ehcontguard\0".as_ptr() as *const _,
1,
)
}
// Insert `llvm.ident` metadata.
//