aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Darwin
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-02-10 07:45:43 +0000
commit476c4db3dc56bee43df384704c75ccc71cfa7a1d (patch)
tree5d0dcec3cc12fc53532fc84029892b98711a2596 /test/asan/TestCases/Darwin
parentca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (diff)
downloadsrc-476c4db3dc56bee43df384704c75ccc71cfa7a1d.tar.gz
src-476c4db3dc56bee43df384704c75ccc71cfa7a1d.zip
Import compiler-rt trunk r228651.vendor/compiler-rt/compiler-rt-r228651
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=278497 svn path=/vendor/compiler-rt/compiler-rt-r228651/; revision=278498; tag=vendor/compiler-rt/compiler-rt-r228651
Diffstat (limited to 'test/asan/TestCases/Darwin')
-rw-r--r--test/asan/TestCases/Darwin/address-range-limit.mm38
-rw-r--r--test/asan/TestCases/Darwin/crashlog-stacktraces.c43
-rw-r--r--test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc2
-rw-r--r--test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc39
-rw-r--r--test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc6
-rw-r--r--test/asan/TestCases/Darwin/interface_symbols_darwin.c9
-rw-r--r--test/asan/TestCases/Darwin/linked-only.cc33
-rw-r--r--test/asan/TestCases/Darwin/mixing-global-constructors.cc42
-rw-r--r--test/asan/TestCases/Darwin/suppressions-darwin.cc8
9 files changed, 211 insertions, 9 deletions
diff --git a/test/asan/TestCases/Darwin/address-range-limit.mm b/test/asan/TestCases/Darwin/address-range-limit.mm
new file mode 100644
index 000000000000..a6906766d7ee
--- /dev/null
+++ b/test/asan/TestCases/Darwin/address-range-limit.mm
@@ -0,0 +1,38 @@
+// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=368.
+
+// RUN: %clang_asan %s -Wno-deprecated-declarations -flat_namespace -bundle -undefined suppress -o %t.bundle
+// RUN: %clang_asan %s -Wno-deprecated-declarations -o %t -framework Foundation && not %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+#import <mach-o/dyld.h>
+
+#include <string>
+
+int main(int argc, char *argv[]) {
+ for (int i = 0; i < 10; i++) {
+ NSObjectFileImage im;
+
+ std::string path = std::string(argv[0]) + ".bundle";
+ NSObjectFileImageReturnCode rc =
+ NSCreateObjectFileImageFromFile(path.c_str(), &im);
+ if (rc != NSObjectFileImageSuccess) {
+ fprintf(stderr, "Could not load bundle.\n");
+ exit(-1);
+ }
+
+ NSModule handle = NSLinkModule(im, "a.bundle", 0);
+ if (handle == 0) {
+ fprintf(stderr, "Could not load bundle.\n");
+ exit(-1);
+ }
+ printf("h: %p\n", handle);
+ }
+
+ char *ptr = (char *)malloc(10);
+ ptr[10] = 'x'; // BOOM
+}
+
+// CHECK: AddressSanitizer: heap-buffer-overflow
+// CHECK: WRITE of size 1
+// CHECK: {{#0 .* in main}}
+// CHECK: is located 0 bytes to the right of 10-byte region
diff --git a/test/asan/TestCases/Darwin/crashlog-stacktraces.c b/test/asan/TestCases/Darwin/crashlog-stacktraces.c
new file mode 100644
index 000000000000..e9af5396e1c3
--- /dev/null
+++ b/test/asan/TestCases/Darwin/crashlog-stacktraces.c
@@ -0,0 +1,43 @@
+// RUN: %clang_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <execinfo.h>
+#include <sanitizer/common_interface_defs.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void death_function() {
+ fprintf(stderr, "DEATH CALLBACK\n");
+
+ void* callstack[128];
+ int i, frames = backtrace(callstack, 128);
+ char** strs = backtrace_symbols(callstack, frames);
+ for (i = 0; i < frames; ++i) {
+ fprintf(stderr, "%s\n", strs[i]);
+ }
+ free(strs);
+
+ fprintf(stderr, "END OF BACKTRACE\n");
+}
+
+int fault_function() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5]; // BOOM
+}
+
+int main() {
+ __sanitizer_set_death_callback(death_function);
+ fault_function();
+ return 0;
+}
+
+// CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+// CHECK: {{READ of size 1 at 0x.* thread T0}}
+// CHECK: {{ #0 0x.* in fault_function}}
+
+// CHECK: DEATH CALLBACK
+// CHECK: death_function
+// CHECK: fault_function
+// CHECK: main
+// CHECK: END OF BACKTRACE
diff --git a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
index b1bb4567f900..0bd4170a353c 100644
--- a/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
+++ b/test/asan/TestCases/Darwin/dyld_insert_libraries_reexec.cc
@@ -20,13 +20,11 @@ int main() {
return 0;
}
-// CHECK-NOINSERT: Parsed ASAN_OPTIONS: verbosity=1
// CHECK-NOINSERT: exec()-ing the program with
// CHECK-NOINSERT: DYLD_INSERT_LIBRARIES
// CHECK-NOINSERT: to enable ASan wrappers.
// CHECK-NOINSERT: Passed
-// CHECK: Parsed ASAN_OPTIONS: verbosity=1
// CHECK-NOT: exec()-ing the program with
// CHECK-NOT: DYLD_INSERT_LIBRARIES
// CHECK-NOT: to enable ASan wrappers.
diff --git a/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc b/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc
new file mode 100644
index 000000000000..a3af8c156ef2
--- /dev/null
+++ b/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cc
@@ -0,0 +1,39 @@
+// Check that when launching with DYLD_INSERT_LIBRARIES, we properly remove
+// the ASan dylib from the environment variable (both when using an absolute
+// or relative path) and also that the other dylibs are left untouched.
+
+// RUN: mkdir -p %T/dyld_insert_libraries_remove
+// RUN: cp `%clang_asan %s -fsanitize=address -### 2>&1 \
+// RUN: | grep "libclang_rt.asan_osx_dynamic.dylib" \
+// RUN: | sed -e 's/.*"\(.*libclang_rt.asan_osx_dynamic.dylib\)".*/\1/'` \
+// RUN: %T/dyld_insert_libraries_remove/libclang_rt.asan_osx_dynamic.dylib
+
+// RUN: %clangxx_asan %s -o %T/dyld_insert_libraries_remove/a.out
+// RUN: %clangxx -DSHARED_LIB %s \
+// RUN: -dynamiclib -o %T/dyld_insert_libraries_remove/dummy-so.dylib
+
+// RUN: ( cd %T/dyld_insert_libraries_remove && \
+// RUN: DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
+// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
+
+// RUN: ( cd %T/dyld_insert_libraries_remove && \
+// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
+// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
+
+// RUN: ( cd %T/dyld_insert_libraries_remove && \
+// RUN: DYLD_INSERT_LIBRARIES=%T/dyld_insert_libraries_remove/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
+// RUN: %run ./a.out 2>&1 ) | FileCheck %s || exit 1
+
+#if !defined(SHARED_LIB)
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ const char kEnvName[] = "DYLD_INSERT_LIBRARIES";
+ printf("%s=%s\n", kEnvName, getenv(kEnvName));
+ // CHECK: {{DYLD_INSERT_LIBRARIES=dummy-so.dylib}}
+ return 0;
+}
+#else // SHARED_LIB
+void foo() {}
+#endif // SHARED_LIB
diff --git a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc b/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
index e472a9dc6972..028683d2fc41 100644
--- a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
+++ b/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
@@ -3,11 +3,11 @@
// ../Linux/interception-in-shared-lib-test.cc.
// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
-// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \
-// RUN: -fPIC
+// RUN: -shared -o %t-so.so \
+// RUN: -fPIC -install_name @rpath/interception-in-shared-lib-test.cc.tmp-so.so
// TODO(glider): figure out how to set rpath in a more portable way and unite
// this test with ../Linux/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable-path -L%T -linterception-in-shared-lib-test && \
+// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable_path %t-so.so && \
// RUN: not %run %t 2>&1 | FileCheck %s
#include <stdio.h>
diff --git a/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
index 8680d678cf91..a75044d491fb 100644
--- a/test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -31,6 +31,15 @@
// RUN: echo __asan_report_store_n >> %t.interface
// RUN: echo __asan_get_current_fake_stack >> %t.interface
// RUN: echo __asan_addr_is_in_fake_stack >> %t.interface
+// RUN: echo __asan_mz_calloc >> %t.interface
+// RUN: echo __asan_mz_destroy >> %t.interface
+// RUN: echo __asan_mz_free >> %t.interface
+// RUN: echo __asan_mz_malloc >> %t.interface
+// RUN: echo __asan_mz_memalign >> %t.interface
+// RUN: echo __asan_mz_realloc >> %t.interface
+// RUN: echo __asan_mz_size >> %t.interface
+// RUN: echo __asan_mz_valloc >> %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
diff --git a/test/asan/TestCases/Darwin/linked-only.cc b/test/asan/TestCases/Darwin/linked-only.cc
new file mode 100644
index 000000000000..bb19ea8535e2
--- /dev/null
+++ b/test/asan/TestCases/Darwin/linked-only.cc
@@ -0,0 +1,33 @@
+// Main executable is uninstrumented, but linked to ASan runtime.
+// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=357.
+
+// RUN: %clangxx -g -O0 %s -c -o %t.o
+// RUN: %clangxx_asan -g -O0 %t.o -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "sanitizer/asan_interface.h"
+
+void test_shadow(char *p, size_t size) {
+ fprintf(stderr, "p = %p\n", p);
+ char *q = (char *)__asan_region_is_poisoned(p, size);
+ fprintf(stderr, "=%zd=\n", q ? q - p : -1);
+}
+
+int main(int argc, char *argv[]) {
+ char *p = (char *)malloc(10000);
+ test_shadow(p, 100);
+ free(p);
+ // CHECK: =-1=
+
+ test_shadow((char *)&main, 1);
+ // CHECK: =-1=
+
+ test_shadow((char *)&p, 1);
+ // CHECK: =-1=
+
+ return 0;
+}
diff --git a/test/asan/TestCases/Darwin/mixing-global-constructors.cc b/test/asan/TestCases/Darwin/mixing-global-constructors.cc
new file mode 100644
index 000000000000..0b0f15cc78d5
--- /dev/null
+++ b/test/asan/TestCases/Darwin/mixing-global-constructors.cc
@@ -0,0 +1,42 @@
+// A global constructor from a non-instrumented part calls a function
+// in an instrumented part.
+// Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=363.
+
+// RUN: %clangxx -DINSTRUMENTED_PART=0 -c %s -o %t-uninst.o
+// RUN: %clangxx_asan -DINSTRUMENTED_PART=1 -c %s -o %t-inst.o
+// RUN: %clangxx_asan %t-uninst.o %t-inst.o -o %t
+
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void func(char *ptr);
+
+#if INSTRUMENTED_PART == 1
+
+void func(char *ptr) {
+ *ptr = 'X';
+}
+
+#else // INSTRUMENTED_PART == 1
+
+struct C1 {
+ C1() {
+ printf("Hello ");
+ char buffer[10] = "world";
+ func(buffer);
+ printf("%s\n", buffer);
+ }
+};
+
+C1 *obj = new C1();
+
+int main(int argc, const char *argv[]) {
+ return 0;
+}
+
+#endif // INSTRUMENTED_PART == 1
+
+// CHECK: Hello Xorld
diff --git a/test/asan/TestCases/Darwin/suppressions-darwin.cc b/test/asan/TestCases/Darwin/suppressions-darwin.cc
index 9a8f56d5dc50..fb37296d404f 100644
--- a/test/asan/TestCases/Darwin/suppressions-darwin.cc
+++ b/test/asan/TestCases/Darwin/suppressions-darwin.cc
@@ -4,17 +4,17 @@
// Check that suppressing the interceptor by name works.
// RUN: echo "interceptor_name:memmove" > %t.supp
-// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing by interceptor name works even without the symbolizer
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:symbolize=false %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: ASAN_OPTIONS="suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing all reports from a library works.
// RUN: echo "interceptor_via_lib:CoreFoundation" > %t.supp
-// RUN: ASAN_OPTIONS=suppressions=%t.supp %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
// Check that suppressing library works even without the symbolizer.
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:symbolize=false %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
+// RUN: ASAN_OPTIONS="suppressions='%t.supp':symbolize=false" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
#include <CoreFoundation/CoreFoundation.h>