1 // RUN: echo "int extra_global;" > %t.extra-source.cpp 2 // RUN: echo "global:*ignorelisted_global*" > %t.ignorelist 3 // RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=address -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,ASAN 4 // RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=kernel-address -fsanitize-ignorelist=%t.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,KASAN 5 // The ignorelist file uses regexps, so Windows path backslashes. 6 // RUN: echo "src:%s" | sed -e 's/\\/\\\\/g' > %t.ignorelist-src 7 // RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=address -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST-SRC 8 // RUN: %clang_cc1 -include %t.extra-source.cpp -fsanitize=kernel-address -fsanitize-ignorelist=%t.ignorelist-src -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST-SRC 9 10 int global; 11 int dyn_init_global = global; 12 int __attribute__((no_sanitize("address"))) attributed_global; 13 int ignorelisted_global; 14 15 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section 16 extern "C" { 17 int __special_global; // KASAN - ignore globals with __-prefix 18 } 19 20 void func() { 21 static int static_var = 0; 22 const char *literal = "Hello, world!"; 23 } 24 25 // ASAN: sectioned_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32 26 // KASAN: sectioned_global{{.*}} global i32 27 // ASAN: @__special_global{{.*}} global { i32, [28 x i8] }{{.*}}, align 32 28 // KASAN: @__special_global{{.*}} global i32 29 30 /// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable attribute. 31 // CHECK-LABEL: define internal void @asan.module_ctor() #[[#ATTR:]] { 32 // ASAN-NEXT: call void @__asan_init 33 // ASAN-NEXT: call void @__asan_version_mismatch_check 34 // KASAN-NOT: call void @__asan_init 35 // KASAN-NOT: call void @__asan_version_mismatch_check 36 // ASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 7) 37 // KASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 5) 38 // CHECK-NEXT: ret void 39 40 // CHECK: define internal void @asan.module_dtor() #[[#ATTR]] { 41 // CHECK-NEXT: call void @__asan_unregister_globals 42 // CHECK-NEXT: ret void 43 44 // CHECK: attributes #[[#ATTR]] = { nounwind } 45 46 /// If -fasynchronous-unwind-tables, set the module flag "uwtable". ctor/dtor 47 /// will thus get the uwtable attribute. 48 // RUN: %clang_cc1 -emit-llvm -fsanitize=address -funwind-tables=2 -o - %s | FileCheck %s --check-prefixes=UWTABLE 49 // UWTABLE: define internal void @asan.module_dtor() #[[#ATTR:]] { 50 // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable } 51 // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 1} 52 53 // CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]} 54 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false} 55 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5} 56 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, i1 false} 57 // CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 10, i32 5} 58 // CHECK: ![[DYN_INIT_GLOBAL]] = !{{{.*}} ![[DYN_INIT_LOC:[0-9]+]], !"dyn_init_global", i1 true, i1 false} 59 // CHECK: ![[DYN_INIT_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 11, i32 5} 60 // CHECK: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true} 61 // CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true} 62 // CHECK: ![[SECTIONED_GLOBAL]] = !{{{.*}} ![[SECTIONED_GLOBAL_LOC:[0-9]+]], !"sectioned_global", i1 false, i1 false} 63 // CHECK: ![[SECTIONED_GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 15, i32 50} 64 // CHECK: ![[SPECIAL_GLOBAL]] = !{{{.*}} ![[SPECIAL_GLOBAL_LOC:[0-9]+]], !"__special_global", i1 false, i1 false} 65 // CHECK: ![[SPECIAL_GLOBAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 17, i32 5} 66 // CHECK: ![[STATIC_VAR]] = !{{{.*}} ![[STATIC_LOC:[0-9]+]], !"static_var", i1 false, i1 false} 67 // CHECK: ![[STATIC_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 21, i32 14} 68 // CHECK: ![[LITERAL]] = !{{{.*}} ![[LITERAL_LOC:[0-9]+]], !"<string literal>", i1 false, i1 false} 69 // CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}asan-globals.cpp", i32 22, i32 25} 70 71 // IGNORELIST-SRC: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], ![[DYN_INIT_GLOBAL:[0-9]+]], ![[ATTR_GLOBAL:[0-9]+]], ![[IGNORELISTED_GLOBAL:[0-9]+]], ![[SECTIONED_GLOBAL:[0-9]+]], ![[SPECIAL_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]} 72 // IGNORELIST-SRC: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], !"extra_global", i1 false, i1 false} 73 // IGNORELIST-SRC: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5} 74 // IGNORELIST-SRC: ![[GLOBAL]] = !{{{.*}} null, null, i1 false, i1 true} 75 // IGNORELIST-SRC: ![[DYN_INIT_GLOBAL]] = !{{{.*}} null, null, i1 true, i1 true} 76 // IGNORELIST-SRC: ![[ATTR_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true} 77 // IGNORELIST-SRC: ![[IGNORELISTED_GLOBAL]] = !{{{.*}}, null, null, i1 false, i1 true} 78 // IGNORELIST-SRC: ![[SECTIONED_GLOBAL]] = !{{{.*}} null, null, i1 false, i1 true} 79 // IGNORELIST-SRC: ![[SPECIAL_GLOBAL]] = !{{{.*}} null, null, i1 false, i1 true} 80 // IGNORELIST-SRC: ![[STATIC_VAR]] = !{{{.*}} null, null, i1 false, i1 true} 81 // IGNORELIST-SRC: ![[LITERAL]] = !{{{.*}} null, null, i1 false, i1 true} 82