-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SanitizerBinaryMetadata] Respect no_sanitize("thread") function attr…
…ibute To avoid false positives, respect no_sanitize("thread") when atomics metadata is enabled. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D148694
- Loading branch information
Showing
3 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --version 2 | ||
// RUN: %clang_cc1 -O -fexperimental-sanitize-metadata=covered -fexperimental-sanitize-metadata=atomics -fexperimental-sanitize-metadata=uar -triple x86_64-gnu-linux -x c -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK | ||
|
||
//. | ||
// CHECK: @__start_sanmd_covered = extern_weak hidden global ptr | ||
// CHECK: @__stop_sanmd_covered = extern_weak hidden global ptr | ||
// CHECK: @__start_sanmd_atomics = extern_weak hidden global ptr | ||
// CHECK: @__stop_sanmd_atomics = extern_weak hidden global ptr | ||
// CHECK: @llvm.used = appending global [4 x ptr] [ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_dtor, ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_dtor], section "llvm.metadata" | ||
// CHECK: @llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_ctor, ptr @__sanitizer_metadata_covered.module_ctor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_ctor, ptr @__sanitizer_metadata_atomics.module_ctor }] | ||
// CHECK: @llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_covered.module_dtor, ptr @__sanitizer_metadata_covered.module_dtor }, { i32, ptr, ptr } { i32 2, ptr @__sanitizer_metadata_atomics.module_dtor, ptr @__sanitizer_metadata_atomics.module_dtor }] | ||
//. | ||
// CHECK: Function Attrs: mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) | ||
// CHECK-LABEL: define dso_local void @escape | ||
// CHECK-SAME: (ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !pcsections !2 { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: ret void | ||
// | ||
__attribute__((noinline, not_tail_called)) void escape(const volatile void *p) { | ||
static const volatile void *sink; | ||
sink = p; | ||
} | ||
|
||
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) | ||
// CHECK-LABEL: define dso_local i32 @normal_function | ||
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !pcsections !4 { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8 | ||
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6:![0-9]+]] | ||
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10 | ||
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) | ||
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11:![0-9]+]] | ||
// CHECK-NEXT: ret i32 [[TMP0]] | ||
// | ||
int normal_function(int *x, int *y) { | ||
__atomic_store_n(x, 1, __ATOMIC_RELAXED); | ||
escape(&x); | ||
return *y; | ||
} | ||
|
||
// CHECK: Function Attrs: disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) | ||
// CHECK-LABEL: define dso_local i32 @test_disable_sanitize_instrumentation | ||
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8 | ||
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]] | ||
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4 | ||
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) | ||
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]] | ||
// CHECK-NEXT: ret i32 [[TMP0]] | ||
// | ||
__attribute__((disable_sanitizer_instrumentation)) int test_disable_sanitize_instrumentation(int *x, int *y) { | ||
__atomic_store_n(x, 1, __ATOMIC_RELAXED); | ||
escape(&x); | ||
return *y; | ||
} | ||
|
||
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) | ||
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_thread | ||
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3:[0-9]+]] !pcsections !13 { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8 | ||
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]] | ||
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10 | ||
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) | ||
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]] | ||
// CHECK-NEXT: ret i32 [[TMP0]] | ||
// | ||
__attribute__((no_sanitize("thread"))) int test_no_sanitize_thread(int *x, int *y) { | ||
__atomic_store_n(x, 1, __ATOMIC_RELAXED); | ||
escape(&x); | ||
return *y; | ||
} | ||
|
||
// CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) | ||
// CHECK-LABEL: define dso_local i32 @test_no_sanitize_all | ||
// CHECK-SAME: (ptr noundef [[X:%.*]], ptr nocapture noundef readonly [[Y:%.*]]) local_unnamed_addr #[[ATTR3]] !pcsections !13 { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8 | ||
// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 8, !tbaa [[TBAA6]] | ||
// CHECK-NEXT: store atomic i32 1, ptr [[X]] monotonic, align 4, !pcsections !10 | ||
// CHECK-NEXT: notail call void @escape(ptr noundef nonnull [[X_ADDR]]) | ||
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Y]], align 4, !tbaa [[TBAA11]] | ||
// CHECK-NEXT: ret i32 [[TMP0]] | ||
// | ||
__attribute__((no_sanitize("all"))) int test_no_sanitize_all(int *x, int *y) { | ||
__atomic_store_n(x, 1, __ATOMIC_RELAXED); | ||
escape(&x); | ||
return *y; | ||
} | ||
//. | ||
// CHECK: attributes #0 = { mustprogress nofree noinline norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } | ||
// CHECK: attributes #1 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } | ||
// CHECK: attributes #2 = { disable_sanitizer_instrumentation mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } | ||
// CHECK: attributes #3 = { mustprogress nofree norecurse nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) "min-legal-vector-width"="0" "no-trapping-math"="true" "no_sanitize_thread" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" } | ||
// CHECK: attributes #4 = { nounwind } | ||
//. | ||
// CHECK: !2 = !{!"sanmd_covered!C", !3} | ||
// CHECK: !3 = !{i64 0} | ||
// CHECK: !4 = !{!"sanmd_covered!C", !5} | ||
// CHECK: !5 = !{i64 3} | ||
// CHECK: !6 = !{!7, !7, i64 0} | ||
// CHECK: !7 = !{!"any pointer", !8, i64 0} | ||
// CHECK: !8 = !{!"omnipotent char", !9, i64 0} | ||
// CHECK: !9 = !{!"Simple C/C++ TBAA"} | ||
// CHECK: !10 = !{!"sanmd_atomics!C"} | ||
// CHECK: !11 = !{!12, !12, i64 0} | ||
// CHECK: !12 = !{!"int", !8, i64 0} | ||
// CHECK: !13 = !{!"sanmd_covered!C", !14} | ||
// CHECK: !14 = !{i64 2} | ||
//. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters