diff options
Diffstat (limited to 'test/sanitizer_common')
15 files changed, 185 insertions, 7 deletions
diff --git a/test/sanitizer_common/TestCases/Linux/deepbind.cc b/test/sanitizer_common/TestCases/Linux/deepbind.cc new file mode 100644 index 000000000000..fc810ad039f4 --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/deepbind.cc @@ -0,0 +1,12 @@ +// RUN: %clangxx %s -o %t && %run not %t 1 2>&1 | FileCheck %s +// UNSUPPORTED: lsan, android + +#include <dlfcn.h> +#include <stdio.h> +#include <string> + +int main (int argc, char *argv[]) { + // CHECK: You are trying to dlopen a <arbitrary path> shared library with RTLD_DEEPBIND flag + void *lib = dlopen("<arbitrary path>", RTLD_NOW | RTLD_DEEPBIND); + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/iconv_test.c b/test/sanitizer_common/TestCases/Linux/iconv_test.c new file mode 100644 index 000000000000..08da34d89a3c --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/iconv_test.c @@ -0,0 +1,28 @@ +// RUN: %clang %s -o %t && %run %t +// Verify that even if iconv returned -1 +// we still treat the initialized part of outbuf as properly initialized. +#include <iconv.h> +#include <assert.h> +#include <stdio.h> + +int main() { + iconv_t cd = iconv_open("UTF-8", "no"); + assert(cd != (iconv_t)-1); + char in[11] = {0x7e, 0x7e, 0x5f, 0x53, 0x55, 0x3e, + 0x99, 0x3c, 0x7e, 0x7e, 0x7e}; + fprintf(stderr, "cd: %p\n", (void*)cd); + char out[100]; + char *inbuf = &in[0]; + size_t inbytesleft = 11; + char *outbuf = &out[0]; + size_t outbytesleft = 100; + int ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + assert(ret == -1); + assert(outbuf - &out[0] == 10); + for (int i = 0; i < 10; i++) { + if (out[i] == 0x77) return 1; + fprintf(stderr, "OUT%d 0x%x -- OK\n", i, (unsigned char)out[i]); + } + iconv_close(cd); +} + diff --git a/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc b/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc index ff1ddc432d4e..92557b7592cb 100644 --- a/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc +++ b/test/sanitizer_common/TestCases/Linux/sem_init_glibc.cc @@ -1,7 +1,7 @@ // RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t // This test depends on the glibc layout of struct sem_t and checks that we // don't leave sem_t::private uninitialized. -// UNSUPPORTED: android +// UNSUPPORTED: android, lsan-x86 #include <features.h> #include <assert.h> #include <semaphore.h> diff --git a/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc b/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc new file mode 100644 index 000000000000..eb4deace060c --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/sysconf_interceptor_bypass_test.cc @@ -0,0 +1,25 @@ +// RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s + +#include <stdio.h> + +// getauxval() used instead of sysconf() in GetPageSize() is defined starting +// glbc version 2.16. +#if defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 16) +extern "C" long sysconf(int name) { + fprintf(stderr, "sysconf wrapper called\n"); + return 0; +} +#endif // defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 16) + +int main() { + // All we need to check is that the sysconf() interceptor defined above was + // not called. Should it get called, it will crash right there, any + // instrumented code executed before sanitizer init is finished will crash + // accessing non-initialized sanitizer internals. Even if it will not crash + // in some configuration, it should never be called anyway. + fprintf(stderr, "Passed\n"); + // CHECK-NOT: sysconf wrapper called + // CHECK: Passed + // CHECK-NOT: sysconf wrapper called + return 0; +} diff --git a/test/sanitizer_common/TestCases/Linux/fpe.cc b/test/sanitizer_common/TestCases/Posix/fpe.cc index 9a6f808a5cd7..9a6f808a5cd7 100644 --- a/test/sanitizer_common/TestCases/Linux/fpe.cc +++ b/test/sanitizer_common/TestCases/Posix/fpe.cc diff --git a/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc index fdb68c0cdea5..12a56c73e049 100644 --- a/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc +++ b/test/sanitizer_common/TestCases/Posix/sanitizer_set_death_callback_test.cc @@ -2,6 +2,13 @@ // REQUIRES: stable-runtime +// For standalone LSan on x86 we have a problem: compiler spills the address +// of allocated at line 42 memory thus memory block allocated in Leak() function +// ends up to be classified as reachable despite the fact we zero out 'sink' at +// the last line of main function. The problem doesn't reproduce with ASan because +// quarantine prohibits memory block reuse for different allocations. +// XFAIL: lsan-x86 + #include <sanitizer/common_interface_defs.h> #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc index d5667649bb9c..d5667649bb9c 100644 --- a/test/sanitizer_common/TestCases/Linux/weak_hook_test.cc +++ b/test/sanitizer_common/TestCases/Posix/weak_hook_test.cc diff --git a/test/sanitizer_common/TestCases/corelimit.cc b/test/sanitizer_common/TestCases/corelimit.cc index 8f54940d04cc..0a86e5b7b7fe 100644 --- a/test/sanitizer_common/TestCases/corelimit.cc +++ b/test/sanitizer_common/TestCases/corelimit.cc @@ -1,5 +1,5 @@ // RUN: %clangxx -O0 %s -o %t && %run %t -// XFAIL: lsan +// UNSUPPORTED: lsan #include <assert.h> #include <sys/time.h> diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc index cf16ec383312..68459b19a159 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cc @@ -1,7 +1,7 @@ // Tests trace pc guard coverage collection. // // REQUIRES: has_sancovcc,stable-runtime -// XFAIL: tsan,darwin,powerpc64,s390x +// XFAIL: tsan,darwin,powerpc64,s390x,mips // // RUN: DIR=%t_workdir // RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard" diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-init.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-init.cc new file mode 100644 index 000000000000..b92a513b6d65 --- /dev/null +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-init.cc @@ -0,0 +1,73 @@ +// Tests trace pc guard coverage collection. +// +// REQUIRES: has_sancovcc,stable-runtime,x86_64-linux +// XFAIL: tsan +// +// RUN: DIR=%t_workdir +// RUN: CLANG_ARGS="-O0 -fsanitize-coverage=trace-pc-guard" +// RUN: rm -rf $DIR +// RUN: mkdir -p $DIR +// RUN: cd $DIR +// RUN: %clangxx -DSHARED1 $CLANG_ARGS -shared %s -o %t_1.so -fPIC +// RUN: %clangxx -DSTATIC1 $CLANG_ARGS %s -c -o %t_2.o +// RUN: %clangxx -DMAIN $CLANG_ARGS %s -o %t %t_1.so %t_2.o +// RUN: %env_tool_opts=coverage=1 %t 2>&1 | FileCheck %s +// RUN: rm -rf $DIR + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> + +extern "C" { + int bar(); + int baz(); +} + +#ifdef MAIN + +extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) { + fprintf(stderr, "__sanitizer_cov_trace_pc_guard_init\n"); +} + +extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t *guard) { } + + +int foo() { + fprintf(stderr, "foo\n"); + return 1; +} + +int main() { + fprintf(stderr, "main\n"); + foo(); + bar(); + baz(); +} + +#endif // MAIN + +extern "C" { + +#ifdef SHARED1 +int bar() { + fprintf(stderr, "bar\n"); + return 1; +} +#endif + +#ifdef STATIC1 +int baz() { + fprintf(stderr, "baz\n"); + return 1; +} +#endif + +} // extern "C" + +// Init is called once per DSO. +// CHECK: __sanitizer_cov_trace_pc_guard_init +// CHECK-NEXT: __sanitizer_cov_trace_pc_guard_init +// CHECK-NEXT: main +// CHECK-NEXT: foo +// CHECK-NEXT: bar +// CHECK-NEXT: baz diff --git a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc index 1b787f143d46..9dcbe6fa0387 100644 --- a/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc +++ b/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cc @@ -1,7 +1,8 @@ // Tests trace pc guard coverage collection. // // REQUIRES: has_sancovcc,stable-runtime -// XFAIL: tsan,darwin,powerpc64,s390x +// UNSUPPORTED: i386-darwin +// XFAIL: tsan,powerpc64,s390x,mips // // RUN: DIR=%t_workdir // RUN: rm -rf $DIR @@ -35,7 +36,7 @@ int main() { // CHECK-NEXT: foo // CHECK-NEXT: SanitizerCoverage: ./sanitizer_coverage_trace_pc_guard.{{.*}}.sancov 2 PCs written // -// CHECK-SANCOV: sanitizer_coverage_trace_pc_guard.cc:22 foo -// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard.cc:27 main +// CHECK-SANCOV: sanitizer_coverage_trace_pc_guard.cc:23 foo +// CHECK-SANCOV-NEXT: sanitizer_coverage_trace_pc_guard.cc:28 main // // CHECK-NOCOV-NOT: SanitizerCoverage diff --git a/test/sanitizer_common/TestCases/symbolize_pc.cc b/test/sanitizer_common/TestCases/symbolize_pc.cc index 0cc81e1f7dcf..68a6733f4464 100644 --- a/test/sanitizer_common/TestCases/symbolize_pc.cc +++ b/test/sanitizer_common/TestCases/symbolize_pc.cc @@ -1,6 +1,5 @@ // RUN: %clangxx -O0 %s -o %t // RUN: %env_tool_opts=strip_path_prefix=/TestCases/ %run %t 2>&1 | FileCheck %s -// UNSUPPORTED: i386-darwin // // Tests __sanitizer_symbolize_pc. #include <stdio.h> diff --git a/test/sanitizer_common/TestCases/symbolize_stack.cc b/test/sanitizer_common/TestCases/symbolize_stack.cc new file mode 100644 index 000000000000..e50cdb0632b3 --- /dev/null +++ b/test/sanitizer_common/TestCases/symbolize_stack.cc @@ -0,0 +1,28 @@ +// RUN: %clangxx -O0 %s -o %t && %run %t 2>&1 | FileCheck %s + +// Test that symbolizer does not crash on frame with large function name. + +#include <sanitizer/common_interface_defs.h> +#include <vector> + +template <int N> struct A { + template <class T> void RecursiveTemplateFunction(const T &t); +}; + +template <int N> +template <class T> +__attribute__((noinline)) void A<N>::RecursiveTemplateFunction(const T &) { + std::vector<T> t; + return A<N - 1>().RecursiveTemplateFunction(t); +} + +template <> +template <class T> +__attribute__((noinline)) void A<0>::RecursiveTemplateFunction(const T &) { + __sanitizer_print_stack_trace(); +} + +int main() { + // CHECK: {{vector<.*vector<.*vector<.*vector<.*vector<}} + A<10>().RecursiveTemplateFunction(0); +} diff --git a/test/sanitizer_common/lit.common.cfg b/test/sanitizer_common/lit.common.cfg index b32fb1ba9685..2926edb127aa 100644 --- a/test/sanitizer_common/lit.common.cfg +++ b/test/sanitizer_common/lit.common.cfg @@ -26,6 +26,9 @@ config.available_features.add(config.tool_name) if config.target_arch not in ['arm', 'armhf', 'aarch64']: config.available_features.add('stable-runtime') +if config.host_os == 'Linux' and config.target_arch == 'i386' and config.tool_name == "lsan": + config.available_features.add("lsan-x86") + if config.host_os == 'Darwin': # On Darwin, we default to `abort_on_error=1`, which would make tests run # much slower. Let's override this and run lit tests with 'abort_on_error=0'. diff --git a/test/sanitizer_common/print_address.h b/test/sanitizer_common/print_address.h index 018db61800d3..db2e8341a9d2 100644 --- a/test/sanitizer_common/print_address.h +++ b/test/sanitizer_common/print_address.h @@ -11,6 +11,8 @@ void print_address(const char *str, int n, ...) { // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not // match to the format used in the diagnotic message. fprintf(stderr, "0x%012lx ", (unsigned long) p); +#elif defined(__i386__) || defined(__arm__) + fprintf(stderr, "0x%08lx ", (unsigned long) p); #elif defined(__mips64) fprintf(stderr, "0x%010lx ", (unsigned long) p); #endif |