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
|
@ -62,7 +62,7 @@ pub fn sanitize_attrs<'ll>(
|
|||
) -> SmallVec<[&'ll Attribute; 4]> {
|
||||
let mut attrs = SmallVec::new();
|
||||
let enabled = cx.tcx.sess.opts.unstable_opts.sanitizer - no_sanitize;
|
||||
if enabled.contains(SanitizerSet::ADDRESS) {
|
||||
if enabled.contains(SanitizerSet::ADDRESS) || enabled.contains(SanitizerSet::KERNELADDRESS) {
|
||||
attrs.push(llvm::AttributeKind::SanitizeAddress.create_attr(cx.llcx));
|
||||
}
|
||||
if enabled.contains(SanitizerSet::MEMORY) {
|
||||
|
|
|
@ -442,6 +442,10 @@ pub(crate) unsafe fn llvm_optimize(
|
|||
sanitize_thread: config.sanitizer.contains(SanitizerSet::THREAD),
|
||||
sanitize_hwaddress: config.sanitizer.contains(SanitizerSet::HWADDRESS),
|
||||
sanitize_hwaddress_recover: config.sanitizer_recover.contains(SanitizerSet::HWADDRESS),
|
||||
sanitize_kernel_address: config.sanitizer.contains(SanitizerSet::KERNELADDRESS),
|
||||
sanitize_kernel_address_recover: config
|
||||
.sanitizer_recover
|
||||
.contains(SanitizerSet::KERNELADDRESS),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -482,6 +482,8 @@ pub struct SanitizerOptions {
|
|||
pub sanitize_thread: bool,
|
||||
pub sanitize_hwaddress: bool,
|
||||
pub sanitize_hwaddress_recover: bool,
|
||||
pub sanitize_kernel_address: bool,
|
||||
pub sanitize_kernel_address_recover: bool,
|
||||
}
|
||||
|
||||
/// LLVMRelocMode
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue