Auto merge of #99679 - repnop:kernel-address-sanitizer, r=cuviper
Add `kernel-address` sanitizer support for freestanding targets This PR adds support for KASan (kernel address sanitizer) instrumentation in freestanding targets. I included the minimal set of `x86_64-unknown-none`, `riscv64{imac, gc}-unknown-none-elf`, and `aarch64-unknown-none` but there's likely other targets it can be added to. (`linux_kernel_base.rs`?) KASan uses the address sanitizer attributes but has the `CompileKernel` parameter set to `true` in the pass creation.
This commit is contained in:
commit
fabfd1fd93
18 changed files with 142 additions and 12 deletions
|
@ -15,7 +15,7 @@ pub fn target() -> Target {
|
|||
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
|
||||
linker: Some("rust-lld".into()),
|
||||
features: "+v8a,+strict-align,+neon,+fp-armv8".into(),
|
||||
supported_sanitizers: SanitizerSet::KCFI,
|
||||
supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS,
|
||||
relocation_model: RelocModel::Static,
|
||||
disable_redzone: true,
|
||||
max_atomic_width: Some(128),
|
||||
|
|
|
@ -812,6 +812,7 @@ bitflags::bitflags! {
|
|||
const MEMTAG = 1 << 6;
|
||||
const SHADOWCALLSTACK = 1 << 7;
|
||||
const KCFI = 1 << 8;
|
||||
const KERNELADDRESS = 1 << 9;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -824,6 +825,7 @@ impl SanitizerSet {
|
|||
SanitizerSet::ADDRESS => "address",
|
||||
SanitizerSet::CFI => "cfi",
|
||||
SanitizerSet::KCFI => "kcfi",
|
||||
SanitizerSet::KERNELADDRESS => "kernel-address",
|
||||
SanitizerSet::LEAK => "leak",
|
||||
SanitizerSet::MEMORY => "memory",
|
||||
SanitizerSet::MEMTAG => "memtag",
|
||||
|
@ -866,6 +868,7 @@ impl IntoIterator for SanitizerSet {
|
|||
SanitizerSet::SHADOWCALLSTACK,
|
||||
SanitizerSet::THREAD,
|
||||
SanitizerSet::HWADDRESS,
|
||||
SanitizerSet::KERNELADDRESS,
|
||||
]
|
||||
.iter()
|
||||
.copied()
|
||||
|
@ -2341,6 +2344,7 @@ impl Target {
|
|||
Some("address") => SanitizerSet::ADDRESS,
|
||||
Some("cfi") => SanitizerSet::CFI,
|
||||
Some("kcfi") => SanitizerSet::KCFI,
|
||||
Some("kernel-address") => SanitizerSet::KERNELADDRESS,
|
||||
Some("leak") => SanitizerSet::LEAK,
|
||||
Some("memory") => SanitizerSet::MEMORY,
|
||||
Some("memtag") => SanitizerSet::MEMTAG,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use crate::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy};
|
||||
use crate::spec::{RelocModel, Target, TargetOptions};
|
||||
|
||||
use super::SanitizerSet;
|
||||
|
||||
pub fn target() -> Target {
|
||||
Target {
|
||||
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
|
||||
|
@ -20,6 +22,7 @@ pub fn target() -> Target {
|
|||
code_model: Some(CodeModel::Medium),
|
||||
emit_debug_gdb_scripts: false,
|
||||
eh_frame_header: false,
|
||||
supported_sanitizers: SanitizerSet::KERNELADDRESS,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::spec::{Cc, CodeModel, LinkerFlavor, Lld, PanicStrategy};
|
||||
use crate::spec::{RelocModel, Target, TargetOptions};
|
||||
use crate::spec::{RelocModel, SanitizerSet, Target, TargetOptions};
|
||||
|
||||
pub fn target() -> Target {
|
||||
Target {
|
||||
|
@ -19,6 +19,7 @@ pub fn target() -> Target {
|
|||
code_model: Some(CodeModel::Medium),
|
||||
emit_debug_gdb_scripts: false,
|
||||
eh_frame_header: false,
|
||||
supported_sanitizers: SanitizerSet::KERNELADDRESS,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn target() -> Target {
|
|||
features:
|
||||
"-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float"
|
||||
.into(),
|
||||
supported_sanitizers: SanitizerSet::KCFI,
|
||||
supported_sanitizers: SanitizerSet::KCFI | SanitizerSet::KERNELADDRESS,
|
||||
disable_redzone: true,
|
||||
panic_strategy: PanicStrategy::Abort,
|
||||
code_model: Some(CodeModel::Kernel),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue