diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-14 15:38:48 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-14 15:38:48 +0000 |
commit | 5894cadf20b9970848068ff54fa4e2bfd0a9683b (patch) | |
tree | d2cbfed3f6ec3aaf3c88cfee1f6512e155cc82f8 /test | |
parent | 3bce7d2fca357e6a1db9eff4a1c58545a3020f1b (diff) |
vendor/compiler-rt/compiler-rt-release_40-r292951vendor/compiler-rt/compiler-rt-release_40-r292732vendor/compiler-rt/compiler-rt-release_40-r292009
Notes
Diffstat (limited to 'test')
-rw-r--r-- | test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc | 9 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/start-deactivated.cc | 37 | ||||
-rw-r--r-- | test/asan/lit.cfg | 8 | ||||
-rw-r--r-- | test/profile/Linux/comdat_rename.test | 6 | ||||
-rw-r--r-- | test/profile/lit.cfg | 6 | ||||
-rw-r--r-- | test/tsan/Darwin/ignore-noninstrumented.mm | 53 | ||||
-rw-r--r-- | test/xray/TestCases/Linux/patching-unpatching.cc | 1 |
7 files changed, 101 insertions, 19 deletions
diff --git a/test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc b/test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc index 7176484ed21ce..24022a140c903 100644 --- a/test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc +++ b/test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc @@ -5,8 +5,10 @@ // RUN: FileCheck %s --check-prefix=CHECK-VALUE // RUN: %env_asan_opts=thread_local_quarantine_size_kb=64:quarantine_size_mb=64 %run %t 2>&1 | \ // RUN: FileCheck %s --allow-empty --check-prefix=CHECK-SMALL-LOCAL-CACHE-SMALL-OVERHEAD -// RUN: %env_asan_opts=thread_local_quarantine_size_kb=0:quarantine_size_mb=64 %run %t 2>&1 | \ -// RUN: FileCheck %s --check-prefix=CHECK-NO-LOCAL-CACHE-HUGE-OVERHEAD +// RUN: %env_asan_opts=thread_local_quarantine_size_kb=0:quarantine_size_mb=0 %run %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-QUARANTINE-DISABLED +// RUN: %env_asan_opts=thread_local_quarantine_size_kb=0:quarantine_size_mb=64 not %run %t 2>&1 | \ +// RUN: FileCheck %s --check-prefix=CHECK-FOR-PARAMETER-ERROR #include <stdio.h> #include <stdlib.h> @@ -37,4 +39,5 @@ int main() { // CHECK-VALUE: thread_local_quarantine_size_kb=256K // CHECK-SMALL-LOCAL-CACHE-SMALL-OVERHEAD-NOT: Heap size limit exceeded -// CHECK-NO-LOCAL-CACHE-HUGE-OVERHEAD: Heap size limit exceeded +// CHECK-QUARANTINE-DISABLED-NOT: Heap size limit exceeded +// CHECK-FOR-PARAMETER-ERROR: thread_local_quarantine_size_kb can be set to 0 only when quarantine_size_mb is set to 0 diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc index 9691404ebcea9..b223f04e46a9c 100644 --- a/test/asan/TestCases/Posix/start-deactivated.cc +++ b/test/asan/TestCases/Posix/start-deactivated.cc @@ -21,6 +21,7 @@ // XFAIL: arm-linux-gnueabi #if !defined(SHARED_LIB) + #include <assert.h> #include <dlfcn.h> #include <stdio.h> @@ -32,13 +33,13 @@ #include "sanitizer/asan_interface.h" -constexpr unsigned nPtrs = 200; -char *ptrs[nPtrs]; - void test_malloc_shadow(char *p, size_t sz, bool expect_redzones) { + // Last byte of the left redzone, if present. assert((char *)__asan_region_is_poisoned(p - 1, sz + 1) == (expect_redzones ? p - 1 : nullptr)); + // The user memory. assert((char *)__asan_region_is_poisoned(p, sz) == nullptr); + // First byte of the right redzone, if present. assert((char *)__asan_region_is_poisoned(p, sz + 1) == (expect_redzones ? p + sz : nullptr)); } @@ -46,12 +47,29 @@ void test_malloc_shadow(char *p, size_t sz, bool expect_redzones) { typedef void (*Fn)(); int main(int argc, char *argv[]) { + constexpr unsigned nPtrs = 200; + char *ptrs[nPtrs]; + // Before activation: no redzones. for (size_t sz = 1; sz < nPtrs; ++sz) { ptrs[sz] = (char *)malloc(sz); test_malloc_shadow(ptrs[sz], sz, false); } + // Create a honey pot for the future, instrumented, allocations. Since the + // quarantine is disabled, chunks are going to be recycled right away and + // reused for the new allocations. New allocations must get the proper + // redzones anyway, whether it's a fresh or reused allocation. + constexpr size_t HoneyPotBlockSize = 4096; + constexpr int HoneyPotSize = 200; + char *honeyPot[HoneyPotSize]; + for (int i = 1; i < HoneyPotSize; ++i) { + honeyPot[i] = (char *)malloc(HoneyPotBlockSize); + test_malloc_shadow(honeyPot[i], HoneyPotBlockSize, false); + } + for (int i = 1; i < HoneyPotSize; ++i) + free(honeyPot[i]); + std::string path = std::string(argv[0]) + "-so.so"; void *dso = dlopen(path.c_str(), RTLD_NOW); if (!dso) { @@ -67,11 +85,17 @@ int main(int argc, char *argv[]) { } // After activation: redzones. + for (int i = 1; i < HoneyPotSize; ++i) { + honeyPot[i] = (char *)malloc(HoneyPotBlockSize); + test_malloc_shadow(honeyPot[i], HoneyPotBlockSize, true); + } { - char *p = (char *)malloc(100); - test_malloc_shadow(p, 100, true); + char *p = (char *)malloc(HoneyPotBlockSize); + test_malloc_shadow(p, HoneyPotBlockSize, true); free(p); } + for (int i = 1; i < HoneyPotSize; ++i) + free(honeyPot[i]); // Pre-existing allocations got redzones, too. for (size_t sz = 1; sz < nPtrs; ++sz) { @@ -93,7 +117,9 @@ int main(int argc, char *argv[]) { return 0; } + #else // SHARED_LIB + #include <stdio.h> #include <stdlib.h> @@ -101,6 +127,7 @@ extern "C" void do_another_bad_thing() { char *volatile p = (char *)malloc(100); printf("%hhx\n", p[105]); } + #endif // SHARED_LIB // help=1 in activation flags lists only flags are are supported at activation diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg index 1059f393ab34f..7703f5a31b0dc 100644 --- a/test/asan/lit.cfg +++ b/test/asan/lit.cfg @@ -61,18 +61,18 @@ else: # GCC-ASan doesn't link in all the necessary libraries automatically, so # we have to do it ourselves. if config.compiler_id == 'GNU': - extra_linkflags = ["-pthread", "-lstdc++", libdl_flag] + extra_link_flags = ["-pthread", "-lstdc++", libdl_flag] else: - extra_linkflags = [] + extra_link_flags = [] # BFD linker in 64-bit android toolchains fails to find libm.so, which is a # transitive shared library dependency (via asan runtime). if config.android: - extra_linkflags += ["-lm"] + extra_link_flags += ["-lm"] # Setup default compiler flags used with -fsanitize=address option. # FIXME: Review the set of required flags and check if it can be reduced. -target_cflags = [get_required_attr(config, "target_cflags")] + extra_linkflags +target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags target_cxxflags = config.cxx_mode_flags + target_cflags clang_asan_static_cflags = (["-fsanitize=address", "-mno-omit-leaf-frame-pointer", diff --git a/test/profile/Linux/comdat_rename.test b/test/profile/Linux/comdat_rename.test index cd5c672de4f25..b323352544a83 100644 --- a/test/profile/Linux/comdat_rename.test +++ b/test/profile/Linux/comdat_rename.test @@ -1,6 +1,6 @@ // RUN: rm -fr %t.prof -// RUN: %clangxx_pgogen=%t.prof/ -o %t.gen -O2 %S/../Inputs/comdat_rename_1.cc %S/../Inputs/comdat_rename_2.cc +// RUN: %clangxx_pgogen=%t.prof/ -o %t.gen -mllvm -do-comdat-renaming=true -O2 %S/../Inputs/comdat_rename_1.cc %S/../Inputs/comdat_rename_2.cc // RUN: %run %t.gen // RUN: llvm-profdata merge -o %t.profdata %t.prof/ -// RUN: %clangxx_profuse=%t.profdata -O2 -emit-llvm -S %S/../Inputs/comdat_rename_1.cc -o - | FileCheck %S/../Inputs/comdat_rename_1.cc -// RUN: %clangxx_profuse=%t.profdata -O2 -emit-llvm -S %S/../Inputs/comdat_rename_2.cc -o - | FileCheck %S/../Inputs/comdat_rename_2.cc +// RUN: %clangxx_profuse=%t.profdata -O2 -mllvm -do-comdat-renaming=true -emit-llvm -S %S/../Inputs/comdat_rename_1.cc -o - | FileCheck %S/../Inputs/comdat_rename_1.cc +// RUN: %clangxx_profuse=%t.profdata -O2 -mllvm -do-comdat-renaming=true -emit-llvm -S %S/../Inputs/comdat_rename_2.cc -o - | FileCheck %S/../Inputs/comdat_rename_2.cc diff --git a/test/profile/lit.cfg b/test/profile/lit.cfg index a6e6ef81c6228..9ca394212e9f4 100644 --- a/test/profile/lit.cfg +++ b/test/profile/lit.cfg @@ -34,9 +34,9 @@ if config.test_exec_root is None: raise SystemExit if config.host_os in ['Linux']: - extra_linkflags = ["-ldl"] + extra_link_flags = ["-ldl"] else: - extra_linkflags = [] + extra_link_flags = [] # Test suffixes. config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm', '.ll', '.test'] @@ -46,7 +46,7 @@ config.excludes = ['Inputs'] # Clang flags. target_cflags=[get_required_attr(config, "target_cflags")] -clang_cflags = target_cflags + extra_linkflags +clang_cflags = target_cflags + extra_link_flags clang_cxxflags = config.cxx_mode_flags + clang_cflags def build_invocation(compile_flags, with_lto = False): diff --git a/test/tsan/Darwin/ignore-noninstrumented.mm b/test/tsan/Darwin/ignore-noninstrumented.mm new file mode 100644 index 0000000000000..5e4453102a9c6 --- /dev/null +++ b/test/tsan/Darwin/ignore-noninstrumented.mm @@ -0,0 +1,53 @@ +// Check that ignore_noninstrumented_modules=1 supresses races from system libraries on OS X. + +// RUN: %clang_tsan %s -o %t -framework Foundation + +// Check that without the flag, there are false positives. +// RUN: %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE + +// With ignore_noninstrumented_modules=1, no races are reported. +// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s + +// With ignore_noninstrumented_modules=1, races in user's code are still reported. +// RUN: %env_tsan_opts=ignore_noninstrumented_modules=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE + +#import <Foundation/Foundation.h> + +#import "../test.h" + +char global_buf[64]; + +void *Thread1(void *x) { + barrier_wait(&barrier); + strcpy(global_buf, "hello world"); + return NULL; +} + +void *Thread2(void *x) { + strcpy(global_buf, "world hello"); + barrier_wait(&barrier); + return NULL; +} + +int main(int argc, char *argv[]) { + fprintf(stderr, "Hello world.\n"); + + // NSUserDefaults uses XPC which triggers the false positive. + NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; + fprintf(stderr, "d = %p\n", d); + + if (argc > 1 && strcmp(argv[1], "race") == 0) { + barrier_init(&barrier, 2); + pthread_t t[2]; + pthread_create(&t[0], NULL, Thread1, NULL); + pthread_create(&t[1], NULL, Thread2, NULL); + pthread_join(t[0], NULL); + pthread_join(t[1], NULL); + } + + fprintf(stderr, "Done.\n"); +} + +// CHECK: Hello world. +// CHECK-RACE: SUMMARY: ThreadSanitizer: data race +// CHECK: Done. diff --git a/test/xray/TestCases/Linux/patching-unpatching.cc b/test/xray/TestCases/Linux/patching-unpatching.cc index e684e427f068f..05478a4880562 100644 --- a/test/xray/TestCases/Linux/patching-unpatching.cc +++ b/test/xray/TestCases/Linux/patching-unpatching.cc @@ -3,7 +3,6 @@ // // RUN: %clangxx_xray -fxray-instrument -std=c++11 %s -o %t // RUN: XRAY_OPTIONS="patch_premain=false" %run %t 2>&1 | FileCheck %s -// REQUIRES: stable-runtime #include "xray/xray_interface.h" |