Skip to content

Commit d956109

Browse files
committed
Make sanitize(kernel_address = ..) attribute work with -Zsanitize=address
To do it the same as how clang disables address sanitizer, we now disable ASAN on sanitize(kernel_address = "off") and KASAN on sanitize(address = "off"). The same was added to clang in https://reviews.llvm.org/D44981.
1 parent 4292cb6 commit d956109

19 files changed

+78
-205
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ codegen_ssa_invalid_monomorphization_unsupported_symbol = invalid monomorphizati
166166
codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size = invalid monomorphization of `{$name}` intrinsic: unsupported {$symbol} from `{$in_ty}` with element `{$in_elem}` of size `{$size}` to `{$ret_ty}`
167167
168168
codegen_ssa_invalid_sanitize = invalid argument for `sanitize`
169-
.note = expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
169+
.note = expected one of: `address`, `kernel_address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow_call_stack`, or `thread`
170170
171171
codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`, only `windows` and `console` are allowed
172172

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,13 @@ fn parse_sanitize_attr(tcx: TyCtxt<'_>, attr: &Attribute) -> SanitizerSet {
535535
};
536536
let segments = set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
537537
match segments.as_slice() {
538-
[sym::address] if set.value_str() == Some(sym::off) => {
538+
// Similar to clang, sanitize(address = ..) and
539+
// sanitize(kernel_address = ..) control both ASan and KASan
540+
// Source: https://reviews.llvm.org/D44981.
541+
[sym::address] | [sym::kernel_address] if set.value_str() == Some(sym::off) => {
539542
result |= SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
540543
}
541-
[sym::address] if set.value_str() == Some(sym::on) => {
544+
[sym::address] | [sym::kernel_address] if set.value_str() == Some(sym::on) => {
542545
result &= !SanitizerSet::ADDRESS;
543546
result &= !SanitizerSet::KERNELADDRESS;
544547
}

compiler/rustc_feature/src/removed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ declare_features! (
192192
(removed, no_debug, "1.43.0", Some(29721), Some("removed due to lack of demand"), 69667),
193193
// Allows the use of `no_sanitize` attribute.
194194
/// The feature was renamed to `sanitize` and the attribute to `#[sanitize(xyz = "on|off")]`
195-
(removed, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 1234),
195+
(removed, no_sanitize, "CURRENT_RUSTC_VERSION", Some(39699), Some(r#"renamed to sanitize(xyz = "on|off")"#), 142681),
196196
/// Note: this feature was previously recorded in a separate
197197
/// `STABLE_REMOVED` list because it, uniquely, was once stable but was
198198
/// then removed. But there was no utility storing it separately, so now

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ passes_object_lifetime_err =
553553
{$repr}
554554
555555
passes_only_has_effect_on =
556-
`#[{$attr_name}]` only has an effect on {$passes_only_has_effect_on ->
556+
`#[{$attr_name}]` only has an effect on {$target_name ->
557557
[function] functions
558558
[module] modules
559559
[trait_implementation_block] trait implementation blocks

compiler/rustc_passes/src/check_attr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
313313
[sym::diagnostic, sym::on_unimplemented, ..] => {
314314
self.check_diagnostic_on_unimplemented(attr.span(), hir_id, target)
315315
}
316-
[sym::coverage, ..] => self.check_coverage(attr.span(), span, target),
317316
[sym::sanitize, ..] => {
318317
self.check_sanitize(attr, span, target)
319318
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ symbols! {
12471247
iterator,
12481248
iterator_collect_fn,
12491249
kcfi,
1250+
kernel_address,
12501251
keylocker_x86,
12511252
keyword,
12521253
kind,

tests/codegen-llvm/sanitizer/cfi/emit-type-checks-attr-no-sanitize.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/codegen-llvm/sanitizer/kcfi/emit-kcfi-operand-bundle-attr-no-sanitize.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/codegen-llvm/sanitizer/no-sanitize-inlining.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)