Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa
Add LLVM CFI support to the Rust compiler This PR adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue #89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you, `@eddyb` and `@pcc,` for all the help!
This commit is contained in:
commit
a8f6e614f8
35 changed files with 473 additions and 39 deletions
|
@ -351,8 +351,7 @@ mod desc {
|
|||
pub const parse_panic_strategy: &str = "either `unwind` or `abort`";
|
||||
pub const parse_opt_panic_strategy: &str = parse_panic_strategy;
|
||||
pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
|
||||
pub const parse_sanitizers: &str =
|
||||
"comma separated list of sanitizers: `address`, `hwaddress`, `leak`, `memory` or `thread`";
|
||||
pub const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `hwaddress`, `leak`, `memory` or `thread`";
|
||||
pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
|
||||
pub const parse_cfguard: &str =
|
||||
"either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
|
||||
|
@ -605,6 +604,7 @@ mod parse {
|
|||
for s in v.split(',') {
|
||||
*slot |= match s {
|
||||
"address" => SanitizerSet::ADDRESS,
|
||||
"cfi" => SanitizerSet::CFI,
|
||||
"leak" => SanitizerSet::LEAK,
|
||||
"memory" => SanitizerSet::MEMORY,
|
||||
"thread" => SanitizerSet::THREAD,
|
||||
|
|
|
@ -672,6 +672,9 @@ impl Session {
|
|||
pub fn is_nightly_build(&self) -> bool {
|
||||
self.opts.unstable_features.is_nightly_build()
|
||||
}
|
||||
pub fn is_sanitizer_cfi_enabled(&self) -> bool {
|
||||
self.opts.debugging_opts.sanitizer.contains(SanitizerSet::CFI)
|
||||
}
|
||||
pub fn overflow_checks(&self) -> bool {
|
||||
self.opts
|
||||
.cg
|
||||
|
@ -1398,6 +1401,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
|
|||
disable it using `-C target-feature=-crt-static`",
|
||||
);
|
||||
}
|
||||
|
||||
// LLVM CFI requires LTO.
|
||||
if sess.is_sanitizer_cfi_enabled() {
|
||||
if sess.opts.cg.lto == config::LtoCli::Unspecified
|
||||
|| sess.opts.cg.lto == config::LtoCli::No
|
||||
|| sess.opts.cg.lto == config::LtoCli::Thin
|
||||
{
|
||||
sess.err("`-Zsanitizer=cfi` requires `-Clto`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds data on the current incremental compilation session, if there is one.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue