summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Linux
diff options
context:
space:
mode:
Diffstat (limited to 'test/asan/TestCases/Linux')
-rw-r--r--test/asan/TestCases/Linux/asan_default_suppressions.cc7
-rw-r--r--test/asan/TestCases/Linux/asan_prelink_test.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_preload_test-1.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_preload_test-2.cc2
-rw-r--r--test/asan/TestCases/Linux/asan_rt_confict_test-1.cc2
-rw-r--r--test/asan/TestCases/Linux/clang_gcc_abi.cc3
-rw-r--r--test/asan/TestCases/Linux/coverage-and-lsan.cc20
-rw-r--r--test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc41
-rw-r--r--test/asan/TestCases/Linux/coverage-caller-callee.cc74
-rw-r--r--test/asan/TestCases/Linux/coverage-direct-activation.cc59
-rw-r--r--test/asan/TestCases/Linux/coverage-direct-large.cc65
-rw-r--r--test/asan/TestCases/Linux/coverage-direct.cc83
-rw-r--r--test/asan/TestCases/Linux/coverage-disabled.cc20
-rw-r--r--test/asan/TestCases/Linux/coverage-fork-direct.cc38
-rw-r--r--test/asan/TestCases/Linux/coverage-fork.cc38
-rw-r--r--test/asan/TestCases/Linux/coverage-levels.cc29
-rw-r--r--test/asan/TestCases/Linux/coverage-maybe-open-file.cc31
-rw-r--r--test/asan/TestCases/Linux/coverage-missing.cc84
-rw-r--r--test/asan/TestCases/Linux/coverage-module-unloaded.cc56
-rw-r--r--test/asan/TestCases/Linux/coverage-reset.cc52
-rw-r--r--test/asan/TestCases/Linux/coverage-sandboxing.cc85
-rw-r--r--test/asan/TestCases/Linux/coverage-tracing.cc50
-rw-r--r--test/asan/TestCases/Linux/coverage.cc71
-rw-r--r--test/asan/TestCases/Linux/init-order-dlopen.cc47
-rw-r--r--test/asan/TestCases/Linux/initialization-bug-any-order.cc4
-rw-r--r--test/asan/TestCases/Linux/interception-in-shared-lib-test.cc32
-rw-r--r--test/asan/TestCases/Linux/interface_symbols_linux.c14
-rw-r--r--test/asan/TestCases/Linux/kernel-area.cc20
-rw-r--r--test/asan/TestCases/Linux/leak.cc6
-rw-r--r--test/asan/TestCases/Linux/leak_check_segv.cc23
-rw-r--r--test/asan/TestCases/Linux/malloc-in-qsort.cc4
-rw-r--r--test/asan/TestCases/Linux/malloc_delete_mismatch.cc8
-rw-r--r--test/asan/TestCases/Linux/nohugepage_test.cc24
-rw-r--r--test/asan/TestCases/Linux/odr-violation.cc22
-rw-r--r--test/asan/TestCases/Linux/overflow-in-qsort.cc4
-rw-r--r--test/asan/TestCases/Linux/ptrace.cc6
-rw-r--r--test/asan/TestCases/Linux/quarantine_size_mb.cc10
-rw-r--r--test/asan/TestCases/Linux/read_binary_name_regtest.c50
-rw-r--r--test/asan/TestCases/Linux/signal_during_stop_the_world.cc60
-rw-r--r--test/asan/TestCases/Linux/sized_delete_test.cc18
-rw-r--r--test/asan/TestCases/Linux/stack-overflow-sigbus.cc2
-rw-r--r--test/asan/TestCases/Linux/stack-trace-dlclose.cc4
-rw-r--r--test/asan/TestCases/Linux/static_tls.cc29
-rw-r--r--test/asan/TestCases/Linux/stress_dtls.c6
44 files changed, 399 insertions, 908 deletions
diff --git a/test/asan/TestCases/Linux/asan_default_suppressions.cc b/test/asan/TestCases/Linux/asan_default_suppressions.cc
new file mode 100644
index 0000000000000..5ff59c1dfe7f5
--- /dev/null
+++ b/test/asan/TestCases/Linux/asan_default_suppressions.cc
@@ -0,0 +1,7 @@
+// Test that we use the suppressions from __asan_default_suppressions.
+// RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s
+extern "C" {
+ const char *__asan_default_suppressions() { return "FooBar"; }
+}
+// CHECK: AddressSanitizer: failed to parse suppressions
+int main() {}
diff --git a/test/asan/TestCases/Linux/asan_prelink_test.cc b/test/asan/TestCases/Linux/asan_prelink_test.cc
index 6145c01f7342c..9e58f83d40c68 100644
--- a/test/asan/TestCases/Linux/asan_prelink_test.cc
+++ b/test/asan/TestCases/Linux/asan_prelink_test.cc
@@ -7,7 +7,7 @@
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -Wl,-Ttext-segment=0x3600000000 ||\
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -Wl,-Ttext=0x3600000000
// RUN: %clangxx_asan %t.o %t.so -Wl,-R. -o %t
-// RUN: ASAN_OPTIONS=verbosity=1 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s
// GNU driver doesn't handle .so files properly.
// REQUIRES: x86_64-supported-target, asan-64-bits, Clang
diff --git a/test/asan/TestCases/Linux/asan_preload_test-1.cc b/test/asan/TestCases/Linux/asan_preload_test-1.cc
index e5eab5545b83b..4e365b5633f37 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-1.cc
@@ -5,7 +5,7 @@
// RUN: %clangxx %s %t.so -o %t
//
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
diff --git a/test/asan/TestCases/Linux/asan_preload_test-2.cc b/test/asan/TestCases/Linux/asan_preload_test-2.cc
index 0f22264cf1fb5..488fd52e682a6 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-2.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-2.cc
@@ -1,7 +1,7 @@
// Test that preloaded runtime works with unsanitized executables.
//
// RUN: %clangxx %s -o %t
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
index 30f1c17700c8a..8cf761c905f80 100644
--- a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
@@ -2,7 +2,7 @@
// executable is prohibited.
//
// RUN: %clangxx_asan_static %s -o %t
-// RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
+// RUN: env LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
// XFAIL: android
diff --git a/test/asan/TestCases/Linux/clang_gcc_abi.cc b/test/asan/TestCases/Linux/clang_gcc_abi.cc
index e833881661d2b..669d1524077ce 100644
--- a/test/asan/TestCases/Linux/clang_gcc_abi.cc
+++ b/test/asan/TestCases/Linux/clang_gcc_abi.cc
@@ -8,9 +8,10 @@
#include <stdlib.h>
+__attribute__((noinline))
int boom() {
volatile int three = 3;
- char *s = (char *)malloc(three);
+ char * volatile s = (char *)malloc(three);
// CHECK: #1 0x{{.*}} in boom {{.*}}clang_gcc_abi.cc:[[@LINE-1]]
return s[three]; //BOOM
}
diff --git a/test/asan/TestCases/Linux/coverage-and-lsan.cc b/test/asan/TestCases/Linux/coverage-and-lsan.cc
deleted file mode 100644
index 4cb8e2af3084d..0000000000000
--- a/test/asan/TestCases/Linux/coverage-and-lsan.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Make sure coverage is dumped even if there are reported leaks.
-//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-//
-// RUN: rm -rf %T/coverage-and-lsan
-//
-// RUN: mkdir -p %T/coverage-and-lsan/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %sancov print %T/coverage-and-lsan/*.sancov 2>&1
-//
-// REQUIRES: leak-detection
-
-int *g = new int;
-int main(int argc, char **argv) {
- g = 0;
- return 0;
-}
-
-// CHECK: LeakSanitizer: detected memory leaks
-// CHECK: CovDump:
diff --git a/test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc b/test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc
deleted file mode 100644
index 7598f6bc7bc53..0000000000000
--- a/test/asan/TestCases/Linux/coverage-caller-callee-total-count.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Test __sanitizer_get_total_unique_coverage for caller-callee coverage
-
-// RUN: %clangxx_asan -fsanitize-coverage=4 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1 %run %t
-// RUN: rm -f caller-callee*.sancov
-//
-// REQUIRES: asan-64-bits
-
-#include <sanitizer/coverage_interface.h>
-#include <stdio.h>
-#include <assert.h>
-int P = 0;
-struct Foo {virtual void f() {if (P) printf("Foo::f()\n");}};
-struct Foo1 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo2 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-
-Foo *foo[3] = {new Foo, new Foo1, new Foo2};
-
-uintptr_t CheckNewTotalUniqueCoverageIsLargerAndReturnIt(uintptr_t old_total) {
- uintptr_t new_total = __sanitizer_get_total_unique_coverage();
- assert(new_total > old_total);
- return new_total;
-}
-
-int main(int argc, char **argv) {
- uintptr_t total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(0);
- foo[0]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
- foo[1]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
- foo[2]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
- // Ok, called every function once.
- // Now call them again from another call site. Should get new coverage.
- foo[0]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
- foo[1]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
- foo[2]->f();
- total = CheckNewTotalUniqueCoverageIsLargerAndReturnIt(total);
-}
diff --git a/test/asan/TestCases/Linux/coverage-caller-callee.cc b/test/asan/TestCases/Linux/coverage-caller-callee.cc
deleted file mode 100644
index cd318962b8e0e..0000000000000
--- a/test/asan/TestCases/Linux/coverage-caller-callee.cc
+++ /dev/null
@@ -1,74 +0,0 @@
-// Test caller-callee coverage with large number of threads
-// and various numbers of callers and callees.
-
-// RUN: %clangxx_asan -fsanitize-coverage=4 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 10 1 2>&1 | FileCheck %s --check-prefix=CHECK-10-1
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 9 2 2>&1 | FileCheck %s --check-prefix=CHECK-9-2
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 7 3 2>&1 | FileCheck %s --check-prefix=CHECK-7-3
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 17 1 2>&1 | FileCheck %s --check-prefix=CHECK-17-1
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 15 2 2>&1 | FileCheck %s --check-prefix=CHECK-15-2
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 18 3 2>&1 | FileCheck %s --check-prefix=CHECK-18-3
-// RUN: rm -f caller-callee*.sancov
-//
-// REQUIRES: asan-64-bits
-//
-// CHECK-10-1: CovDump: 10 caller-callee pairs written
-// CHECK-9-2: CovDump: 18 caller-callee pairs written
-// CHECK-7-3: CovDump: 21 caller-callee pairs written
-// CHECK-17-1: CovDump: 14 caller-callee pairs written
-// CHECK-15-2: CovDump: 28 caller-callee pairs written
-// CHECK-18-3: CovDump: 42 caller-callee pairs written
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-int P = 0;
-struct Foo {virtual void f() {if (P) printf("Foo::f()\n");}};
-struct Foo1 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo2 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo3 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo4 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo5 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo6 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo7 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo8 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo9 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo10 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo11 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo12 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo13 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo14 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo15 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo16 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo17 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo18 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-struct Foo19 : Foo {virtual void f() {if (P) printf("%d\n", __LINE__);}};
-
-Foo *foo[20] = {
- new Foo, new Foo1, new Foo2, new Foo3, new Foo4, new Foo5, new Foo6,
- new Foo7, new Foo8, new Foo9, new Foo10, new Foo11, new Foo12, new Foo13,
- new Foo14, new Foo15, new Foo16, new Foo17, new Foo18, new Foo19,
-};
-
-int n_functions = 10;
-int n_callers = 2;
-
-void *Thread(void *arg) {
- if (n_callers >= 1) for (int i = 0; i < 2000; i++) foo[i % n_functions]->f();
- if (n_callers >= 2) for (int i = 0; i < 2000; i++) foo[i % n_functions]->f();
- if (n_callers >= 3) for (int i = 0; i < 2000; i++) foo[i % n_functions]->f();
- return arg;
-}
-
-int main(int argc, char **argv) {
- if (argc >= 2)
- n_functions = atoi(argv[1]);
- if (argc >= 3)
- n_callers = atoi(argv[2]);
- const int kNumThreads = 16;
- pthread_t t[kNumThreads];
- for (int i = 0; i < kNumThreads; i++)
- pthread_create(&t[i], 0, Thread, 0);
- for (int i = 0; i < kNumThreads; i++)
- pthread_join(t[i], 0);
-}
diff --git a/test/asan/TestCases/Linux/coverage-direct-activation.cc b/test/asan/TestCases/Linux/coverage-direct-activation.cc
deleted file mode 100644
index 9b2a0d8897c85..0000000000000
--- a/test/asan/TestCases/Linux/coverage-direct-activation.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Test for direct coverage writing enabled at activation time.
-
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_activation_test_1.so -fPIC
-// RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o
-// RUN: %clangxx_asan -fsanitize-coverage=1 %t.o %libdl -o %t
-
-// RUN: rm -rf %T/coverage-direct-activation
-
-// RUN: mkdir -p %T/coverage-direct-activation/normal
-// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t
-// RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt
-
-// RUN: mkdir -p %T/coverage-direct-activation/direct
-// RUN: ASAN_OPTIONS=start_deactivated=1,coverage_direct=1,verbosity=1 \
-// RUN: ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t
-// RUN: cd %T/coverage-direct-activation/direct
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// Test start_deactivated=1,coverage=1 in ASAN_OPTIONS.
-
-// RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct/out.txt
-
-// RUN: mkdir -p %T/coverage-direct-activation/direct2
-// RUN: ASAN_OPTIONS=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \
-// RUN: ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t
-// RUN: cd %T/coverage-direct-activation/direct2
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: diff -u coverage-direct-activation/normal/out.txt coverage-direct-activation/direct2/out.txt
-
-// XFAIL: android
-
-#include <assert.h>
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#ifdef SHARED
-extern "C" {
-void bar() { printf("bar\n"); }
-}
-#else
-
-int main(int argc, char **argv) {
- fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_activation_test_1.so", RTLD_LAZY);
- assert(handle1);
- void (*bar1)() = (void (*)())dlsym(handle1, "bar");
- assert(bar1);
- bar1();
-
- return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Linux/coverage-direct-large.cc b/test/asan/TestCases/Linux/coverage-direct-large.cc
deleted file mode 100644
index 25c950e0bb300..0000000000000
--- a/test/asan/TestCases/Linux/coverage-direct-large.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Test for direct coverage writing with lots of data.
-// Current implementation maps output file in chunks of 64K. This test overflows
-// 1 chunk.
-
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %T/libcoverage_direct_large_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSO_DIR=\"%T\" %s %libdl -o %t
-
-// RUN: rm -rf %T/coverage-direct-large
-
-// RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: mkdir -p %T/coverage-direct-large/direct && cd %T/coverage-direct-large/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: diff -u coverage-direct-large/normal/out.txt coverage-direct-large/direct/out.txt
-//
-// XFAIL: android
-
-#define F0(Q, x) Q(x)
-#define F1(Q, x) \
- F0(Q, x##0) F0(Q, x##1) F0(Q, x##2) F0(Q, x##3) F0(Q, x##4) F0(Q, x##5) \
- F0(Q, x##6) F0(Q, x##7) F0(Q, x##8) F0(Q, x##9)
-#define F2(Q, x) \
- F1(Q, x##0) F1(Q, x##1) F1(Q, x##2) F1(Q, x##3) F1(Q, x##4) F1(Q, x##5) \
- F1(Q, x##6) F1(Q, x##7) F1(Q, x##8) F1(Q, x##9)
-#define F3(Q, x) \
- F2(Q, x##0) F2(Q, x##1) F2(Q, x##2) F2(Q, x##3) F2(Q, x##4) F2(Q, x##5) \
- F2(Q, x##6) F2(Q, x##7) F2(Q, x##8) F2(Q, x##9)
-#define F4(Q, x) \
- F3(Q, x##0) F3(Q, x##1) F3(Q, x##2) F3(Q, x##3) F3(Q, x##4) F3(Q, x##5) \
- F3(Q, x##6) F3(Q, x##7) F3(Q, x##8) F3(Q, x##9)
-
-#define DECL(x) __attribute__((noinline)) static void x() {}
-#define CALL(x) x();
-
-F4(DECL, f)
-
-#ifdef SHARED
-extern "C" void so_entry() {
- F4(CALL, f)
-}
-#else
-
-#include <assert.h>
-#include <dlfcn.h>
-int main(void) {
- F4(CALL, f)
-
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_large_test_1.so", RTLD_LAZY);
- assert(handle1);
- void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
- assert(so_entry);
- so_entry();
-
- return 0;
-}
-
-#endif // SHARED
diff --git a/test/asan/TestCases/Linux/coverage-direct.cc b/test/asan/TestCases/Linux/coverage-direct.cc
deleted file mode 100644
index 45222fa1a03eb..0000000000000
--- a/test/asan/TestCases/Linux/coverage-direct.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-// Test for direct coverage writing with dlopen at coverage level 1 to 3.
-
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
-
-// RUN: rm -rf %T/coverage-direct
-
-// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
-// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
-
-// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
-// RUN: cd %T/coverage-direct/direct
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
-
-
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%T\" %s %libdl -o %t
-
-// RUN: rm -rf %T/coverage-direct
-
-// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
-// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
-
-// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
-// RUN: cd %T/coverage-direct/direct
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
-
-
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%T\" %s %libdl -o %t
-
-// RUN: rm -rf %T/coverage-direct
-
-// RUN: mkdir -p %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
-// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
-
-// RUN: mkdir -p %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
-// RUN: cd %T/coverage-direct/direct
-// RUN: %sancov rawunpack *.sancov.raw
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
-
-// RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
-
-// XFAIL: android
-
-#include <assert.h>
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#ifdef SHARED
-extern "C" {
-void bar() { printf("bar\n"); }
-}
-#else
-
-int main(int argc, char **argv) {
- fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_direct_test_1.so", RTLD_LAZY);
- assert(handle1);
- void (*bar1)() = (void (*)())dlsym(handle1, "bar");
- assert(bar1);
- bar1();
-
- return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Linux/coverage-disabled.cc b/test/asan/TestCases/Linux/coverage-disabled.cc
deleted file mode 100644
index cb33542a5701b..0000000000000
--- a/test/asan/TestCases/Linux/coverage-disabled.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Test that no data is collected without a runtime flag.
-//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-//
-// RUN: rm -rf %T/coverage-disabled
-//
-// RUN: mkdir -p %T/coverage-disabled/normal
-// RUN: ASAN_OPTIONS=coverage_direct=0:coverage_dir=%T/coverage-disabled/normal:verbosity=1 %run %t
-// RUN: not %sancov print %T/coverage-disabled/normal/*.sancov 2>&1
-//
-// RUN: mkdir -p %T/coverage-disabled/direct
-// RUN: ASAN_OPTIONS=coverage_direct=1:coverage_dir=%T/coverage-disabled/direct:verbosity=1 %run %t
-// RUN: cd %T/coverage-disabled/direct
-// RUN: not %sancov rawunpack *.sancov
-//
-// XFAIL: android
-
-int main(int argc, char **argv) {
- return 0;
-}
diff --git a/test/asan/TestCases/Linux/coverage-fork-direct.cc b/test/asan/TestCases/Linux/coverage-fork-direct.cc
deleted file mode 100644
index 51cbbd821b8ef..0000000000000
--- a/test/asan/TestCases/Linux/coverage-fork-direct.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: rm -rf %T/coverage-fork-direct
-// RUN: mkdir -p %T/coverage-fork-direct && cd %T/coverage-fork-direct
-// RUN: (ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t; \
-// RUN: %sancov rawunpack *.sancov.raw; %sancov print *.sancov) 2>&1
-//
-// XFAIL: android
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-__attribute__((noinline))
-void foo() { printf("foo\n"); }
-
-__attribute__((noinline))
-void bar() { printf("bar\n"); }
-
-__attribute__((noinline))
-void baz() { printf("baz\n"); }
-
-int main(int argc, char **argv) {
- pid_t child_pid = fork();
- if (child_pid == 0) {
- fprintf(stderr, "Child PID: %d\n", getpid());
- baz();
- } else {
- fprintf(stderr, "Parent PID: %d\n", getpid());
- foo();
- bar();
- }
- return 0;
-}
-
-// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
-// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
-// CHECK-DAG: read 3 PCs from {{.*}}.[[ParentPID]].sancov
-// CHECK-DAG: read 1 PCs from {{.*}}.[[ChildPID]].sancov
diff --git a/test/asan/TestCases/Linux/coverage-fork.cc b/test/asan/TestCases/Linux/coverage-fork.cc
deleted file mode 100644
index 38c200942609c..0000000000000
--- a/test/asan/TestCases/Linux/coverage-fork.cc
+++ /dev/null
@@ -1,38 +0,0 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: export ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1
-// RUN: rm -rf %T/coverage-fork
-// RUN: mkdir -p %T/coverage-fork && cd %T/coverage-fork
-// RUN: %run %t 2>&1 | FileCheck %s
-//
-// XFAIL: android
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-__attribute__((noinline))
-void foo() { printf("foo\n"); }
-
-__attribute__((noinline))
-void bar() { printf("bar\n"); }
-
-__attribute__((noinline))
-void baz() { printf("baz\n"); }
-
-int main(int argc, char **argv) {
- pid_t child_pid = fork();
- if (child_pid == 0) {
- fprintf(stderr, "Child PID: %d\n", getpid());
- baz();
- } else {
- fprintf(stderr, "Parent PID: %d\n", getpid());
- foo();
- bar();
- }
- return 0;
-}
-
-// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
-// CHECK-DAG: [[ChildPID]].sancov: 1 PCs written
-// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
-// CHECK-DAG: [[ParentPID]].sancov: 3 PCs written
diff --git a/test/asan/TestCases/Linux/coverage-levels.cc b/test/asan/TestCases/Linux/coverage-levels.cc
deleted file mode 100644
index cc196c5a9e187..0000000000000
--- a/test/asan/TestCases/Linux/coverage-levels.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-// Test various levels of coverage
-//
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=1 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=2 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=3 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3
-
-// RUN: ASAN_OPTIONS=coverage=1:coverage_bitset=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
-// RUN: ASAN_OPTIONS=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOBITSET
-// RUN: ASAN_OPTIONS=coverage=1:coverage_pcs=0:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3_NOPCS
-//
-// REQUIRES: asan-64-bits
-
-volatile int sink;
-int main(int argc, char **argv) {
- if (argc == 0)
- sink = 0;
-}
-
-// CHECK1: CovDump: bitset of 1 bits written, 1 bits are set
-// CHECK1: 1 PCs written
-// CHECK2: CovDump: bitset of 3 bits written, 2 bits are set
-// CHECK2: 2 PCs written
-// CHECK3: CovDump: bitset of 4 bits written, 3 bits are set
-// CHECK3: 3 PCs written
-// CHECK3_NOBITSET-NOT: bitset of
-// CHECK3_NOPCS-NOT: PCs written
diff --git a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc b/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
deleted file mode 100644
index 4580de4117993..0000000000000
--- a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
-// XFAIL: android
-//
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: rm -rf %T/coverage-maybe-open-file
-// RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file
-// RUN: ASAN_OPTIONS=coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success
-// RUN: ASAN_OPTIONS=coverage=0 %run %t | FileCheck %s --check-prefix=CHECK-fail
-// RUN: [ "$(cat test.sancov.packed)" == "test" ]
-// RUN: cd .. && rm -rf %T/coverage-maybe-open-file
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sanitizer/coverage_interface.h>
-
-int main(int argc, char **argv) {
- int fd = __sanitizer_maybe_open_cov_file("test");
- if (fd > 0) {
- printf("SUCCESS\n");
- const char s[] = "test\n";
- write(fd, s, strlen(s));
- close(fd);
- } else {
- printf("FAIL\n");
- }
-}
-
-// CHECK-success: SUCCESS
-// CHECK-fail: FAIL
diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc
new file mode 100644
index 0000000000000..36f33b505e27a
--- /dev/null
+++ b/test/asan/TestCases/Linux/coverage-missing.cc
@@ -0,0 +1,84 @@
+// Test for "sancov.py missing ...".
+
+// RUN: export ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1:coverage_dir=%T/coverage-missing
+
+// First case: coverage from executable. main() is called on every code path.
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t -DFOOBAR -DMAIN
+// RUN: rm -rf %T/coverage-missing
+// RUN: mkdir -p %T/coverage-missing
+// RUN: cd %T/coverage-missing
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t
+// RUN: %sancov print *.sancov > main.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat main.txt | wc -l) == 1 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
+// RUN: %sancov print *.sancov > foo.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat foo.txt | wc -l) == 3 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
+// RUN: %sancov print *.sancov > bar.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat bar.txt | wc -l) == 4 ]
+// RUN: %sancov missing %t < foo.txt > foo-missing.txt
+// RUN: sort main.txt foo-missing.txt -o foo-missing-with-main.txt
+// The "missing from foo" set may contain a few bogus PCs from the sanitizer
+// runtime, but it must include the entire "bar" code path as a subset. Sorted
+// lists can be tested for set inclusion with diff + grep.
+// RUN: ( diff bar.txt foo-missing-with-main.txt || true ) | not grep "^<"
+
+// Second case: coverage from DSO.
+// cd %T
+// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %dynamiclib -DFOOBAR -shared -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=func %s %dynamiclib -o %t -DMAIN
+// RUN: export LIBNAME=`basename %dynamiclib`
+// RUN: rm -rf %T/coverage-missing
+// RUN: mkdir -p %T/coverage-missing
+// RUN: cd %T/coverage-missing
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x
+// RUN: %sancov print $LIBNAME.*.sancov > foo.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat foo.txt | wc -l) == 2 ]
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS %t x x
+// RUN: %sancov print $LIBNAME.*.sancov > bar.txt
+// RUN: rm *.sancov
+// RUN: [ $(cat bar.txt | wc -l) == 3 ]
+// RUN: %sancov missing %dynamiclib < foo.txt > foo-missing.txt
+// RUN: ( diff bar.txt foo-missing.txt || true ) | not grep "^<"
+
+// REQUIRES: x86_64-supported-target, i386-supported-target
+// XFAIL: android
+
+#include <stdio.h>
+
+void foo1();
+void foo2();
+void bar1();
+void bar2();
+void bar3();
+
+#if defined(FOOBAR)
+void foo1() { fprintf(stderr, "foo1\n"); }
+void foo2() { fprintf(stderr, "foo2\n"); }
+
+void bar1() { fprintf(stderr, "bar1\n"); }
+void bar2() { fprintf(stderr, "bar2\n"); }
+void bar3() { fprintf(stderr, "bar3\n"); }
+#endif
+
+#if defined(MAIN)
+int main(int argc, char **argv) {
+ switch (argc) {
+ case 1:
+ break;
+ case 2:
+ foo1();
+ foo2();
+ break;
+ case 3:
+ bar1();
+ bar2();
+ bar3();
+ break;
+ }
+}
+#endif
diff --git a/test/asan/TestCases/Linux/coverage-module-unloaded.cc b/test/asan/TestCases/Linux/coverage-module-unloaded.cc
deleted file mode 100644
index f8d9c57f81be9..0000000000000
--- a/test/asan/TestCases/Linux/coverage-module-unloaded.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Check that unloading a module doesn't break coverage dumping for remaining
-// modules.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_2.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
-// RUN: mkdir -p %T/coverage-module-unloaded && cd %T/coverage-module-unloaded
-// RUN: %run %t 2>&1 | FileCheck %s
-// RUN: %run %t foo 2>&1 | FileCheck %s
-// RUN: cd .. && rm coverage-module-unloaded -r
-//
-// https://code.google.com/p/address-sanitizer/issues/detail?id=263
-// XFAIL: android
-
-#include <assert.h>
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#ifdef SHARED
-extern "C" {
-void bar() { printf("bar\n"); }
-}
-#else
-
-int main(int argc, char **argv) {
- fprintf(stderr, "PID: %d\n", getpid());
- void *handle1 =
- dlopen(SO_DIR "/libcoverage_module_unloaded_test_1.so", RTLD_LAZY);
- assert(handle1);
- void (*bar1)() = (void (*)())dlsym(handle1, "bar");
- assert(bar1);
- bar1();
- void *handle2 =
- dlopen(SO_DIR "/libcoverage_module_unloaded_test_2.so", RTLD_LAZY);
- assert(handle2);
- void (*bar2)() = (void (*)())dlsym(handle2, "bar");
- assert(bar2);
- bar2();
-
- // It matters whether the unloaded module has a higher or lower address range
- // than the remaining one. Make sure to test both cases.
- if (argc < 2)
- dlclose(bar1 < bar2 ? handle1 : handle2);
- else
- dlclose(bar1 < bar2 ? handle2 : handle1);
- return 0;
-}
-#endif
-
-// CHECK: PID: [[PID:[0-9]+]]
-// CHECK: [[PID]].sancov: 1 PCs written
-// CHECK: .so.[[PID]]
-// If we get coverage for both DSOs, it means the module wasn't unloaded and
-// this test is useless.
-// CHECK-NOT: .so.[[PID]]
diff --git a/test/asan/TestCases/Linux/coverage-reset.cc b/test/asan/TestCases/Linux/coverage-reset.cc
deleted file mode 100644
index d3d35e21b5a72..0000000000000
--- a/test/asan/TestCases/Linux/coverage-reset.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// Test __sanitizer_reset_coverage().
-
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t
-// RUN: ASAN_OPTIONS=coverage=1 %run %t
-
-#include <sanitizer/coverage_interface.h>
-#include <stdio.h>
-#include <assert.h>
-static volatile int sink;
-__attribute__((noinline)) void bar() { sink = 2; }
-__attribute__((noinline)) void foo() { sink = 1; }
-
-#define GET_AND_PRINT_COVERAGE() \
- bitset = 0; \
- for (size_t i = 0; i < n_guards; i++) \
- if (guards[i]) bitset |= 1U << i; \
- printf("line %d: bitset %zd total: %zd\n", __LINE__, bitset, \
- __sanitizer_get_total_unique_coverage());
-
-#define IS_POWER_OF_TWO(a) ((a & ((a) - 1)) == 0)
-
-int main() {
- size_t *guards = 0;
- size_t bitset;
- size_t n_guards = __sanitizer_get_coverage_guards(&guards);
-
- GET_AND_PRINT_COVERAGE();
- size_t main_bit = bitset;
- assert(IS_POWER_OF_TWO(main_bit));
-
- foo();
- GET_AND_PRINT_COVERAGE();
- size_t foo_bit = bitset & ~main_bit;
- assert(IS_POWER_OF_TWO(foo_bit));
-
- bar();
- GET_AND_PRINT_COVERAGE();
- size_t bar_bit = bitset & ~(main_bit | foo_bit);
- assert(IS_POWER_OF_TWO(bar_bit));
-
- __sanitizer_reset_coverage();
- GET_AND_PRINT_COVERAGE();
- assert(bitset == 0);
-
- foo();
- GET_AND_PRINT_COVERAGE();
- assert(bitset == foo_bit);
-
- bar();
- GET_AND_PRINT_COVERAGE();
- assert(bitset == (foo_bit | bar_bit));
-}
diff --git a/test/asan/TestCases/Linux/coverage-sandboxing.cc b/test/asan/TestCases/Linux/coverage-sandboxing.cc
deleted file mode 100644
index 1a72c6bb9a6e3..0000000000000
--- a/test/asan/TestCases/Linux/coverage-sandboxing.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_sandboxing_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_sandboxing_test
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
-// RUN: rm -rf %T/coverage_sandboxing_test
-// RUN: mkdir %T/coverage_sandboxing_test && cd %T/coverage_sandboxing_test
-// RUN: mkdir vanilla && cd vanilla
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-vanilla
-// RUN: mkdir ../sandbox1 && cd ../sandbox1
-// RUN: %run %t a 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox
-// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed
-// RUN: mkdir ../sandbox2 && cd ../sandbox2
-// RUN: %run %t a b 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox
-// RUN: %sancov unpack coverage_sandboxing_test.sancov.packed
-// RUN: cd ..
-// RUN: %sancov print vanilla/libcoverage_sandboxing_test.so.*.sancov > vanilla.txt
-// RUN: %sancov print sandbox1/libcoverage_sandboxing_test.so.*.sancov > sandbox1.txt
-// RUN: %sancov print sandbox2/libcoverage_sandboxing_test.so.*.sancov > sandbox2.txt
-// RUN: diff vanilla.txt sandbox1.txt
-// RUN: diff vanilla.txt sandbox2.txt
-// RUN: cd ../ && rm coverage_sandboxing_test -r
-// https://code.google.com/p/address-sanitizer/issues/detail?id=263
-// XFAIL: android
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sanitizer/coverage_interface.h>
-
-#define bb0(n) \
- case n: \
- fprintf(stderr, "foo: %d\n", n); \
- break;
-
-#define bb1(n) bb0(n) bb0(n + 1)
-#define bb2(n) bb1(n) bb1(n + 2)
-#define bb3(n) bb2(n) bb2(n + 4)
-#define bb4(n) bb3(n) bb3(n + 8)
-#define bb5(n) bb4(n) bb4(n + 16)
-#define bb6(n) bb5(n) bb5(n + 32)
-#define bb7(n) bb6(n) bb6(n + 64)
-#define bb8(n) bb7(n) bb7(n + 128)
-
-#ifdef SHARED
-void foo(int i) {
- switch(i) {
- // 256 basic blocks
- bb8(0)
- }
-}
-#else
-extern void foo(int i);
-
-int main(int argc, char **argv) {
- assert(argc <= 3);
- for (int i = 0; i < 256; i++) foo(i);
- fprintf(stderr, "PID: %d\n", getpid());
- if (argc == 1) {
- // Vanilla mode, dump to individual files.
- return 0;
- }
- // Dump to packed file.
- int fd = creat("coverage_sandboxing_test.sancov.packed", 0660);
- __sanitizer_sandbox_arguments args = {0};
- args.coverage_sandboxed = 1;
- args.coverage_fd = fd;
- if (argc == 2)
- // Write to packed file, do not split into blocks.
- args.coverage_max_block_size = 0;
- else if (argc == 3)
- // Write to packed file, split into blocks (as if writing to a socket).
- args.coverage_max_block_size = 100;
- __sanitizer_sandbox_on_notify(&args);
- return 0;
-}
-#endif
-
-// CHECK-vanilla: PID: [[PID:[0-9]+]]
-// CHECK-vanilla: [[PID]].sancov: 1 PCs written
-// CHECK-vanilla: .so.[[PID]].sancov: 258 PCs written
-
-// CHECK-sandbox: PID: [[PID:[0-9]+]]
-// CHECK-sandbox: 258 PCs written to packed file
diff --git a/test/asan/TestCases/Linux/coverage-tracing.cc b/test/asan/TestCases/Linux/coverage-tracing.cc
deleted file mode 100644
index 49dbb5e9528b9..0000000000000
--- a/test/asan/TestCases/Linux/coverage-tracing.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Test -mllvm -sanitizer-coverage-experimental-tracing
-//
-// RUN: %clangxx_asan -O1 -fsanitize-coverage=1 -mllvm -sanitizer-coverage-experimental-tracing %s -o %t
-// RUN: rm -rf %T/coverage-tracing
-// RUN: mkdir %T/coverage-tracing
-// RUN: cd %T/coverage-tracing
-// RUN: A=x; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK1; mv trace-points.*.sancov $A.points
-// RUN: A=f; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
-// RUN: A=b; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK2; mv trace-points.*.sancov $A.points
-// RUN: A=bf; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
-// RUN: A=fb; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK3; mv trace-points.*.sancov $A.points
-// RUN: A=ffb; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
-// RUN: A=fff; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 1 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK4; mv trace-points.*.sancov $A.points
-// RUN: A=bbf; ASAN_OPTIONS=coverage=1:verbosity=1 %run %t $A 100 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK301; mv trace-points.*.sancov $A.points
-// RUN: diff f.points fff.points
-// RUN: diff bf.points fb.points
-// RUN: diff bf.points ffb.points
-// RUN: diff bf.points bbf.points
-// RUN: not diff x.points f.points
-// RUN: not diff x.points b.points
-// RUN: not diff x.points bf.points
-// RUN: not diff f.points b.points
-// RUN: not diff f.points bf.points
-// RUN: not diff b.points bf.points
-// RUN: rm -rf %T/coverage-tracing
-//
-// REQUIRES: asan-64-bits
-
-#include <stdlib.h>
-volatile int sink;
-__attribute__((noinline)) void foo() { sink++; }
-__attribute__((noinline)) void bar() { sink++; }
-
-int main(int argc, char **argv) {
- if (argc != 3) return 0;
- int n = strtol(argv[2], 0, 10);
- while (n-- > 0) {
- for (int i = 0; argv[1][i]; i++) {
- if (argv[1][i] == 'f') foo();
- else if (argv[1][i] == 'b') bar();
- }
- }
-}
-
-// CHECK: CovDump: Trace: 3 PCs written
-// CHECK1: CovDump: Trace: 1 Events written
-// CHECK2: CovDump: Trace: 2 Events written
-// CHECK3: CovDump: Trace: 3 Events written
-// CHECK4: CovDump: Trace: 4 Events written
-// CHECK301: CovDump: Trace: 301 Events written
diff --git a/test/asan/TestCases/Linux/coverage.cc b/test/asan/TestCases/Linux/coverage.cc
deleted file mode 100644
index 06fe1a295eafb..0000000000000
--- a/test/asan/TestCases/Linux/coverage.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_test
-// RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
-// RUN: mkdir -p %T/coverage && cd %T/coverage
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main
-// RUN: %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo
-// RUN: %run %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar
-// RUN: %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
-// RUN: not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report
-// RUN: not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv
-// RUN: cd .. && rm coverage -r
-//
-// https://code.google.com/p/address-sanitizer/issues/detail?id=263
-// XFAIL: android
-
-#include <sanitizer/coverage_interface.h>
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef SHARED
-void bar() { printf("bar\n"); }
-#else
-__attribute__((noinline))
-void foo() { printf("foo\n"); }
-extern void bar();
-
-int G[4];
-
-int main(int argc, char **argv) {
- fprintf(stderr, "PID: %d\n", getpid());
- for (int i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "foo")) {
- uintptr_t old_coverage = __sanitizer_get_total_unique_coverage();
- foo();
- uintptr_t new_coverage = __sanitizer_get_total_unique_coverage();
- assert(new_coverage > old_coverage);
- }
- if (!strcmp(argv[i], "bar"))
- bar();
- }
- if (argc == 5) {
- static volatile char *zero = 0;
- *zero = 0; // SEGV if argc == 5.
- }
- return G[argc]; // Buffer overflow if argc >= 4.
-}
-#endif
-
-// CHECK-main: PID: [[PID:[0-9]+]]
-// CHECK-main: [[PID]].sancov: 1 PCs written
-// CHECK-main-NOT: .so.[[PID]]
-//
-// CHECK-foo: PID: [[PID:[0-9]+]]
-// CHECK-foo: [[PID]].sancov: 2 PCs written
-// CHECK-foo-NOT: .so.[[PID]]
-//
-// CHECK-bar: PID: [[PID:[0-9]+]]
-// CHECK-bar: [[PID]].sancov: 1 PCs written
-// CHECK-bar: .so.[[PID]].sancov: 1 PCs written
-//
-// CHECK-foo-bar: PID: [[PID:[0-9]+]]
-// CHECK-foo-bar: [[PID]].sancov: 2 PCs written
-// CHECK-foo-bar: so.[[PID]].sancov: 1 PCs written
-//
-// CHECK-report: AddressSanitizer: global-buffer-overflow
-// CHECK-report: PCs written
-//
-// CHECK-segv: AddressSanitizer: SEGV
-// CHECK-segv: PCs written
diff --git a/test/asan/TestCases/Linux/init-order-dlopen.cc b/test/asan/TestCases/Linux/init-order-dlopen.cc
new file mode 100644
index 0000000000000..fcfb5d143df6c
--- /dev/null
+++ b/test/asan/TestCases/Linux/init-order-dlopen.cc
@@ -0,0 +1,47 @@
+// Regression test for
+// https://code.google.com/p/address-sanitizer/issues/detail?id=178
+
+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
+// RUN: %clangxx_asan -O0 %s %libdl -Wl,--export-dynamic -o %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t 2>&1
+
+// dlopen() can not be intercepted on Android, making strict_init_order nearly
+// useless there.
+// UNSUPPORTED: android
+
+#if defined(SHARED_LIB)
+#include <stdio.h>
+
+struct Bar {
+ Bar(int val) : val(val) { printf("Bar::Bar(%d)\n", val); }
+ int val;
+};
+
+int get_foo_val();
+Bar global_bar(get_foo_val());
+#else // SHARED LIB
+#include <dlfcn.h>
+#include <stdio.h>
+#include <string>
+struct Foo {
+ Foo() : val(42) { printf("Foo::Foo()\n"); }
+ int val;
+};
+
+Foo global_foo;
+
+int get_foo_val() {
+ return global_foo.val;
+}
+
+int main(int argc, char *argv[]) {
+ std::string path = std::string(argv[0]) + "-so.so";
+ void *handle = dlopen(path.c_str(), RTLD_NOW);
+ if (!handle) {
+ printf("error in dlopen(): %s\n", dlerror());
+ return 1;
+ }
+ printf("%d\n", get_foo_val());
+ return 0;
+}
+#endif // SHARED_LIB
diff --git a/test/asan/TestCases/Linux/initialization-bug-any-order.cc b/test/asan/TestCases/Linux/initialization-bug-any-order.cc
index a462f4a163f1c..0f2fccae79bba 100644
--- a/test/asan/TestCases/Linux/initialization-bug-any-order.cc
+++ b/test/asan/TestCases/Linux/initialization-bug-any-order.cc
@@ -4,9 +4,9 @@
// strict init-order checking).
// RUN: %clangxx_asan -O0 %s %p/../Helpers/initialization-bug-extra.cc -o %t
-// RUN: ASAN_OPTIONS=strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_asan -O0 %p/../Helpers/initialization-bug-extra.cc %s -o %t
-// RUN: ASAN_OPTIONS=strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
// Do not test with optimization -- the error may be optimized away.
diff --git a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc b/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
deleted file mode 100644
index b828d5524ee0d..0000000000000
--- a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Check that memset() call from a shared library gets intercepted.
-// Please always keep this file in sync with
-// ../Darwin/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
-// TODO(glider): figure out how to set rpath in a more portable way and unite
-// this test with ../Darwin/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \
-// RUN: not %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <string.h>
-
-#if defined(SHARED_LIB)
-extern "C"
-void my_memset(void *p, size_t sz) {
- memset(p, 0, sz);
-}
-#else
-extern "C" void my_memset(void *p, size_t sz);
-
-int main(int argc, char *argv[]) {
- char buf[10];
- my_memset(buf, 11);
- // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
- // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
- // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
- return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Linux/interface_symbols_linux.c b/test/asan/TestCases/Linux/interface_symbols_linux.c
index a616732ff9f80..9e876799d384b 100644
--- a/test/asan/TestCases/Linux/interface_symbols_linux.c
+++ b/test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -24,8 +24,22 @@
// 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_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: echo __asan_alloca_poison >> %t.interface
+// RUN: echo __asan_allocas_unpoison >> %t.interface
// RUN: cat %t.interface | sort -u | diff %t.symbols -
// FIXME: nm -D on powerpc somewhy shows ASan interface symbols residing
diff --git a/test/asan/TestCases/Linux/kernel-area.cc b/test/asan/TestCases/Linux/kernel-area.cc
index 8dd509f849755..8d3f7d6f8e88d 100644
--- a/test/asan/TestCases/Linux/kernel-area.cc
+++ b/test/asan/TestCases/Linux/kernel-area.cc
@@ -4,19 +4,19 @@
// Test that kernel area is not sanitized on 32-bit machines.
//
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
-// RUN: ASAN_OPTIONS=verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
-// RUN: ASAN_OPTIONS=verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits
//
-// CHECK-kernel-32-bits: || `[0x38000000, 0xbfffffff]` || HighMem ||
-// CHECK-kernel-32-bits: || `[0x27000000, 0x37ffffff]` || HighShadow ||
-// CHECK-kernel-32-bits: || `[0x24000000, 0x26ffffff]` || ShadowGap ||
+// CHECK-kernel-32-bits: || `[0x38{{0+}}, 0xb{{f+}}]` || HighMem ||
+// CHECK-kernel-32-bits: || `[0x27{{0+}}, 0x37{{f+}}]` || HighShadow ||
+// CHECK-kernel-32-bits: || `[0x24{{0+}}, 0x26{{f+}}]` || ShadowGap ||
//
-// CHECK-kernel-64-bits: || `[0x40000000, 0xffffffff]` || HighMem ||
-// CHECK-kernel-64-bits: || `[0x28000000, 0x3fffffff]` || HighShadow ||
-// CHECK-kernel-64-bits: || `[0x24000000, 0x27ffffff]` || ShadowGap ||
+// CHECK-kernel-64-bits: || `[0x4{{0+}}, 0x{{f+}}]` || HighMem ||
+// CHECK-kernel-64-bits: || `[0x28{{0+}}, 0x3{{f+}}]` || HighShadow ||
+// CHECK-kernel-64-bits: || `[0x24{{0+}}, 0x27{{f+}}]` || ShadowGap ||
//
-// REQUIRES: asan-32-bits
+// REQUIRES: asan-32-bits,i386-supported-target
int main() {
return 0;
diff --git a/test/asan/TestCases/Linux/leak.cc b/test/asan/TestCases/Linux/leak.cc
index 36dc6ddb8adfb..15c03b45e4c98 100644
--- a/test/asan/TestCases/Linux/leak.cc
+++ b/test/asan/TestCases/Linux/leak.cc
@@ -2,9 +2,9 @@
// REQUIRES: leak-detection
//
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=detect_leaks=1 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS="" not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_leaks=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:detect_leaks=0 %run %t
#include <stdio.h>
int *t;
diff --git a/test/asan/TestCases/Linux/leak_check_segv.cc b/test/asan/TestCases/Linux/leak_check_segv.cc
new file mode 100644
index 0000000000000..8160d5fe56bb1
--- /dev/null
+++ b/test/asan/TestCases/Linux/leak_check_segv.cc
@@ -0,0 +1,23 @@
+// Test that SIGSEGV during leak checking does not crash the process.
+// RUN: %clangxx_asan -O1 %s -o %t && LSAN_OPTIONS="verbosity=1" not %run %t 2>&1
+// REQUIRES: leak-detection
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sanitizer/lsan_interface.h>
+
+char data[10 * 1024 * 1024];
+
+int main() {
+ void *p = malloc(10 * 1024 * 1024);
+ // surprise-surprise!
+ mprotect((void*)(((unsigned long)p + 4095) & ~4095), 16 * 1024, PROT_NONE);
+ mprotect((void*)(((unsigned long)data + 4095) & ~4095), 16 * 1024, PROT_NONE);
+ __lsan_do_leak_check();
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: Tracer caught signal 11
+// CHECK: LeakSanitizer has encountered a fatal error
+// CHECK-NOT: DONE
+
diff --git a/test/asan/TestCases/Linux/malloc-in-qsort.cc b/test/asan/TestCases/Linux/malloc-in-qsort.cc
index 80af409d66a94..f7c7c5fe3df73 100644
--- a/test/asan/TestCases/Linux/malloc-in-qsort.cc
+++ b/test/asan/TestCases/Linux/malloc-in-qsort.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
-// RUN: ASAN_OPTIONS=fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
// Test how well we unwind in presence of qsort in the stack
// (i.e. if we can unwind through a function compiled w/o frame pointers).
diff --git a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
index 18d65ce0008f6..33d0ede15f3c0 100644
--- a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
+++ b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
@@ -4,14 +4,14 @@
// RUN: %clangxx_asan -g %s -o %t 2>&1
// Find error and provide malloc context.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
// No error here.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=0 %run %t
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=0 %run %t
// Also works if no malloc context is available.
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
#include <stdlib.h>
diff --git a/test/asan/TestCases/Linux/nohugepage_test.cc b/test/asan/TestCases/Linux/nohugepage_test.cc
index b549f3bc2119b..aeb70c94ec994 100644
--- a/test/asan/TestCases/Linux/nohugepage_test.cc
+++ b/test/asan/TestCases/Linux/nohugepage_test.cc
@@ -3,8 +3,8 @@
// where asan consumed too much RAM due to transparent hugetables.
//
// RUN: %clangxx_asan -g %s -o %t
-// RUN: ASAN_OPTIONS=no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s
+// RUN: %run %t 2>&1 | FileCheck %s
//
// Would be great to run the test with no_huge_pages_for_shadow=0, but
// the result will depend on the OS version and settings...
@@ -22,15 +22,31 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <errno.h>
#include <sanitizer/asan_interface.h>
-char FileContents[1 << 14];
+char FileContents[1 << 16];
void FileToString(const char *path) {
FileContents[0] = 0;
int fd = open(path, 0);
if (fd < 0) return;
- ssize_t res = read(fd, FileContents, sizeof(FileContents) - 1);
+ char *p = FileContents;
+ ssize_t size = sizeof(FileContents) - 1;
+ ssize_t res = 0;
+ do {
+ ssize_t got = read (fd, p, size);
+ if (got == 0)
+ break;
+ else if (got > 0)
+ {
+ p += got;
+ res += got;
+ size -= got;
+ }
+ else if (errno != EINTR)
+ break;
+ } while (size > 0 && res < sizeof(FileContents));
if (res >= 0)
FileContents[res] = 0;
}
diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc
index ddc68a2db0f18..e9311d16bd5fb 100644
--- a/test/asan/TestCases/Linux/odr-violation.cc
+++ b/test/asan/TestCases/Linux/odr-violation.cc
@@ -1,19 +1,27 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
// XFAIL: android
//
+// We use fast_unwind_on_malloc=0 to have full unwinding even w/o frame
+// pointers. This setting is not on by default because it's too expensive.
+//
// Different size: detect a bug if detect_odr_violation>=1
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
-// RUN: ASAN_OPTIONS=detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
//
// Same size: report a bug only if detect_odr_violation>=2.
// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
-// RUN: ASAN_OPTIONS=detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
-// RUN: not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::ZZZ" > %t.supp
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: echo "odr_violation:foo::G" > %t.supp
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_malloc=0:detect_odr_violation=2:suppressions=%t.supp %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: rm -f %t.supp
// GNU driver doesn't handle .so files properly.
// REQUIRES: Clang
diff --git a/test/asan/TestCases/Linux/overflow-in-qsort.cc b/test/asan/TestCases/Linux/overflow-in-qsort.cc
index 21bdff60cd305..26fe67d60729b 100644
--- a/test/asan/TestCases/Linux/overflow-in-qsort.cc
+++ b/test/asan/TestCases/Linux/overflow-in-qsort.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
-// RUN: ASAN_OPTIONS=fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:fast_unwind_on_fatal=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SLOW
// Test how well we unwind in presence of qsort in the stack
// (i.e. if we can unwind through a function compiled w/o frame pointers).
diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc
index 7e5acb64c7a13..6840ebe28bfd3 100644
--- a/test/asan/TestCases/Linux/ptrace.cc
+++ b/test/asan/TestCases/Linux/ptrace.cc
@@ -31,8 +31,8 @@ int main(void) {
// CHECK: AddressSanitizer: stack-buffer-overflow
// CHECK: {{.*ptrace.cc:}}[[@LINE-2]]
assert(!res);
-#if __WORDSIZE == 64
- printf("%zx\n", regs.rip);
+#ifdef __x86_64__
+ printf("%lx\n", (unsigned long)regs.rip);
#else
printf("%lx\n", regs.eip);
#endif
@@ -42,7 +42,7 @@ int main(void) {
assert(!res);
printf("%lx\n", (unsigned long)fpregs.cwd);
-#if __WORDSIZE == 32
+#ifndef __x86_64__
user_fpxregs_struct fpxregs;
res = ptrace(PTRACE_GETFPXREGS, pid, NULL, &fpxregs);
assert(!res);
diff --git a/test/asan/TestCases/Linux/quarantine_size_mb.cc b/test/asan/TestCases/Linux/quarantine_size_mb.cc
index 4499992444f9b..1820cb90c4ef6 100644
--- a/test/asan/TestCases/Linux/quarantine_size_mb.cc
+++ b/test/asan/TestCases/Linux/quarantine_size_mb.cc
@@ -1,10 +1,10 @@
// Test quarantine_size_mb (and the deprecated quarantine_size)
// RUN: %clangxx_asan %s -o %t
-// RUN: ASAN_OPTIONS=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
-// RUN: ASAN_OPTIONS=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
-// RUN: ASAN_OPTIONS=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
-// RUN: ASAN_OPTIONS=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
-// RUN: ASAN_OPTIONS=hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
#include <string.h>
char *g;
diff --git a/test/asan/TestCases/Linux/read_binary_name_regtest.c b/test/asan/TestCases/Linux/read_binary_name_regtest.c
new file mode 100644
index 0000000000000..0e408d0e366d1
--- /dev/null
+++ b/test/asan/TestCases/Linux/read_binary_name_regtest.c
@@ -0,0 +1,50 @@
+// Regression test for https://crbug.com/502974, where ASan was unable to read
+// the binary name because of sandbox restrictions.
+// This test uses seccomp-BPF to restrict the readlink() system call and makes
+// sure ASan is still able to
+// RUN: not ls /usr/include/linux/seccomp.h || ( %clang_asan %s -o %t && not %run %t 2>&1 | FileCheck %s )
+// UNSUPPORTED: android
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/prctl.h>
+#include <sys/syscall.h>
+#include <linux/filter.h>
+#include <linux/seccomp.h>
+
+#define syscall_nr (offsetof(struct seccomp_data, nr))
+
+void corrupt() {
+ void *p = malloc(10);
+ free(p);
+ free(p);
+}
+
+int main() {
+ prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
+
+ struct sock_filter filter[] = {
+ /* Grab the system call number */
+ BPF_STMT(BPF_LD + BPF_W + BPF_ABS, syscall_nr),
+ // If this is __NR_readlink,
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, __NR_readlink, 0, 1),
+ // return with EPERM,
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ERRNO | EPERM),
+ // otherwise allow the syscall.
+ BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW)
+ };
+ struct sock_fprog prog;
+ prog.len = (unsigned short)(sizeof(filter)/sizeof(filter[0]));
+ prog.filter = filter;
+
+ int res = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog, 0, 0);
+ if (res != 0) {
+ fprintf(stderr, "PR_SET_SECCOMP unsupported!\n");
+ }
+ corrupt();
+ // CHECK: AddressSanitizer
+ // CHECK-NOT: reading executable name failed
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/signal_during_stop_the_world.cc b/test/asan/TestCases/Linux/signal_during_stop_the_world.cc
new file mode 100644
index 0000000000000..b1a41fe20c05d
--- /dev/null
+++ b/test/asan/TestCases/Linux/signal_during_stop_the_world.cc
@@ -0,0 +1,60 @@
+// Test StopTheWorld behavior during signal storm.
+// Historically StopTheWorld crashed because did not handle EINTR properly.
+// The test is somewhat convoluted, but that's what caused crashes previously.
+
+// RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <time.h>
+#include <pthread.h>
+#include <sanitizer/lsan_interface.h>
+
+static void handler(int signo);
+static void *thr(void *arg);
+
+int main() {
+ struct sigaction act = {};
+ act.sa_handler = handler;
+ sigaction(SIGPROF, &act, 0);
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "failed to fork\n");
+ exit(1);
+ }
+ if (pid == 0) {
+ // Child constantly sends signals to parent to cause spurious return from
+ // waitpid in StopTheWorld.
+ prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+ pid_t parent = getppid();
+ for (;;) {
+ // There is no strong reason for these two particular signals,
+ // but at least one of them ought to unblock waitpid.
+ kill(parent, SIGCHLD);
+ kill(parent, SIGPROF);
+ }
+ }
+ usleep(10000); // Let the child start.
+ __lsan_do_leak_check();
+ // Kill and join the child.
+ kill(pid, SIGTERM);
+ waitpid(pid, 0, 0);
+ sleep(1); // If the tracer thread still runs, give it time to crash.
+ fprintf(stderr, "DONE\n");
+// CHECK: DONE
+}
+
+static void handler(int signo) {
+}
+
+static void *thr(void *arg) {
+ for (;;)
+ sleep(1);
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/sized_delete_test.cc b/test/asan/TestCases/Linux/sized_delete_test.cc
index 343cb0a86fedc..1146b8239d8c7 100644
--- a/test/asan/TestCases/Linux/sized_delete_test.cc
+++ b/test/asan/TestCases/Linux/sized_delete_test.cc
@@ -1,14 +1,10 @@
-// RUN: %clangxx_asan -Xclang -fsized-deallocation -O0 %s -o %t
-// RUN: not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=1 not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
-// RUN: not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=0 %run %t scalar
-// RUN: ASAN_OPTIONS=new_delete_type_mismatch=0 %run %t array
-
-// Sized-delete is implemented with a weak delete() definition.
-// Weak symbols are kind of broken on Android.
-// XFAIL: android, asan-dynamic-runtime
+// RUN: %clangxx_asan -fsized-deallocation -O0 %s -o %t
+// RUN: not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=1 not %run %t scalar 2>&1 | FileCheck %s -check-prefix=SCALAR
+// RUN: not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=0 %run %t scalar
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:new_delete_type_mismatch=0 %run %t array
#include <new>
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/stack-overflow-sigbus.cc b/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
index 5f597e9c51f0f..23c4d23ce406e 100644
--- a/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
+++ b/test/asan/TestCases/Linux/stack-overflow-sigbus.cc
@@ -1,6 +1,6 @@
// Test ASan detection of stack-overflow condition when Linux sends SIGBUS.
-// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/stack-trace-dlclose.cc b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
index b3bd9f7780f5a..f207a94ae65e3 100644
--- a/test/asan/TestCases/Linux/stack-trace-dlclose.cc
+++ b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
@@ -3,7 +3,7 @@
//
// RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC
// RUN: %clangxx_asan -DSO_DIR=\"%T\" %s %libdl -o %t
-// RUN: ASAN_OPTIONS=exitcode=0 %run %t 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:exitcode=0 %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
@@ -40,6 +40,6 @@ int main(int argc, char **argv) {
}
#endif
-// CHECK: {{ #0 0x.* in malloc}}
+// CHECK: {{ #0 0x.* in (__interceptor_)?malloc}}
// CHECK: {{ #1 0x.* \(<unknown module>\)}}
// CHECK: {{ #2 0x.* in main}}
diff --git a/test/asan/TestCases/Linux/static_tls.cc b/test/asan/TestCases/Linux/static_tls.cc
new file mode 100644
index 0000000000000..785228b292388
--- /dev/null
+++ b/test/asan/TestCases/Linux/static_tls.cc
@@ -0,0 +1,29 @@
+// REQUIRES: asan-64-bits
+// Regression test: __tls_get_addr interceptor must recognize static TLS.
+//
+// RUN: %clangxx_asan -DSHARED %s -shared -o %t-so.so -fPIC
+// RUN: %clangxx_asan %s -ldl -pthread -o %t %t-so.so
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %run %t 2>&1 | FileCheck %s
+
+// CHECK: before
+// CHECK: __tls_get_addr: static tls
+// CHECK: after
+
+// XFAIL: powerpc64
+
+#ifndef SHARED
+#include <stdio.h>
+
+unsigned *f();
+int main(int argc, char *argv[]) {
+ fprintf(stderr, "before\n");
+ f();
+ fprintf(stderr, "after\n");
+ return 0;
+}
+#else // SHARED
+static __thread unsigned ThreadLocal;
+unsigned *f() {
+ return &ThreadLocal;
+}
+#endif
diff --git a/test/asan/TestCases/Linux/stress_dtls.c b/test/asan/TestCases/Linux/stress_dtls.c
index cb901ee59953a..7af33b9457ea0 100644
--- a/test/asan/TestCases/Linux/stress_dtls.c
+++ b/test/asan/TestCases/Linux/stress_dtls.c
@@ -12,9 +12,9 @@
// RUN: %clangxx_asan %s -ldl -pthread -o %t
// RUN: %run %t 0 3
// RUN: %run %t 2 3
-// RUN: ASAN_OPTIONS=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
// CHECK: __tls_get_addr
// CHECK: Creating thread 0
// CHECK: __tls_get_addr