aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Darwin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:02:53 +0000
commitab0bf875a5f328a6710f4e48258979ae1bc8da1c (patch)
tree66903cf9f73151825893dcc216b04c0930317a10 /test/asan/TestCases/Darwin
parentabacad30a54c59ad437ccf54ec5236a8dd7f3ba9 (diff)
downloadsrc-ab0bf875a5f328a6710f4e48258979ae1bc8da1c.tar.gz
src-ab0bf875a5f328a6710f4e48258979ae1bc8da1c.zip
Vendor import of compiler-rt trunk r300422:vendor/compiler-rt/compiler-rt-trunk-r300422
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=317021 svn path=/vendor/compiler-rt/compiler-rt-trunk-r300422/; revision=317022; tag=vendor/compiler-rt/compiler-rt-trunk-r300422
Diffstat (limited to 'test/asan/TestCases/Darwin')
-rw-r--r--test/asan/TestCases/Darwin/interface_symbols_darwin.c82
-rw-r--r--test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc1
-rw-r--r--test/asan/TestCases/Darwin/scribble.cc58
-rw-r--r--test/asan/TestCases/Darwin/suppressions-darwin.cc1
-rw-r--r--test/asan/TestCases/Darwin/suppressions-sandbox.cc1
5 files changed, 87 insertions, 56 deletions
diff --git a/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
index ed5779ebe220..9450575b4ecd 100644
--- a/test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -3,62 +3,32 @@
// ../Linux/interface_symbols.c
// RUN: %clang_asan -dead_strip -O2 %s -o %t.exe
-// RUN: rm -f %t.symbols %t.interface
-
+//
+// note: we can not use -D on Darwin.
// RUN: nm -g `%clang_asan %s -fsanitize=address -### 2>&1 | grep "libclang_rt.asan_osx_dynamic.dylib" | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \
-// RUN: | grep " T " | sed "s/.* T //" \
-// RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" \
-// RUN: | sed -E "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
-// RUN: | grep -v "__asan_default_options" \
-// RUN: | grep -v "__asan_on_error" > %t.symbols
-
-// RUN: cat %p/../../../../lib/asan/asan_interface_internal.h \
-// RUN: | sed "s/\/\/.*//" | sed "s/typedef.*//" \
-// RUN: | grep -v "OPTIONAL" \
-// RUN: | grep "__asan_.*(" | sed "s/.* __asan_/__asan_/;s/(.*//" \
-// RUN: > %t.interface
-// RUN: echo __asan_report_load1 >> %t.interface
-// RUN: echo __asan_report_load2 >> %t.interface
-// RUN: echo __asan_report_load4 >> %t.interface
-// RUN: echo __asan_report_load8 >> %t.interface
-// RUN: echo __asan_report_load16 >> %t.interface
-// RUN: echo __asan_report_store1 >> %t.interface
-// RUN: echo __asan_report_store2 >> %t.interface
-// RUN: echo __asan_report_store4 >> %t.interface
-// RUN: echo __asan_report_store8 >> %t.interface
-// RUN: echo __asan_report_store16 >> %t.interface
-// RUN: echo __asan_report_load_n >> %t.interface
-// RUN: echo __asan_report_store_n >> %t.interface
-// RUN: echo __asan_report_load1_noabort >> %t.interface
-// RUN: echo __asan_report_load2_noabort >> %t.interface
-// RUN: echo __asan_report_load4_noabort >> %t.interface
-// RUN: echo __asan_report_load8_noabort >> %t.interface
-// RUN: echo __asan_report_load16_noabort >> %t.interface
-// RUN: echo __asan_report_store1_noabort >> %t.interface
-// RUN: echo __asan_report_store2_noabort >> %t.interface
-// RUN: echo __asan_report_store4_noabort >> %t.interface
-// RUN: echo __asan_report_store8_noabort >> %t.interface
-// RUN: echo __asan_report_store16_noabort >> %t.interface
-// RUN: echo __asan_report_load_n_noabort >> %t.interface
-// RUN: echo __asan_report_store_n_noabort >> %t.interface
-// RUN: echo __asan_report_exp_load1 >> %t.interface
-// RUN: echo __asan_report_exp_load2 >> %t.interface
-// RUN: echo __asan_report_exp_load4 >> %t.interface
-// RUN: echo __asan_report_exp_load8 >> %t.interface
-// RUN: echo __asan_report_exp_load16 >> %t.interface
-// RUN: echo __asan_report_exp_store1 >> %t.interface
-// RUN: echo __asan_report_exp_store2 >> %t.interface
-// RUN: echo __asan_report_exp_store4 >> %t.interface
-// RUN: echo __asan_report_exp_store8 >> %t.interface
-// RUN: echo __asan_report_exp_store16 >> %t.interface
-// RUN: echo __asan_report_exp_load_n >> %t.interface
-// RUN: echo __asan_report_exp_store_n >> %t.interface
-// RUN: echo __asan_get_current_fake_stack >> %t.interface
-// RUN: echo __asan_addr_is_in_fake_stack >> %t.interface
-
-// RUN: for i in `jot - 0 10`; do echo __asan_stack_malloc_$i >> %t.interface; done
-// RUN: for i in `jot - 0 10`; do echo __asan_stack_free_$i >> %t.interface; done
-
-// RUN: cat %t.interface | sort -u | diff %t.symbols -
+// RUN: | grep " [TU] " \
+// RUN: | grep -o "\(__asan_\|__ubsan_\|__sancov_\|__sanitizer_\)[^ ]*" \
+// RUN: | grep -v "__sanitizer_syscall" \
+// RUN: | grep -v "__sanitizer_weak_hook" \
+// RUN: | grep -v "__sanitizer_mz" \
+// RUN: | grep -v "__ubsan_handle_dynamic_type_cache_miss" \
+// RUN: | sed -e "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
+// RUN: > %t.exports
+//
+// RUN: grep -e "INTERFACE_\(WEAK_\)\?FUNCTION" \
+// RUN: %p/../../../../lib/asan/asan_interface.inc \
+// RUN: %p/../../../../lib/ubsan/ubsan_interface.inc \
+// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface.inc \
+// RUN: %p/../../../../lib/sanitizer_common/sanitizer_common_interface_posix.inc \
+// RUN: %p/../../../../lib/sanitizer_common/sanitizer_coverage_interface.inc \
+// RUN: | grep -v "__sanitizer_weak_hook" \
+// RUN: | sed -e "s/.*(//" -e "s/).*//" > %t.imports
+//
+// RUN: cat %t.imports | sort | uniq > %t.imports-sorted
+// RUN: cat %t.exports | sort | uniq > %t.exports-sorted
+//
+// RUN: echo
+// RUN: echo "=== NOTE === If you see a mismatch below, please update sanitizer_interface.inc files."
+// RUN: diff %t.imports-sorted %t.exports-sorted
int main() { return 0; }
diff --git a/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc b/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
index 2c643bc03c52..b9b96ef0504e 100644
--- a/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
+++ b/test/asan/TestCases/Darwin/malloc_set_zone_name-mprotect.cc
@@ -47,5 +47,6 @@ int main() {
memset(mem[i], 'a', 8 * (i % kNumIter));
free(mem[i]);
}
+ malloc_destroy_zone(zone);
return 0;
}
diff --git a/test/asan/TestCases/Darwin/scribble.cc b/test/asan/TestCases/Darwin/scribble.cc
new file mode 100644
index 000000000000..0ddee6b5eef5
--- /dev/null
+++ b/test/asan/TestCases/Darwin/scribble.cc
@@ -0,0 +1,58 @@
+// RUN: %clang_asan -O2 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-NOSCRIBBLE %s
+// RUN: env MallocScribble=1 MallocPreScribble=1 %run %t 2>&1 | FileCheck --check-prefix=CHECK-SCRIBBLE %s
+// RUN: %env_asan_opts=max_free_fill_size=4096 %run %t 2>&1 | FileCheck --check-prefix=CHECK-SCRIBBLE %s
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct Isa {
+ const char *class_name;
+};
+
+struct MyClass {
+ long padding;
+ Isa *isa;
+ long data;
+
+ void print_my_class_name();
+};
+
+__attribute__((no_sanitize("address")))
+void MyClass::print_my_class_name() {
+ fprintf(stderr, "this = %p\n", this);
+ fprintf(stderr, "padding = 0x%lx\n", this->padding);
+ fprintf(stderr, "isa = %p\n", this->isa);
+
+ if ((uint32_t)(uintptr_t)this->isa != 0x55555555) {
+ fprintf(stderr, "class name: %s\n", this->isa->class_name);
+ }
+}
+
+int main() {
+ Isa *my_class_isa = (Isa *)malloc(sizeof(Isa));
+ memset(my_class_isa, 0x77, sizeof(Isa));
+ my_class_isa->class_name = "MyClass";
+
+ MyClass *my_object = (MyClass *)malloc(sizeof(MyClass));
+ memset(my_object, 0x88, sizeof(MyClass));
+ my_object->isa = my_class_isa;
+ my_object->data = 42;
+
+ my_object->print_my_class_name();
+ // CHECK-SCRIBBLE: class name: MyClass
+ // CHECK-NOSCRIBBLE: class name: MyClass
+
+ free(my_object);
+
+ my_object->print_my_class_name();
+ // CHECK-NOSCRIBBLE: class name: MyClass
+ // CHECK-SCRIBBLE: isa = {{(0x)?}}{{5555555555555555|55555555}}
+
+ fprintf(stderr, "okthxbai!\n");
+ // CHECK-SCRIBBLE: okthxbai!
+ // CHECK-NOSCRIBBLE: okthxbai!
+ free(my_class_isa);
+}
diff --git a/test/asan/TestCases/Darwin/suppressions-darwin.cc b/test/asan/TestCases/Darwin/suppressions-darwin.cc
index a177c4e17ec4..8c207b102cb0 100644
--- a/test/asan/TestCases/Darwin/suppressions-darwin.cc
+++ b/test/asan/TestCases/Darwin/suppressions-darwin.cc
@@ -27,6 +27,7 @@ int main() {
kCFStringEncodingUTF8, FALSE); // BOOM
fprintf(stderr, "Ignored.\n");
free(a);
+ CFRelease(str);
}
// CHECK-CRASH: AddressSanitizer: heap-buffer-overflow
diff --git a/test/asan/TestCases/Darwin/suppressions-sandbox.cc b/test/asan/TestCases/Darwin/suppressions-sandbox.cc
index ddbad466f7bf..c0b84addaa81 100644
--- a/test/asan/TestCases/Darwin/suppressions-sandbox.cc
+++ b/test/asan/TestCases/Darwin/suppressions-sandbox.cc
@@ -18,6 +18,7 @@ int main() {
kCFStringEncodingUTF8, FALSE); // BOOM
fprintf(stderr, "Ignored.\n");
free(a);
+ CFRelease(str);
}
// CHECK-CRASH: AddressSanitizer: heap-buffer-overflow