-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing module flags for CFI and KCFI sanitizers
Set the cfi-normalize-integers and kcfi-offset module flags when Control-Flow Integrity sanitizers are used, so functions generated by the LLVM backend use the same CFI/KCFI options as rustc. cfi-normalize-integers tells LLVM to also use integer normalization for generated functions when -Zsanitizer-cfi-normalize-integers is used. kcfi-offset specifies the number of prefix nops between the KCFI type hash and the function entry when -Z patchable-function-entry is used. Note that LLVM assumes all indirectly callable functions use the same number of prefix NOPs with -Zsanitizer=kcfi.
- Loading branch information
1 parent
6b678c5
commit 40f1d9d
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/codegen/sanitizer/cfi/add-cfi-normalize-integers-flag.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Verifies that "cfi-normalize-integers" module flag is added. | ||
// | ||
//@ needs-sanitizer-cfi | ||
//@ compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi -Zsanitizer-cfi-normalize-integers | ||
|
||
#![crate_type = "lib"] | ||
|
||
pub fn foo() {} | ||
|
||
// CHECK: !{{[0-9]+}} = !{i32 4, !"cfi-normalize-integers", i32 1} |
21 changes: 21 additions & 0 deletions
21
tests/codegen/sanitizer/kcfi/add-cfi-normalize-integers-flag.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Verifies that "cfi-normalize-integers" module flag is added. | ||
// | ||
//@ revisions: aarch64 x86_64 | ||
//@ [aarch64] compile-flags: --target aarch64-unknown-none | ||
//@ [aarch64] needs-llvm-components: aarch64 | ||
//@ [x86_64] compile-flags: --target x86_64-unknown-none | ||
//@ [x86_64] needs-llvm-components: x86 | ||
//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers | ||
|
||
#![feature(no_core, lang_items)] | ||
#![crate_type = "lib"] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
pub fn foo() {} | ||
|
||
// CHECK: !{{[0-9]+}} = !{i32 4, !"cfi-normalize-integers", i32 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Verifies that "kcfi-offset" module flag is added. | ||
// | ||
//@ revisions: aarch64 x86_64 | ||
//@ [aarch64] compile-flags: --target aarch64-unknown-none | ||
//@ [aarch64] needs-llvm-components: aarch64 | ||
//@ [x86_64] compile-flags: --target x86_64-unknown-none | ||
//@ [x86_64] needs-llvm-components: x86 | ||
//@ compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi -Z patchable-function-entry=4,3 | ||
|
||
#![feature(no_core, lang_items, patchable_function_entry)] | ||
#![crate_type = "lib"] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
pub fn foo() {} | ||
|
||
// CHECK: !{{[0-9]+}} = !{i32 4, !"kcfi-offset", i32 3} |