aboutsummaryrefslogtreecommitdiff
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/abort_on_error.cc18
-rw-r--r--test/asan/TestCases/Linux/activation-options.cc71
-rw-r--r--test/asan/TestCases/Linux/asan_prelink_test.cc2
-rw-r--r--test/asan/TestCases/Linux/calloc-preload.c36
-rw-r--r--test/asan/TestCases/Linux/coverage-missing.cc12
-rw-r--r--test/asan/TestCases/Linux/init-order-dlopen.cc2
-rw-r--r--test/asan/TestCases/Linux/init_fini_sections.cc24
-rw-r--r--test/asan/TestCases/Linux/initialization-bug-any-order.cc4
-rw-r--r--test/asan/TestCases/Linux/interface_symbols_linux.c14
-rw-r--r--test/asan/TestCases/Linux/kernel-area.cc6
-rw-r--r--test/asan/TestCases/Linux/leak.cc6
-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/mincore.cc34
-rw-r--r--test/asan/TestCases/Linux/nohugepage_test.cc4
-rw-r--r--test/asan/TestCases/Linux/odr-violation.cc18
-rw-r--r--test/asan/TestCases/Linux/overflow-in-qsort.cc4
-rw-r--r--test/asan/TestCases/Linux/pthread_create_version.cc23
-rw-r--r--test/asan/TestCases/Linux/ptrace.cc93
-rw-r--r--test/asan/TestCases/Linux/quarantine_size_mb.cc10
-rw-r--r--test/asan/TestCases/Linux/read_binary_name_regtest.c4
-rw-r--r--test/asan/TestCases/Linux/sized_delete_test.cc8
-rw-r--r--test/asan/TestCases/Linux/stack-overflow-sigbus.cc2
-rw-r--r--test/asan/TestCases/Linux/stack-trace-dlclose.cc2
-rw-r--r--test/asan/TestCases/Linux/static_tls.cc4
-rw-r--r--test/asan/TestCases/Linux/stress_dtls.c7
26 files changed, 355 insertions, 65 deletions
diff --git a/test/asan/TestCases/Linux/abort_on_error.cc b/test/asan/TestCases/Linux/abort_on_error.cc
new file mode 100644
index 000000000000..406d98b6764a
--- /dev/null
+++ b/test/asan/TestCases/Linux/abort_on_error.cc
@@ -0,0 +1,18 @@
+// Check that with empty ASAN_OPTIONS, ASan reports on Linux don't crash
+// the process (abort_on_error=0). See also Darwin/abort_on_error.cc.
+
+// RUN: %clangxx_asan %s -o %t
+
+// Intentionally don't inherit the default ASAN_OPTIONS.
+// RUN: ASAN_OPTIONS="" not %run %t 2>&1 | FileCheck %s
+// When we use lit's default ASAN_OPTIONS, we shouldn't crash either. On Linux
+// lit doesn't set ASAN_OPTIONS anyway.
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+}
diff --git a/test/asan/TestCases/Linux/activation-options.cc b/test/asan/TestCases/Linux/activation-options.cc
new file mode 100644
index 000000000000..1a1ad3f8c499
--- /dev/null
+++ b/test/asan/TestCases/Linux/activation-options.cc
@@ -0,0 +1,71 @@
+// Test for ASAN_OPTIONS=start_deactivated=1 mode.
+// Main executable is uninstrumented, but linked to ASan runtime. The shared
+// library is instrumented.
+
+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
+// RUN: %clangxx -O0 %s -c -o %t.o
+// RUN: %clangxx_asan -O0 %t.o %libdl -o %t
+
+// RUN: rm -f %t.asan.options.activation-options.cc.tmp
+// RUN: rm -f %t.asan.options.ABCDE
+// RUN: echo "help=1" >%t.asan.options.activation-options.cc.tmp
+
+// RUN: %env_asan_opts=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND
+
+// RUN: %env_asan_opts=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options not %run %t 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING
+
+// RUN: %env_asan_opts=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b not %run %t --fix-name 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-NO-HELP --check-prefix=CHECK-MISSING
+
+// RUN: echo "help=1" >%t.asan.options.ABCDE
+
+// RUN: %env_asan_opts=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=include=%t.asan.options.%b %run %t --fix-name 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CHECK-HELP --check-prefix=CHECK-FOUND
+
+// XFAIL: arm-linux-gnueabi
+// XFAIL: android
+
+#if !defined(SHARED_LIB)
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <string>
+
+#include "sanitizer/asan_interface.h"
+
+typedef void (*Fn)();
+
+int main(int argc, char *argv[]) {
+ std::string path = std::string(argv[0]) + "-so.so";
+
+ if (argc > 1 && strcmp(argv[1], "--fix-name") == 0) {
+ assert(strlen(argv[0]) > 5);
+ strcpy(argv[0], "ABCDE");
+ }
+
+ void *dso = dlopen(path.c_str(), RTLD_NOW);
+ if (!dso) {
+ fprintf(stderr, "dlopen failed: %s\n", dlerror());
+ return 1;
+ }
+
+ return 0;
+}
+#else // SHARED_LIB
+// Empty: all we need is an ASan shared library constructor.
+#endif // SHARED_LIB
+
+// CHECK-HELP: Available flags for {{.*}}Sanitizer:
+// CHECK-NO-HELP-NOT: Available flags for {{.*}}Sanitizer:
+// CHECK-FOUND-NOT: Failed to read options
+// CHECK-MISSING: Failed to read options
diff --git a/test/asan/TestCases/Linux/asan_prelink_test.cc b/test/asan/TestCases/Linux/asan_prelink_test.cc
index 9e58f83d40c6..d67d945851f9 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: env ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=1 %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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/calloc-preload.c b/test/asan/TestCases/Linux/calloc-preload.c
new file mode 100644
index 000000000000..eb1c6738b6e9
--- /dev/null
+++ b/test/asan/TestCases/Linux/calloc-preload.c
@@ -0,0 +1,36 @@
+// Test that initially callocked memory is properly freed
+// (see https://github.com/google/sanitizers/issues/626).
+//
+// RUN: %clang %s -o %t
+// RUN: env LD_PRELOAD=%shared_libasan %run %t
+//
+// REQUIRES: asan-dynamic-runtime
+//
+// This way of setting LD_PRELOAD does not work with Android test runner.
+// REQUIRES: not-android
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static void *ptr;
+
+// This constructor will run before __asan_init
+// so calloc will allocate memory from special pool.
+static void init() {
+ ptr = calloc(10, 1);
+}
+
+__attribute__((section(".preinit_array"), used))
+void *dummy = init;
+
+void free_memory() {
+ // This used to abort because
+ // Asan's free didn't recognize ptr.
+ free(ptr);
+}
+
+int main() {
+ free_memory();
+ return 0;
+}
+
diff --git a/test/asan/TestCases/Linux/coverage-missing.cc b/test/asan/TestCases/Linux/coverage-missing.cc
index 36f33b505e27..6cd3201c48d1 100644
--- a/test/asan/TestCases/Linux/coverage-missing.cc
+++ b/test/asan/TestCases/Linux/coverage-missing.cc
@@ -1,21 +1,19 @@
// 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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x
// RUN: %sancov print *.sancov > bar.txt
// RUN: rm *.sancov
// RUN: [ $(cat bar.txt | wc -l) == 4 ]
@@ -34,11 +32,11 @@
// 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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %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: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-missing %run %t x x
// RUN: %sancov print $LIBNAME.*.sancov > bar.txt
// RUN: rm *.sancov
// RUN: [ $(cat bar.txt | wc -l) == 3 ]
diff --git a/test/asan/TestCases/Linux/init-order-dlopen.cc b/test/asan/TestCases/Linux/init-order-dlopen.cc
index fcfb5d143df6..d469b98089fe 100644
--- a/test/asan/TestCases/Linux/init-order-dlopen.cc
+++ b/test/asan/TestCases/Linux/init-order-dlopen.cc
@@ -3,7 +3,7 @@
// 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
+// RUN: %env_asan_opts=strict_init_order=true %run %t 2>&1
// dlopen() can not be intercepted on Android, making strict_init_order nearly
// useless there.
diff --git a/test/asan/TestCases/Linux/init_fini_sections.cc b/test/asan/TestCases/Linux/init_fini_sections.cc
new file mode 100644
index 000000000000..c7234eeeac2c
--- /dev/null
+++ b/test/asan/TestCases/Linux/init_fini_sections.cc
@@ -0,0 +1,24 @@
+// RUN: %clangxx_asan %s -o %t && %run %t | FileCheck %s
+
+#include <stdio.h>
+
+static void foo() {
+ printf("foo\n");
+}
+
+int main() {
+ return 0;
+}
+
+__attribute__((section(".preinit_array")))
+void (*call_foo)(void) = &foo;
+
+__attribute__((section(".init_array")))
+void (*call_foo_2)(void) = &foo;
+
+__attribute__((section(".fini_array")))
+void (*call_foo_3)(void) = &foo;
+
+// CHECK: foo
+// CHECK: foo
+// CHECK: foo
diff --git a/test/asan/TestCases/Linux/initialization-bug-any-order.cc b/test/asan/TestCases/Linux/initialization-bug-any-order.cc
index 0f2fccae79bb..85fefd40ee03 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: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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/interface_symbols_linux.c b/test/asan/TestCases/Linux/interface_symbols_linux.c
index 9e876799d384..971feb5dc09f 100644
--- a/test/asan/TestCases/Linux/interface_symbols_linux.c
+++ b/test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -3,7 +3,7 @@
// RUN: %clang_asan -O2 %s -o %t.exe
// RUN: nm -D %t.exe | grep " T " | sed "s/.* T //" \
// RUN: | grep "__asan_" | sed "s/___asan_/__asan_/" \
-// RUN: | sed -E "s/__asan_init_v[0-9]+/__asan_init/" \
+// 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_stack_" \
// RUN: | grep -v "__asan_on_error" > %t.symbols
@@ -24,6 +24,18 @@
// 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
diff --git a/test/asan/TestCases/Linux/kernel-area.cc b/test/asan/TestCases/Linux/kernel-area.cc
index 8d3f7d6f8e88..c0f17272ad27 100644
--- a/test/asan/TestCases/Linux/kernel-area.cc
+++ b/test/asan/TestCases/Linux/kernel-area.cc
@@ -4,9 +4,9 @@
// Test that kernel area is not sanitized on 32-bit machines.
//
// RUN: %clangxx_asan %s -o %t
-// 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
+// RUN: %env_asan_opts=verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: %env_asan_opts=verbosity=1:full_address_space=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%kernel_bits
+// RUN: %env_asan_opts=verbosity=1:full_address_space=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-kernel-64-bits
//
// CHECK-kernel-32-bits: || `[0x38{{0+}}, 0xb{{f+}}]` || HighMem ||
// CHECK-kernel-32-bits: || `[0x27{{0+}}, 0x37{{f+}}]` || HighShadow ||
diff --git a/test/asan/TestCases/Linux/leak.cc b/test/asan/TestCases/Linux/leak.cc
index 15c03b45e4c9..e22cd6eac16f 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: 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
+// RUN: %env_asan_opts=detect_leaks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=detect_leaks=0 %run %t
#include <stdio.h>
int *t;
diff --git a/test/asan/TestCases/Linux/malloc-in-qsort.cc b/test/asan/TestCases/Linux/malloc-in-qsort.cc
index f7c7c5fe3df7..e8c9b7480b76 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: 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
+// RUN: %env_asan_opts=fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: %env_asan_opts=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 33d0ede15f3c..66eed33052c3 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: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
+// RUN: %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=ALLOC-STACK
// No error here.
-// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:alloc_dealloc_mismatch=0 %run %t
+// RUN: %env_asan_opts=alloc_dealloc_mismatch=0 %run %t
// Also works if no malloc context is available.
-// 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
+// RUN: %env_asan_opts=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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/mincore.cc b/test/asan/TestCases/Linux/mincore.cc
new file mode 100644
index 000000000000..30f450830fc2
--- /dev/null
+++ b/test/asan/TestCases/Linux/mincore.cc
@@ -0,0 +1,34 @@
+// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+int main(void) {
+ unsigned char vec[20];
+ int res;
+ size_t PS = sysconf(_SC_PAGESIZE);
+ void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE,
+ MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+
+ res = mincore(addr, 10 * PS, vec);
+ assert(res == 0);
+ for (int i = 0; i < 10; ++i)
+ assert((vec[i] & 1) == 0);
+
+ for (int i = 0; i < 5; ++i)
+ ((char *)addr)[i * PS] = 1;
+ res = mincore(addr, 10 * PS, vec);
+ assert(res == 0);
+ for (int i = 0; i < 10; ++i)
+ assert((vec[i] & 1) == (i < 5));
+
+ for (int i = 5; i < 10; ++i)
+ ((char *)addr)[i * PS] = 1;
+ res = mincore(addr, 10 * PS, vec);
+ assert(res == 0);
+ for (int i = 0; i < 10; ++i)
+ assert((vec[i] & 1) == 1);
+
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/nohugepage_test.cc b/test/asan/TestCases/Linux/nohugepage_test.cc
index aeb70c94ec99..2758f0ad04f5 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: env ASAN_OPTIONS=$ASAN_OPTIONS:no_huge_pages_for_shadow=1 %run %t 2>&1 | FileCheck %s
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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...
diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc
index e9311d16bd5f..bc76116632ec 100644
--- a/test/asan/TestCases/Linux/odr-violation.cc
+++ b/test/asan/TestCases/Linux/odr-violation.cc
@@ -7,20 +7,20 @@
// 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: 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
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=0 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %env_asan_opts=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: 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: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=1 %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %env_asan_opts=fast_unwind_on_malloc=0:detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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: %env_asan_opts=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: %env_asan_opts=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.
diff --git a/test/asan/TestCases/Linux/overflow-in-qsort.cc b/test/asan/TestCases/Linux/overflow-in-qsort.cc
index 26fe67d60729..dc3918e876a6 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: 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
+// RUN: %env_asan_opts=fast_unwind_on_fatal=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-FAST
+// RUN: %env_asan_opts=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/pthread_create_version.cc b/test/asan/TestCases/Linux/pthread_create_version.cc
new file mode 100644
index 000000000000..efdb8ca97c4f
--- /dev/null
+++ b/test/asan/TestCases/Linux/pthread_create_version.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx_asan -std=c++11 -pthread %s -o %t && %run %t 2>&1
+// Regression test for the versioned pthread_create interceptor on linux/i386.
+// pthread_attr_init is not intercepted and binds to the new abi
+// pthread_create is intercepted; dlsym always returns the oldest version.
+// This results in a crash inside pthread_create in libc.
+
+#include <pthread.h>
+#include <stdlib.h>
+
+void *ThreadFunc(void *) { return nullptr; }
+
+int main() {
+ pthread_t t;
+ const size_t sz = 1024 * 1024;
+ void *p = malloc(sz);
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setstack(&attr, p, sz);
+ pthread_create(&t, &attr, ThreadFunc, nullptr);
+ pthread_join(t, nullptr);
+ free(p);
+ return 0;
+}
diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc
index 6840ebe28bfd..d87d90be4753 100644
--- a/test/asan/TestCases/Linux/ptrace.cc
+++ b/test/asan/TestCases/Linux/ptrace.cc
@@ -1,9 +1,9 @@
// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
// XFAIL: android
+// XFAIL: mips
//
// RUN: %clangxx_asan -O0 %s -o %t && %run %t
// RUN: %clangxx_asan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// REQUIRES: x86_64-supported-target,i386-supported-target
#include <assert.h>
#include <stdio.h>
@@ -12,6 +12,55 @@
#include <sys/user.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <sys/uio.h> // for iovec
+#include <elf.h> // for NT_PRSTATUS
+#ifdef __aarch64__
+# include <asm/ptrace.h>
+#endif
+
+#if defined(__i386__) || defined(__x86_64__)
+typedef user_regs_struct regs_struct;
+typedef user_fpregs_struct fpregs_struct;
+#if defined(__i386__)
+#define REG_IP eip
+#else
+#define REG_IP rip
+#endif
+#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.REG_IP))
+#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (unsigned long) (__fpregs.cwd))
+#define __PTRACE_FPREQUEST PTRACE_GETFPREGS
+
+#elif defined(__aarch64__)
+typedef struct user_pt_regs regs_struct;
+typedef struct user_fpsimd_state fpregs_struct;
+#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.pc))
+#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs.fpsr))
+#define ARCH_IOVEC_FOR_GETREGSET
+
+#elif defined(__powerpc64__)
+typedef struct pt_regs regs_struct;
+typedef elf_fpregset_t fpregs_struct;
+#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.nip))
+#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t)fpregs[32])
+#define ARCH_IOVEC_FOR_GETREGSET
+
+#elif defined(__mips__)
+typedef struct pt_regs regs_struct;
+typedef elf_fpregset_t fpregs_struct;
+#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.cp0_epc))
+#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t) (__fpregs[32]))
+#define __PTRACE_FPREQUEST PTRACE_GETFPREGS
+
+#elif defined(__arm__)
+# include <asm/ptrace.h>
+# include <sys/procfs.h>
+typedef struct pt_regs regs_struct;
+typedef char fpregs_struct[ARM_VFPREGS_SIZE];
+#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.ARM_pc))
+#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs + 32 * 8))
+#define __PTRACE_FPREQUEST PTRACE_GETVFPREGS
+#endif
+
int main(void) {
pid_t pid;
@@ -21,28 +70,48 @@ int main(void) {
execl("/bin/true", "true", NULL);
} else {
wait(NULL);
- user_regs_struct regs;
+ regs_struct regs;
+ regs_struct* volatile pregs = &regs;
+#ifdef ARCH_IOVEC_FOR_GETREGSET
+ struct iovec regset_io;
+#endif
int res;
- user_regs_struct * volatile pregs = &regs;
+
#ifdef POSITIVE
++pregs;
#endif
- res = ptrace(PTRACE_GETREGS, pid, NULL, pregs);
+
+#ifdef ARCH_IOVEC_FOR_GETREGSET
+# define __PTRACE_REQUEST PTRACE_GETREGSET
+# define __PTRACE_ARGS (void*)NT_PRSTATUS, (void*)&regset_io
+ regset_io.iov_base = pregs;
+ regset_io.iov_len = sizeof(regs_struct);
+#else
+# define __PTRACE_REQUEST PTRACE_GETREGS
+# define __PTRACE_ARGS NULL, pregs
+#endif
+ res = ptrace((enum __ptrace_request)__PTRACE_REQUEST, pid, __PTRACE_ARGS);
// CHECK: AddressSanitizer: stack-buffer-overflow
// CHECK: {{.*ptrace.cc:}}[[@LINE-2]]
assert(!res);
-#ifdef __x86_64__
- printf("%lx\n", (unsigned long)regs.rip);
+ PRINT_REG_PC(regs);
+
+ fpregs_struct fpregs;
+#ifdef ARCH_IOVEC_FOR_GETREGSET
+# define __PTRACE_FPREQUEST PTRACE_GETREGSET
+# define __PTRACE_FPARGS (void*)NT_PRSTATUS, (void*)&regset_io
+ regset_io.iov_base = &fpregs;
+ regset_io.iov_len = sizeof(fpregs_struct);
+ res = ptrace((enum __ptrace_request)PTRACE_GETREGSET, pid, (void*)NT_FPREGSET,
+ (void*)&regset_io);
#else
- printf("%lx\n", regs.eip);
+# define __PTRACE_FPARGS NULL, &fpregs
#endif
-
- user_fpregs_struct fpregs;
- res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs);
+ res = ptrace((enum __ptrace_request)__PTRACE_FPREQUEST, pid, __PTRACE_FPARGS);
assert(!res);
- printf("%lx\n", (unsigned long)fpregs.cwd);
+ PRINT_REG_FP(fpregs);
-#ifndef __x86_64__
+#ifdef __i386__
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 1820cb90c4ef..cbacec22fa1e 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: 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
+// RUN: %env_asan_opts=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: %env_asan_opts=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: %env_asan_opts=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
+// RUN: %env_asan_opts=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: %env_asan_opts=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
index 0e408d0e366d..b09096c89cb7 100644
--- a/test/asan/TestCases/Linux/read_binary_name_regtest.c
+++ b/test/asan/TestCases/Linux/read_binary_name_regtest.c
@@ -14,6 +14,10 @@
#include <linux/filter.h>
#include <linux/seccomp.h>
+#ifndef __NR_readlink
+# define __NR_readlink __NR_readlinkat
+#endif
+
#define syscall_nr (offsetof(struct seccomp_data, nr))
void corrupt() {
diff --git a/test/asan/TestCases/Linux/sized_delete_test.cc b/test/asan/TestCases/Linux/sized_delete_test.cc
index 1146b8239d8c..5d8c7010e31b 100644
--- a/test/asan/TestCases/Linux/sized_delete_test.cc
+++ b/test/asan/TestCases/Linux/sized_delete_test.cc
@@ -1,10 +1,10 @@
// 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: %env_asan_opts=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
+// RUN: %env_asan_opts=new_delete_type_mismatch=1 not %run %t array 2>&1 | FileCheck %s -check-prefix=ARRAY
+// RUN: %env_asan_opts=new_delete_type_mismatch=0 %run %t scalar
+// RUN: %env_asan_opts=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 23c4d23ce406..8c9599c9f611 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=$ASAN_OPTIONS:use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=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 f207a94ae65e..49c208978010 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: env ASAN_OPTIONS=$ASAN_OPTIONS:exitcode=0 %run %t 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
diff --git a/test/asan/TestCases/Linux/static_tls.cc b/test/asan/TestCases/Linux/static_tls.cc
index 785228b29238..11bb1a4f849c 100644
--- a/test/asan/TestCases/Linux/static_tls.cc
+++ b/test/asan/TestCases/Linux/static_tls.cc
@@ -3,13 +3,13 @@
//
// 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
+// RUN: %env_asan_opts=verbosity=2 %run %t 2>&1 | FileCheck %s
// CHECK: before
// CHECK: __tls_get_addr: static tls
// CHECK: after
-// XFAIL: powerpc64
+// XFAIL: aarch64
#ifndef SHARED
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/stress_dtls.c b/test/asan/TestCases/Linux/stress_dtls.c
index 7af33b9457ea..fd1ce0cd472f 100644
--- a/test/asan/TestCases/Linux/stress_dtls.c
+++ b/test/asan/TestCases/Linux/stress_dtls.c
@@ -1,4 +1,5 @@
// REQUIRES: asan-64-bits
+// UNSUPPORTED: android
// Stress test dynamic TLS + dlopen + threads.
//
// Note that glibc 2.15 seems utterly broken on this test,
@@ -12,9 +13,9 @@
// RUN: %clangxx_asan %s -ldl -pthread -o %t
// RUN: %run %t 0 3
// RUN: %run %t 2 3
-// 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
+// RUN: %env_asan_opts=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
+// RUN: %env_asan_opts=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