aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Darwin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-02 19:18:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-02 19:18:27 +0000
commit316d58822dada9440bd06ecfc758dcc2364d617c (patch)
treefe72ec2e6ce9a360dda74d9d57f7acdb0e3c39d6 /test/asan/TestCases/Darwin
parent0230fcf22fe7d19f03d981c9c2c59a3db0b72ea5 (diff)
downloadsrc-316d58822dada9440bd06ecfc758dcc2364d617c.tar.gz
src-316d58822dada9440bd06ecfc758dcc2364d617c.zip
Vendor import of compiler-rt trunk r290819:vendor/compiler-rt/compiler-rt-trunk-r290819
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=311120 svn path=/vendor/compiler-rt/compiler-rt-trunk-r290819/; revision=311121; tag=vendor/compiler-rt/compiler-rt-trunk-r290819
Diffstat (limited to 'test/asan/TestCases/Darwin')
-rw-r--r--test/asan/TestCases/Darwin/cstring_section.c17
-rw-r--r--test/asan/TestCases/Darwin/dead-strip.c22
-rw-r--r--test/asan/TestCases/Darwin/dump_registers.cc26
-rw-r--r--test/asan/TestCases/Darwin/malloc_destroy_zone.cc21
-rw-r--r--test/asan/TestCases/Darwin/odr-lto.cc45
5 files changed, 131 insertions, 0 deletions
diff --git a/test/asan/TestCases/Darwin/cstring_section.c b/test/asan/TestCases/Darwin/cstring_section.c
new file mode 100644
index 000000000000..952d6fcdd465
--- /dev/null
+++ b/test/asan/TestCases/Darwin/cstring_section.c
@@ -0,0 +1,17 @@
+// Test that AddressSanitizer moves constant strings into a separate section.
+
+// RUN: %clang_asan -c -o %t %s
+// RUN: llvm-objdump -s %t | FileCheck %s
+
+// Check that "Hello.\n" is in __asan_cstring and not in __cstring.
+// CHECK: Contents of section __asan_cstring:
+// CHECK: 48656c6c {{.*}} Hello.
+// CHECK: Contents of section __const:
+// CHECK-NOT: 48656c6c {{.*}} Hello.
+// CHECK: Contents of section __cstring:
+// CHECK-NOT: 48656c6c {{.*}} Hello.
+
+int main(int argc, char *argv[]) {
+ argv[0] = "Hello.\n";
+ return 0;
+}
diff --git a/test/asan/TestCases/Darwin/dead-strip.c b/test/asan/TestCases/Darwin/dead-strip.c
new file mode 100644
index 000000000000..f87a5e52b1cf
--- /dev/null
+++ b/test/asan/TestCases/Darwin/dead-strip.c
@@ -0,0 +1,22 @@
+// Test that AddressSanitizer does not re-animate dead globals when dead
+// stripping is turned on.
+//
+// This test verifies that an out-of-bounds access on a global variable is
+// detected after dead stripping has been performed. This proves that the
+// runtime is able to register globals in the __DATA,__asan_globals section.
+
+// REQUIRES: osx-ld64-live_support
+// RUN: %clang_asan -mmacosx-version-min=10.11 -Xlinker -dead_strip -o %t %s
+// RUN: llvm-nm -format=posix %t | FileCheck --check-prefix NM-CHECK %s
+// RUN: not %run %t 2>&1 | FileCheck --check-prefix ASAN-CHECK %s
+
+int alive[1] = {};
+int dead[1] = {};
+// NM-CHECK: {{^_alive }}
+// NM-CHECK-NOT: {{^_dead }}
+
+int main(int argc, char *argv[]) {
+ alive[argc] = 0;
+ // ASAN-CHECK: {{0x.* is located 0 bytes to the right of global variable}}
+ return 0;
+}
diff --git a/test/asan/TestCases/Darwin/dump_registers.cc b/test/asan/TestCases/Darwin/dump_registers.cc
new file mode 100644
index 000000000000..884ad2ed44c0
--- /dev/null
+++ b/test/asan/TestCases/Darwin/dump_registers.cc
@@ -0,0 +1,26 @@
+// Check that ASan dumps the CPU registers on a SIGSEGV.
+
+// RUN: %clangxx_asan %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdio.h>
+
+int main() {
+ fprintf(stderr, "Hello\n");
+ char *ptr;
+
+ if (sizeof(void *) == 8)
+ ptr = (char *)0x6666666666666666;
+ else if (sizeof(void *) == 4)
+ ptr = (char *)0x55555555;
+ else
+ assert(0 && "Your computer is weird.");
+
+ char c = *ptr; // BOOM
+ // CHECK: ERROR: AddressSanitizer: SEGV
+ // CHECK: Register values:
+ // CHECK: {{0x55555555|0x6666666666666666}}
+ fprintf(stderr, "World\n");
+ return c;
+}
diff --git a/test/asan/TestCases/Darwin/malloc_destroy_zone.cc b/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
new file mode 100644
index 000000000000..9144bd689f74
--- /dev/null
+++ b/test/asan/TestCases/Darwin/malloc_destroy_zone.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_asan %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <malloc/malloc.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main() {
+ fprintf(stderr, "start\n");
+ malloc_zone_t *zone = malloc_create_zone(0, 0);
+ fprintf(stderr, "zone = %p\n", zone);
+ malloc_set_zone_name(zone, "myzone");
+ fprintf(stderr, "name changed\n");
+ malloc_destroy_zone(zone);
+ fprintf(stderr, "done\n");
+ return 0;
+}
+
+// CHECK: start
+// CHECK-NEXT: zone = 0x{{.*}}
+// CHECK-NEXT: name changed
+// CHECK-NEXT: done
diff --git a/test/asan/TestCases/Darwin/odr-lto.cc b/test/asan/TestCases/Darwin/odr-lto.cc
new file mode 100644
index 000000000000..40abec5827d5
--- /dev/null
+++ b/test/asan/TestCases/Darwin/odr-lto.cc
@@ -0,0 +1,45 @@
+// Check that -asan-use-private-alias and use_odr_indicator=1 silence the false
+// positive ODR violation on Darwin with LTO.
+
+// REQUIRES: lto
+
+// RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto
+// RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto
+// RUN: %clangxx_asan %t-1.o %t-2.o -o %t -flto
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ODR
+
+// RUN: %clangxx_asan -DPART=0 -c %s -o %t-1.o -flto -mllvm -asan-use-private-alias
+// RUN: %clangxx_asan -DPART=1 -c %s -o %t-2.o -flto -mllvm -asan-use-private-alias
+// RUN: %clangxx_asan %t-1.o %t-2.o -o %t -flto
+// RUN: %env_asan_opts=use_odr_indicator=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ODR
+
+#include <stdio.h>
+#include <stdlib.h>
+void putstest();
+
+#if PART == 1
+
+static const char *my_global = "test\n\00abc";
+
+int main()
+{
+ fputs(my_global, stderr);
+ putstest();
+ fprintf(stderr, "Done.\n");
+ return 0;
+}
+
+#else // PART == 1
+
+static const char *my_other_global = "test\n\00abc";
+
+void putstest()
+{
+ fputs(my_other_global, stderr);
+}
+
+#endif // PART == 1
+
+// CHECK-ODR: ERROR: AddressSanitizer: odr-violation
+// CHECK-NO-ODR-NOT: ERROR: AddressSanitizer: odr-violation
+// CHECK-NO-ODR: Done.