diff options
author | Mitch Phillips <31459023+hctim@users.noreply.github.com> | 2022-07-13 18:39:26 +0300 |
---|---|---|
committer | Mitch Phillips <31459023+hctim@users.noreply.github.com> | 2022-07-13 18:54:41 +0300 |
commit | 90e5a8ac475fa3c2fa7c22a341e798d6f7356b54 (patch) | |
tree | a0b13d99de440f2e29b9981def322f6948fabdd6 /clang | |
parent | 4f281fa2a86b1806ec3143373795d8eac559e37f (diff) |
Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.
For MTE globals, we should have clang emit the attribute for all GV's
that it creates, and then use that in the upcoming AArch64 global
tagging IR pass. We need a positive attribute for this sanitizer (rather
than implicit sanitization of all globals) because it needs to interact
with other parts of LLVM, including:
1. Suppressing certain global optimisations (like merging),
2. Emitting extra directives by the ASM writer, and
3. Putting extra information in the symbol table entries.
While this does technically make the LLVM IR / bitcode format
non-backwards-compatible, nobody should have used this attribute yet,
because it's a no-op.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D128950
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/SanitizerMetadata.cpp | 6 | ||||
-rw-r--r-- | clang/test/CodeGen/memtag-globals.cpp | 47 | ||||
-rw-r--r-- | clang/test/CodeGen/sanitizer-special-case-list-globals.c | 30 |
3 files changed, 44 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp index 0c752304b13d..7848cf012633 100644 --- a/clang/lib/CodeGen/SanitizerMetadata.cpp +++ b/clang/lib/CodeGen/SanitizerMetadata.cpp @@ -60,8 +60,10 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, Meta.NoHWAddress |= CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty); - Meta.NoMemtag |= NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); - Meta.NoMemtag |= CGM.isInNoSanitizeList( + Meta.Memtag |= + static_cast<bool>(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals); + Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag); + Meta.Memtag &= !CGM.isInNoSanitizeList( FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty); Meta.IsDynInit = IsDynInit && !Meta.NoAddress && diff --git a/clang/test/CodeGen/memtag-globals.cpp b/clang/test/CodeGen/memtag-globals.cpp index 2eee42de283c..da801cc9d633 100644 --- a/clang/test/CodeGen/memtag-globals.cpp +++ b/clang/test/CodeGen/memtag-globals.cpp @@ -17,23 +17,30 @@ void func() { const char *literal = "Hello, world!"; } -// CHECK: @{{.*}}extra_global{{.*}} = -// CHECK-NOT: no_sanitize_memtag -// CHECK: @{{.*}}global{{.*}} = -// CHECK-NOT: no_sanitize_memtag -// CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// CHECK: @{{.*}}static_var{{.*}} = -// CHECK-NOT: no_sanitize_memtag -// CHECK: @{{.*}} = {{.*}} c"Hello, world!\00" -// CHECK-NOT: no_sanitize_memtag - -// IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} global -// IGNORELIST-NOT: no_sanitize_memtag -// IGNORELIST: @{{.*}}global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// IGNORELIST: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// IGNORELIST: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// IGNORELIST: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}}, no_sanitize_memtag -// IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}, no_sanitize_memtag +// CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag +// CHECK: @{{.*}}global{{.*}} ={{.*}} sanitize_memtag + +// CHECK: @{{.*}}attributed_global{{.*}} = +// CHECK-NOT: sanitize_memtag +// CHECK: @{{.*}}disable_instrumentation_global{{.*}} = +// CHECK-NOT: sanitize_memtag +// CHECK: @{{.*}}ignorelisted_global{{.*}} = +// CHECK-NOT: sanitize_memtag + +// CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag +// CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag + +// IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag + +// IGNORELIST: @{{.*}}global{{.*}} = +// IGNORELIST-NOT: sanitize_memtag +// IGNORELIST: @{{.*}}attributed_global{{.*}} = +// IGNORELIST-NOT: sanitize_memtag +// IGNORELIST: @{{.*}}disable_instrumentation_global{{.*}} = +// IGNORELIST-NOT: sanitize_memtag +// IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} = +// IGNORELIST-NOT: sanitize_memtag +// IGNORELIST: @{{.*}}static_var{{.*}} = +// IGNORELIST-NOT: sanitize_memtag +// IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} +// IGNORELIST-NOT: sanitize_memtag diff --git a/clang/test/CodeGen/sanitizer-special-case-list-globals.c b/clang/test/CodeGen/sanitizer-special-case-list-globals.c index 5497aef22168..a688b00630ed 100644 --- a/clang/test/CodeGen/sanitizer-special-case-list-globals.c +++ b/clang/test/CodeGen/sanitizer-special-case-list-globals.c @@ -17,12 +17,9 @@ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \ // RUN: | FileCheck %s --check-prefix=HWASAN -/// TODO(hctim): Move over to memtag-globals when it's implemented. For now -/// though, it's fine, the frontend still annotates based on any memtag sanitizer -/// being used. -// RUN: %clang_cc1 -fsanitize=memtag-heap -triple=aarch64-linux-android31 -emit-llvm %s -o -\ +// RUN: %clang_cc1 -fsanitize=memtag-globals -triple=aarch64-linux-android31 \ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \ -// RUN: | FileCheck %s --check-prefix=MEMTAG +// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=MEMTAG /// Check that the '[cfi-vcall|cfi-icall] src:*' rule in the ignorelist doesn't change /// anything for ASan. @@ -46,11 +43,12 @@ // RUN: -fsanitize-ignorelist=%S/Inputs/sanitizer-special-case-list-globals.txt \ // RUN: | FileCheck %s --check-prefix=NONE -// NONE: @always_ignored ={{.*}} global -// NONE-NOT: no_sanitize -// ASAN: @always_ignored ={{.*}} global {{.*}}, no_sanitize_address -// HWASAN: @always_ignored ={{.*}} global {{.*}}, no_sanitize_hwaddress -// MEMTAG: @always_ignored ={{.*}} global {{.*}}, no_sanitize_memtag +// NONE: @always_ignored ={{.*}} global +// NONE-NOT: no_sanitize +// ASAN: @always_ignored ={{.*}} global {{.*}}, no_sanitize_address +// HWASAN: @always_ignored ={{.*}} global {{.*}}, no_sanitize_hwaddress +// MEMTAG: @always_ignored ={{.*}} global +// MEMTAG-NOT: sanitize_memtag unsigned always_ignored; // NONE: @hwasan_ignored ={{.*}} global @@ -58,8 +56,7 @@ unsigned always_ignored; // ASAN: @hwasan_ignored ={{.*}} global // ASAN-NOT: no_sanitize_address // HWASAN: @hwasan_ignored ={{.*}} global {{.*}}, no_sanitize_hwaddress -// MEMTAG: @hwasan_ignored ={{.*}} global -// MEMTAG-NOT: no_sanitize_memtag +// MEMTAG: @hwasan_ignored ={{.*}} global {{.*}} sanitize_memtag unsigned hwasan_ignored; // NONE: @asan_ignored ={{.*}} global @@ -67,8 +64,7 @@ unsigned hwasan_ignored; // ASAN: @asan_ignored ={{.*}} global {{.*}}, no_sanitize_address // HWASAN: @asan_ignored.hwasan = {{.*}} global // HWASAN-NOT: no_sanitize_hwaddress -// MEMTAG: @asan_ignored ={{.*}} global -// MEMTAG-NOT: no_sanitize_memtag +// MEMTAG: @asan_ignored ={{.*}} global {{.*}} sanitize_memtag unsigned asan_ignored; // NONE: @memtag_ignored ={{.*}} global @@ -77,7 +73,8 @@ unsigned asan_ignored; // ASAN-NOT: no_sanitize_address // HWASAN: @memtag_ignored.hwasan = {{.*}} global // HWASAN-NOT: no_sanitize_hwaddress -// MEMTAG: @memtag_ignored ={{.*}} global {{.*}}, no_sanitize_memtag +// MEMTAG: @memtag_ignored ={{.*}} global +// MEMTAG-NOT: sanitize_memtag unsigned memtag_ignored; // NONE: @never_ignored ={{.*}} global @@ -86,6 +83,5 @@ unsigned memtag_ignored; // ASAN-NOT: no_sanitize_address // HWASAN: @never_ignored.hwasan ={{.*}} global // HWASAN-NOT: no_sanitize_hwaddress -// MEMTAG: @never_ignored ={{.*}} global -// MEMTAG-NOT: no_sanitize_memtag +// MEMTAG: @never_ignored ={{.*}} global {{.*}} sanitize_memtag unsigned never_ignored; |