-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add LLVM KCFI support to the Rust compiler #105109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -828,6 +828,7 @@ symbols! { | |
item_like_imports, | ||
iter, | ||
iter_repeat, | ||
kcfi, | ||
keyword, | ||
kind, | ||
kreg, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ | |
// | ||
// For example, `-C target-cpu=cortex-a53`. | ||
|
||
use super::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions}; | ||
use super::{ | ||
Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, SanitizerSet, Target, TargetOptions, | ||
}; | ||
|
||
pub fn target() -> Target { | ||
let opts = TargetOptions { | ||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes), | ||
linker: Some("rust-lld".into()), | ||
features: "+strict-align,+neon,+fp-armv8".into(), | ||
supported_sanitizers: SanitizerSet::KCFI, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that a trivial PR just adding this line to the target spec, or is there more work required? |
||
relocation_model: RelocModel::Static, | ||
disable_redzone: true, | ||
max_atomic_width: Some(128), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Verifies that "kcfi" module flag is added. | ||
// | ||
// needs-sanitizer-kcfi | ||
// compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi | ||
|
||
#![crate_type="lib"] | ||
|
||
pub fn foo() { | ||
} | ||
|
||
// CHECK: !{{[0-9]+}} = !{i32 4, !"kcfi", i32 1} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Verifies that KCFI type metadata for functions are emitted. | ||
// | ||
// 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: | ||
// compile-flags: -Cno-prepopulate-passes -Zsanitizer=kcfi | ||
|
||
#![crate_type="lib"] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
|
||
#[lang="sized"] | ||
trait Sized { } | ||
#[lang="copy"] | ||
trait Copy { } | ||
|
||
impl Copy for i32 {} | ||
|
||
pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 { | ||
// CHECK-LABEL: define{{.*}}foo | ||
// FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 | ||
// CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE1:[0-9]+]] | ||
// CHECK: call i32 %f(i32 %arg){{.*}}[ "kcfi"(i32 -1666898348) ] | ||
f(arg) | ||
} | ||
|
||
pub fn bar(f: fn(i32, i32) -> i32, arg1: i32, arg2: i32) -> i32 { | ||
// CHECK-LABEL: define{{.*}}bar | ||
// FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 | ||
// CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE2:[0-9]+]] | ||
// CHECK: call i32 %f(i32 %arg1, i32 %arg2){{.*}}[ "kcfi"(i32 -1789026986) ] | ||
f(arg1, arg2) | ||
} | ||
|
||
pub fn baz(f: fn(i32, i32, i32) -> i32, arg1: i32, arg2: i32, arg3: i32) -> i32 { | ||
// CHECK-LABEL: define{{.*}}baz | ||
// FIXME(rcvalle): Change <unknown kind #36> to !kcfi_type when Rust is updated to LLVM 16 | ||
// CHECK-SAME: {{.*}}!<unknown kind #36> ![[TYPE3:[0-9]+]] | ||
// CHECK: call i32 %f(i32 %arg1, i32 %arg2, i32 %arg3){{.*}}[ "kcfi"(i32 1248878270) ] | ||
f(arg1, arg2, arg3) | ||
} | ||
|
||
// CHECK: ![[TYPE1]] = !{i32 653723426} | ||
// CHECK: ![[TYPE2]] = !{i32 412174924} | ||
// CHECK: ![[TYPE3]] = !{i32 -636668840} |
Uh oh!
There was an error while loading. Please reload this page.