Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -1,3 +1,7 @@ +if(${COMPILER_RT_CROSS_COMPILING_NOANDROID}) +SET(ANDROID "0" CACHE STRING "ANDROID" FORCE) +endif() + # CMake build for CompilerRT. # # This build assumes that CompilerRT is checked out into the Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -174,7 +174,15 @@ detect_target_arch() set(COMPILER_RT_OS_SUFFIX "-android") elseif(NOT APPLE) # Supported archs for Apple platforms are generated later - if("${LLVM_NATIVE_ARCH}" STREQUAL "X86") + # See If the user wants cross compiling, e.g. using clang for something + # other than android. + # This is useful if we want to use CMAKE_C_FLAGS and CMAKE_C_COMPILER to + # pass in cross compilation args, i.e. we are using a single version of clang + # that has a default target other than the host to generate compiler-rt for the + # host (or some other platform) + if(${COMPILER_RT_CROSS_COMPILING}) + detect_target_arch() + elseif("${LLVM_NATIVE_ARCH}" STREQUAL "X86") if(NOT MSVC) test_target_arch(x86_64 "" "-m64") # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may @@ -260,7 +268,11 @@ set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} mips64 mips64el) set(ALL_PROFILE_SUPPORTED_ARCH ${X86_64} i386 i686 ${ARM32} mips mips64 mipsel mips64el ${ARM64} powerpc64 powerpc64le) +if(${COMPILER_RT_FORCE_TSAN_AARCH64}) +set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} mips64 mips64el ${ARM64}) +else() set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} mips64 mips64el) +endif() set(ALL_UBSAN_SUPPORTED_ARCH ${X86_64} i386 i686 ${ARM32} ${ARM64} mips mipsel mips64 mips64el powerpc64 powerpc64le) set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86_64} i386 i686) @@ -492,7 +504,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Linux|FreeBSD") + OS_NAME MATCHES "Linux|FreeBSD|Android") set(COMPILER_RT_HAS_TSAN TRUE) else() set(COMPILER_RT_HAS_TSAN FALSE) Index: lib/interception/interception_linux.cc =================================================================== --- lib/interception/interception_linux.cc +++ lib/interception/interception_linux.cc @@ -19,8 +19,14 @@ namespace __interception { bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, - uptr real, uptr wrapper) { + uptr real, uptr wrapper) { *func_addr = (uptr)dlsym(RTLD_NEXT, func_name); +#if defined(__aarch64__) && defined(__ANDROID__) + // At least one functions, such as android's dl_iterate_phdr + // need RTLD_DEFAULT to be found properly + if (!(*func_addr)) + *func_addr = (uptr)dlsym(RTLD_DEFAULT, func_name); +#endif return real == wrapper; } Index: lib/sanitizer_common/sanitizer_libc.cc =================================================================== --- lib/sanitizer_common/sanitizer_libc.cc +++ lib/sanitizer_common/sanitizer_libc.cc @@ -71,6 +71,19 @@ return dest; } +void *internal_malloc(uptr n) { + return InternalAlloc(n); +} + +void *internal_calloc(uptr n, uptr s) { + void *rtn = InternalAlloc(n * s); + if (rtn) { + internal_memset(rtn, 0, n * s); + } + return (void*)0; +} + + // Semi-fast bzero for 16-aligned data. Still far from peak performance. void internal_bzero_aligned16(void *s, uptr n) { struct S16 { u64 a, b; } ALIGNED(16); Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -327,7 +327,8 @@ #if !SANITIZER_GO static void GetTls(uptr *addr, uptr *size) { #if SANITIZER_LINUX -# if defined(__x86_64__) || defined(__i386__) || defined(__aarch64__) +# if defined(__x86_64__) || defined(__i386__) || \ + (defined(__aarch64__) && !defined(__ANDROID__)) *addr = ThreadSelf(); *size = GetTlsSize(); *addr -= *size; Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -160,12 +160,12 @@ #define SANITIZER_INTERCEPT_POLL SI_NOT_WINDOWS #define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WORDEXP \ - SI_FREEBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID + (SI_FREEBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_SIGWAIT SI_NOT_WINDOWS #define SANITIZER_INTERCEPT_SIGWAITINFO SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_SIGTIMEDWAIT SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_SIGSETOPS \ - SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID + (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || __aarch64__) #define SANITIZER_INTERCEPT_SIGPENDING SI_NOT_WINDOWS #define SANITIZER_INTERCEPT_SIGPROCMASK SI_NOT_WINDOWS #define SANITIZER_INTERCEPT_BACKTRACE SI_FREEBSD || SI_LINUX_NOT_ANDROID Index: lib/sanitizer_common/sanitizer_platform_limits_posix.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -321,7 +321,8 @@ long pw_change; char *pw_class; #endif -#if !(SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32)) + +#if !(SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32) && !__aarch64__) char *pw_gecos; #endif char *pw_dir; @@ -398,6 +399,23 @@ int cmsg_level; int cmsg_type; }; +#elif SANITIZER_ANDROID +struct __sanitizer_msghdr { + void* msg_name; + unsigned msg_namelen; + struct __sanitizer_iovec* msg_iov; + unsigned long msg_iovlen; + void* msg_control; + unsigned long msg_controllen; + int msg_flags; +}; + +struct __sanitizer_cmsghdr { + unsigned long cmsg_len; + int cmsg_level; + int cmsg_type; +}; + #else struct __sanitizer_msghdr { void *msg_name; @@ -715,6 +733,50 @@ int _fileno; }; # define SANITIZER_HAS_STRUCT_FILE 1 +#elif SANITIZER_ANDROID + struct __sanitizer__sbuf { + unsigned char* _base; + uptr _size; + }; + + struct __sanitizer_FILE { + unsigned char *_p; /* current position in (some) buffer */ + int _r; /* read space left for getc() */ + int _w; /* write space left for putc() */ +#if defined(__LP64__) + int _flags; /* flags, below; this FILE is free if 0 */ + int _file; /* fileno, if Unix descriptor, else -1 */ +#else + short _flags; /* flags, below; this FILE is free if 0 */ + short _file; /* fileno, if Unix descriptor, else -1 */ +#endif + /* the buffer (at least 1 byte, if !NULL) */ + struct __sanitizer__sbuf _bf; + int _lbfsize; /* 0 or -_bf._size, for inline putc */ + + /* operations */ + void *_cookie; /* cookie passed to io functions */ + int (*_close)(void *a); + int (*_read)(void *a , char *b, int c); + uptr (*_seek)(void *a, uptr b, int c); + int (*_write)(void *a, const char *b, int c); + + /* extension data, to avoid further ABI breakage */ + struct __sanitizer__sbuf _ext; + /* data for long sequences of ungetc() */ + unsigned char *_up; /* saved _p when _p is doing ungetc data */ + int _ur; /* saved _r when _r is counting ungetc data */ + + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ + unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + + struct __sanitizer__sbuf _lb; /* buffer for fgetln() */ + + /* Unix stdio files get aligned to block boundaries on fseek() */ + int _blksize; /* stat.st_blksize (may be != _bf._size) */ + uptr _offset; /* current lseek offset */ + }; +# define SANITIZER_HAS_STRUCT_FILE 0 #else typedef void __sanitizer_FILE; # define SANITIZER_HAS_STRUCT_FILE 0 Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -171,6 +171,7 @@ #include #include #include +#include #endif #if SANITIZER_LINUX @@ -1155,7 +1156,7 @@ CHECK_SIZE_AND_OFFSET(passwd, pw_dir); CHECK_SIZE_AND_OFFSET(passwd, pw_shell); -#if !SANITIZER_ANDROID +#if !SANITIZER_ANDROID || (SANITIZER_ANDROID && __aarch64__) CHECK_SIZE_AND_OFFSET(passwd, pw_gecos); #endif Index: lib/tsan/CMakeLists.txt =================================================================== --- lib/tsan/CMakeLists.txt +++ lib/tsan/CMakeLists.txt @@ -17,6 +17,7 @@ # FIXME: Add support for --sysroot=. compile flag: set(TSAN_SOURCES + rtl/tsan_aarch64_tls_workaround.cc rtl/tsan_clock.cc rtl/tsan_flags.cc rtl/tsan_fd.cc @@ -53,6 +54,7 @@ endif() set(TSAN_HEADERS + rtl/tsan_aarch64_tls_workaround.h rtl/tsan_clock.h rtl/tsan_defs.h rtl/tsan_dense_alloc.h Index: lib/tsan/rtl/tsan.syms.extra =================================================================== --- lib/tsan/rtl/tsan.syms.extra +++ lib/tsan/rtl/tsan.syms.extra @@ -9,6 +9,7 @@ __tsan_release __tsan_acquire __ubsan_* +InitTSanWorkAround Annotate* WTFAnnotate* RunningOnValgrind Index: lib/tsan/rtl/tsan_aarch64_tls_workaround.h =================================================================== --- /dev/null +++ lib/tsan/rtl/tsan_aarch64_tls_workaround.h @@ -0,0 +1,42 @@ +//===-- tsan_android_aarch64_tls_workaround.h -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of ThreadSanitizer (TSan), a race detector. +// +// This file presents some macros +//===----------------------------------------------------------------------===// + +#ifndef TSAN_AARCH64_TLS_WORKAROUND_H +#define TSAN_AARCH64_TLS_WORKAROUND_H + +// This file implements a few macros +// For OSs that properly implement __thread, this will devolve to a no-op. +// For others (notably Android on AArch64), we get around the lack of support +// via using pthread calls internally to implement it. +#include "sanitizer_common/sanitizer_platform.h" + +#if defined(__aarch64__) && SANITIZER_ANDROID +#define SANITIZER_TLS_WORKAROUND_NEEDED 1 +#define GetFromTLS(tlsvar) get_from_tls_##tlsvar() + +namespace __tsan { +extern "C" bool InitTLSWorkAround(); +}; + +// Due to chicken-vs-egg decl issues, these are the real accessor functions. +// char &get_from_tls_cur_thread_placeholder() (used in tsan_rtl.cc) +// __sanitizer_sigset_t &get_from_tls_emptset() (used in tsan_interceptors.cc) +// __sanitizer_sigset_t &get_from_tls_oldset(); + +#else +#define GetFromTLS(tlsvar) tlsvar +#define SANITIZER_TLS_WORKAROUND_NEEDED 0 +#endif // defined(__aarch64__) && SANITIZER_ANDROID + +#endif Index: lib/tsan/rtl/tsan_aarch64_tls_workaround.cc =================================================================== --- /dev/null +++ lib/tsan/rtl/tsan_aarch64_tls_workaround.cc @@ -0,0 +1,60 @@ +#include + +#include "sanitizer_common/sanitizer_atomic.h" +#include "sanitizer_common/sanitizer_libc.h" +#include "sanitizer_common/sanitizer_linux.h" +#include "sanitizer_common/sanitizer_platform_limits_posix.h" +#include "sanitizer_common/sanitizer_placement_new.h" +#include "sanitizer_common/sanitizer_stacktrace.h" +#include "interception/interception.h" + +#include "tsan_interface.h" +#include "tsan_platform.h" +#include "tsan_rtl.h" +#include "interception/interception.h" +#include + +#if SANITIZER_TLS_WORKAROUND_NEEDED + +namespace __tsan { + +// This needs to be aligned(64) +struct TSanTLSHack { + uptr tid; + char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64); + __sanitizer_sigset_t emptyset, oldset; +}; + +static const int kPrimeNumber = 2053; +static TSanTLSHack* TLSHack[kPrimeNumber]; + +extern +TSanTLSHack *GetTSanTLSHack() { + uptr tid = GetThreadSelf(); + uptr hash = tid % kPrimeNumber; + + if (TLSHack[hash] == 0ll) { + TLSHack[hash] = (TSanTLSHack*)InternalAlloc(sizeof(TSanTLSHack)); + TLSHack[hash]->tid = tid; + DPrintf("Thread %p at slot %p getting ThreadState %p\n", + tid, hash, &(TLSHack[hash]->cur_thread_placeholder[0])); + return TLSHack[hash]; + } + CHECK_EQ(TLSHack[hash]->tid, tid); + return TLSHack[hash]; +} + +char &get_from_tls_cur_thread_placeholder() { + return GetTSanTLSHack()->cur_thread_placeholder[0]; +}; + +__sanitizer_sigset_t &get_from_tls_emptyset() { + return GetTSanTLSHack()->emptyset; +}; + +__sanitizer_sigset_t &get_from_tls_oldset() { + return GetTSanTLSHack()->oldset; +}; + +} // namespace __tsan +#endif // SANITIZER_TLS_WORKAROUND_NEEDED Index: lib/tsan/rtl/tsan_interceptors.h =================================================================== --- lib/tsan/rtl/tsan_interceptors.h +++ lib/tsan/rtl/tsan_interceptors.h @@ -18,12 +18,23 @@ } // namespace __tsan +#if SANITIZER_TLS_WORKAROUND_NEEDED #define SCOPED_INTERCEPTOR_RAW(func, ...) \ ThreadState *thr = cur_thread(); \ const uptr caller_pc = GET_CALLER_PC(); \ + DPrintf("#%d: intercept " #func " %s:%d:%s\n", \ + thr->tid, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ ScopedInterceptor si(thr, #func, caller_pc); \ const uptr pc = StackTrace::GetCurrentPc(); \ - (void)pc; \ + (void)pc; +#else +#define SCOPED_INTERCEPTOR_RAW(func, ...) \ + ThreadState *thr = cur_thread(); \ + const uptr caller_pc = GET_CALLER_PC(); \ + ScopedInterceptor si(thr, #func, caller_pc); \ + const uptr pc = StackTrace::GetCurrentPc(); \ + (void)pc; +#endif // SANITIZER_TLS_WORKAROUND_NEEDED /**/ #if SANITIZER_FREEBSD Index: lib/tsan/rtl/tsan_interceptors.cc =================================================================== --- lib/tsan/rtl/tsan_interceptors.cc +++ lib/tsan/rtl/tsan_interceptors.cc @@ -20,6 +20,10 @@ #include "sanitizer_common/sanitizer_placement_new.h" #include "sanitizer_common/sanitizer_stacktrace.h" #include "interception/interception.h" + +// this needs to be pulled in first +#include "tsan_aarch64_tls_workaround.h" + #include "tsan_interceptors.h" #include "tsan_interface.h" #include "tsan_platform.h" @@ -28,6 +32,14 @@ #include "tsan_mman.h" #include "tsan_fd.h" +#if SANITIZER_TLS_WORKAROUND_NEEDED +u64 GLOBAL_interceptor_count = 0; + +__attribute__((section(".preinit_array"), used)) +void (*__local_tsan_preinitc)(void) = __tsan_init; +#endif // SANITIZER_TLS_WORKAROUND_NEEDED + + using namespace __tsan; // NOLINT #if SANITIZER_FREEBSD @@ -45,6 +57,11 @@ #endif +#if SANITIZER_ANDROID +#define __errno_location __errno +#define fileno_unlocked fileno +#endif + #ifdef __mips__ const int kSigCount = 129; #else @@ -80,7 +97,9 @@ extern "C" int pthread_key_create(unsigned *key, void (*destructor)(void* v)); extern "C" int pthread_setspecific(unsigned key, const void *v); DECLARE_REAL(int, pthread_mutexattr_gettype, void *, void *) +#if !SANITIZER_ANDROID extern "C" int pthread_yield(); +#endif extern "C" int pthread_sigmask(int how, const __sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset); // REAL(sigfillset) defined in common interceptors. @@ -88,15 +107,42 @@ DECLARE_REAL(int, fflush, __sanitizer_FILE *fp) extern "C" void *pthread_self(); extern "C" void _exit(int status); + extern "C" int *__errno_location(); extern "C" int fileno_unlocked(void *stream); + +#if SANITIZER_ANDROID && __aarch64__ +// bionic does not have __libc_(malloc/realloc/calloc/free) +DECLARE_REAL(void *, malloc, uptr); +DECLARE_REAL(void *, calloc, uptr, uptr); +DECLARE_REAL(void *, realloc, void *, uptr); +DECLARE_REAL(void, free, void *); + +#define __libc_malloc REAL(malloc) +#define __libc_realloc REAL(realloc) +#define __libc_calloc REAL(calloc) +#define __libc_free REAL(free) +#else +extern "C" void *__libc_malloc(uptr size); +extern "C" void __libc_free(void *ptr); extern "C" void *__libc_calloc(uptr size, uptr n); extern "C" void *__libc_realloc(void *ptr, uptr size); +#endif + extern "C" int dirfd(void *dirp); #if !SANITIZER_FREEBSD extern "C" int mallopt(int param, int value); #endif + +#if SANITIZER_ANDROID +extern __sanitizer_FILE __sF[]; +#define stdout (&__sF[1]) +#define stderr (&__sF[2]) +#else extern __sanitizer_FILE *stdout, *stderr; +#endif // SANITIZER_ANDROID + + const int PTHREAD_MUTEX_RECURSIVE = 1; const int PTHREAD_MUTEX_RECURSIVE_NP = 1; const int EINVAL = 22; @@ -127,7 +173,7 @@ # define F_TLOCK 2 /* Test and lock a region for exclusive use. */ # define F_TEST 3 /* Test a region for other processes locks. */ -#define errno (*__errno_location()) +#define get_errno_lval (*__errno_location()) typedef void (*sighandler_t)(int sig); typedef void (*sigactionhandler_t)(int sig, my_siginfo_t *siginfo, void *uctx); @@ -538,7 +584,11 @@ TSAN_INTERCEPTOR(void*, calloc, uptr size, uptr n) { if (cur_thread()->in_symbolizer) +#if SANITIZER_ANDROID + return REAL(calloc)(size, n); +#else return __libc_calloc(size, n); +#endif void *p = 0; { SCOPED_INTERCEPTOR_RAW(calloc, size, n); @@ -550,7 +600,12 @@ TSAN_INTERCEPTOR(void*, realloc, void *p, uptr size) { if (cur_thread()->in_symbolizer) +#if SANITIZER_ANDROID + return REAL(realloc)(p, size); +#else return __libc_realloc(p, size); +#endif + if (p) invoke_free_hook(p); { @@ -668,7 +723,7 @@ if (*addr) { if (!IsAppMem((uptr)*addr) || !IsAppMem((uptr)*addr + sz - 1)) { if (flags & MAP_FIXED) { - errno = EINVAL; + get_errno_lval = EINVAL; return false; } else { *addr = 0; @@ -831,7 +886,7 @@ } ThreadIgnoreEnd(thr, 0); while ((tid = atomic_load(&p->tid, memory_order_acquire)) == 0) - pthread_yield(); + internal_sched_yield(); ThreadStart(thr, tid, GetTid()); atomic_store(&p->tid, 0, memory_order_release); } @@ -891,7 +946,7 @@ // before the new thread got a chance to acquire from it in ThreadStart. atomic_store(&p.tid, tid, memory_order_release); while (atomic_load(&p.tid, memory_order_acquire) != 0) - pthread_yield(); + internal_sched_yield(); } if (attr == &myattr) pthread_attr_destroy(&myattr); @@ -1265,7 +1320,7 @@ atomic_store(a, 2, memory_order_release); } else { while (v != 2) { - pthread_yield(); + internal_sched_yield(); v = atomic_load(a, memory_order_acquire); } if (!thr->in_ignored_lib) @@ -1419,7 +1474,7 @@ #define TSAN_MAYBE_INTERCEPT_LSTAT64 #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) { SCOPED_TSAN_INTERCEPTOR(__fxstat, version, fd, buf); if (fd > 0) @@ -1432,7 +1487,9 @@ #endif TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) { -#if SANITIZER_FREEBSD +// SANITIZER_TLS_WORKAROUND_NEEDED is for ANDROID&&__aarch64__ +// ANDROID does not have fxstat and friends +#if SANITIZER_FREEBSD||SANITIZER_TLS_WORKAROUND_NEEDED SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf); if (fd > 0) FdAccess(thr, pc, fd); @@ -1445,7 +1502,7 @@ #endif } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_TLS_WORKAROUND_NEEDED TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) { SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf); if (fd > 0) @@ -1457,7 +1514,7 @@ #define TSAN_MAYBE_INTERCEPT___FXSTAT64 #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_TLS_WORKAROUND_NEEDED TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) { SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf); if (fd > 0) @@ -1466,8 +1523,18 @@ } #define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64) #else +#if SANITIZER_TLS_WORKAROUND_NEEDED +TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) { + SCOPED_TSAN_INTERCEPTOR(fstat64, fd, buf); + if (fd > 0) + FdAccess(thr, pc, fd); + return REAL(fstat64)(fd, buf); +} +#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64) +#else #define TSAN_MAYBE_INTERCEPT_FSTAT64 #endif +#endif TSAN_INTERCEPTOR(int, open, const char *name, int flags, int mode) { SCOPED_TSAN_INTERCEPTOR(open, name, flags, mode); @@ -1867,8 +1934,8 @@ if (acquire) Acquire(thr, 0, (uptr)&sigactions[sig]); // Ensure that the handler does not spoil errno. - const int saved_errno = errno; - errno = 99; + const int saved_errno = get_errno_lval; + get_errno_lval = 99; // This code races with sigaction. Be careful to not read sa_sigaction twice. // Also need to remember pc for reporting before the call, // because the handler can reset it. @@ -1888,7 +1955,7 @@ // because in async signal processing case (when handler is called directly // from rtl_generic_sighandler) we have not yet received the reraised // signal; and it looks too fragile to intercept all ways to reraise a signal. - if (flags()->report_bugs && !sync && sig != SIGTERM && errno != 99) { + if (flags()->report_bugs && !sync && sig != SIGTERM && get_errno_lval != 99) { VarSizeStackTrace stack; // StackTrace::GetNestInstructionPc(pc) is used because return address is // expected, OutputReport() will undo this. @@ -1900,7 +1967,7 @@ OutputReport(thr, rep); } } - errno = saved_errno; + get_errno_lval = saved_errno; } void ProcessPendingSignals(ThreadState *thr) { @@ -1910,10 +1977,21 @@ return; atomic_store(&sctx->have_pending_signals, 0, memory_order_relaxed); atomic_fetch_add(&thr->in_signal_handler, 1, memory_order_relaxed); +#if SANITIZER_TLS_WORKAROUND_NEEDED + extern __sanitizer_sigset_t &get_from_tls_emptyset(); + extern __sanitizer_sigset_t &get_from_tls_oldset(); + extern void internal_sigfillset(__sanitizer_sigset_t *f); +#else // These are too big for stack. static THREADLOCAL __sanitizer_sigset_t emptyset, oldset; - CHECK_EQ(0, REAL(sigfillset)(&emptyset)); - CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &emptyset, &oldset)); +#endif + __sanitizer_sigset_t *P = & GetFromTLS(emptyset); + CHECK_EQ(0, REAL(sigfillset)(P)); + __sanitizer_sigset_t *E = &GetFromTLS(emptyset); + __sanitizer_sigset_t *O = &GetFromTLS(oldset); + + CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, E, O)); + for (int sig = 0; sig < kSigCount; sig++) { SignalDesc *signal = &sctx->pending_signals[sig]; if (signal->armed) { @@ -1922,7 +2000,7 @@ &signal->siginfo, &signal->ctx); } } - CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &oldset, 0)); + CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &GetFromTLS(oldset), 0)); atomic_fetch_add(&thr->in_signal_handler, -1, memory_order_relaxed); } @@ -2463,7 +2541,7 @@ REAL(memcpy) = internal_memcpy; // Instruct libc malloc to consume less memory. -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID mallopt(1, 0); // M_MXFAST mallopt(-3, 32*1024); // M_MMAP_THRESHOLD #endif Index: lib/tsan/rtl/tsan_interface.cc =================================================================== --- lib/tsan/rtl/tsan_interface.cc +++ lib/tsan/rtl/tsan_interface.cc @@ -23,8 +23,15 @@ typedef u16 uint16_t; typedef u32 uint32_t; typedef u64 uint64_t; +#if SANITIZER_TLS_WORKAROUND_NEEDED +static u64 __tsan_init_count = 0; +#endif void __tsan_init() { +#if SANITIZER_TLS_WORKAROUND_NEEDED + __tsan_init_count++; + DPrintf("__tsan_init called %lld times\n", __tsan_init_count); +#endif Initialize(cur_thread()); } Index: lib/tsan/rtl/tsan_new_delete.cc =================================================================== --- lib/tsan/rtl/tsan_new_delete.cc +++ lib/tsan/rtl/tsan_new_delete.cc @@ -20,6 +20,16 @@ struct nothrow_t {}; } // namespace std +#if SANITIZER_TLS_WORKAROUND_NEEDED +#include "interception/interception.h" + +DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr); +DECLARE_REAL_AND_INTERCEPTOR(void, free, void *); + +#define __libc_malloc REAL(malloc) +#define __libc_free REAL(free) +#endif + #define OPERATOR_NEW_BODY(mangled_name) \ if (cur_thread()->in_symbolizer) \ return __libc_malloc(size); \ Index: lib/tsan/rtl/tsan_platform.h =================================================================== --- lib/tsan/rtl/tsan_platform.h +++ lib/tsan/rtl/tsan_platform.h @@ -14,7 +14,6 @@ #ifndef TSAN_PLATFORM_H #define TSAN_PLATFORM_H - #if !defined(__LP64__) && !defined(_WIN64) # error "Only 64-bit is supported" #endif @@ -87,6 +86,7 @@ const uptr kAppMemXor = 0x0400000000ull; const uptr kVdsoBeg = 0xfffff00000ull; #elif defined(__aarch64__) +#if !SANITIZER_ANDROID /* C/C++ on linux/aarch64 (39-bit VMA) 0000 4000 00 - 0200 0000 00: main binary @@ -113,7 +113,28 @@ const uptr kAppMemMsk = 0x7800000000ull; const uptr kAppMemXor = 0x0800000000ull; const uptr kVdsoBeg = 0x7f00000000ull; -#endif +#else +/* +// aarch64-android: -- memory maps are wierd here. +*/ +const uptr kShadowBeg = 0x1400000000ull; +const uptr kShadowEnd = 0x2400000000ull; +const uptr kMetaShadowBeg = 0x3000000000ull; +const uptr kMetaShadowEnd = 0x4000000000ull; +const uptr kLoAppMemBeg = 0x5500000000ull; +const uptr kLoAppMemEnd = 0x5600000000ull; +const uptr kTraceMemBeg = 0x6000000000ull; +const uptr kTraceMemEnd = 0x6200000000ull; +const uptr kHeapMemBeg = 0x7e00000000ull; +const uptr kHeapMemEnd = 0x7f00000000ull; +const uptr kHiAppMemBeg = 0x7f00000000ull; +const uptr kHiAppMemEnd = 0x8000000000ull; +const uptr kAppMemMsk = 0xfc00000000ull; +const uptr kAppMemMskRtn = 0x7c00000000ull; +const uptr kAppMemXor = 0x0400000000ull; +const uptr kVdsoBeg = 0xf000000000ull; +#endif // !SANITIZER_ANDROID +#endif // __aarch64__ ALWAYS_INLINE bool IsAppMem(uptr mem) { @@ -146,6 +167,16 @@ ^ kAppMemXor) / kMetaShadowCell * kMetaShadowSize) | kMetaShadowBeg); } +#if defined(__aarch64__) +ALWAYS_INLINE +uptr ShadowToMem(uptr s) { + CHECK(IsShadowMem(s)); + if (s >= MemToShadow(kLoAppMemBeg) && s <= MemToShadow(kLoAppMemEnd - 1)) + return (s / kShadowCnt) ^ kAppMemXor | kLoAppMemBeg; + else + return ((s / kShadowCnt) ^ kAppMemXor) | kAppMemMskRtn; +} +#else // __mips64 and __x86_64__ ALWAYS_INLINE uptr ShadowToMem(uptr s) { CHECK(IsShadowMem(s)); @@ -154,6 +185,7 @@ else return ((s / kShadowCnt) ^ kAppMemXor) | kAppMemMsk; } +#endif static USED uptr UserRegions[] = { kLoAppMemBeg, kLoAppMemEnd, Index: lib/tsan/rtl/tsan_platform_linux.cc =================================================================== --- lib/tsan/rtl/tsan_platform_linux.cc +++ lib/tsan/rtl/tsan_platform_linux.cc @@ -221,9 +221,12 @@ #elif defined(__mips64) const uptr kMadviseRangeBeg = 0xff00000000ull; const uptr kMadviseRangeSize = 0x0100000000ull; -#elif defined(__aarch64__) +#elif defined(__aarch64__) && !SANITIZER_ANDROID const uptr kMadviseRangeBeg = 0x7e00000000ull; const uptr kMadviseRangeSize = 0x0100000000ull; +#elif SANITIZER_TLS_WORKAROUND_NEEDED + const uptr kMadviseRangeBeg = kHiAppMemBeg; + const uptr kMadviseRangeSize = kHiAppMemEnd - kHiAppMemBeg; #endif NoHugePagesInRegion(MemToShadow(kMadviseRangeBeg), kMadviseRangeSize * kShadowMultiplier); @@ -311,6 +314,18 @@ Die(); } +#if SANITIZER_TLS_WORKAROUND_NEEDED + // on aaarch64/android, the memory maps are significantly different + ProtectRange(kShadowEnd, kMetaShadowBeg); + ProtectRange(kMetaShadowEnd, kLoAppMemBeg); + ProtectRange(kLoAppMemEnd, kTraceMemBeg); + + // Memory for traces is mapped lazily in MapThreadTrace. + // Protect the whole range for now, so that user does not map something here. + ProtectRange(kTraceMemBeg, kTraceMemEnd); + ProtectRange(kTraceMemEnd, kHeapMemBeg); + //ProtectRange(HeapEnd(), kHiAppMemBeg); +#else ProtectRange(kLoAppMemEnd, kShadowBeg); ProtectRange(kShadowEnd, kMetaShadowBeg); ProtectRange(kMetaShadowEnd, kTraceMemBeg); @@ -319,6 +334,7 @@ ProtectRange(kTraceMemBeg, kTraceMemEnd); ProtectRange(kTraceMemEnd, kHeapMemBeg); ProtectRange(HeapEnd(), kHiAppMemBeg); +#endif } #endif // #ifndef SANITIZER_GO @@ -370,7 +386,7 @@ // This is required to properly "close" the fds, because we do not see internal // closes within glibc. The code is a pure hack. int ExtractResolvFDs(void *state, int *fds, int nfd) { -#if SANITIZER_LINUX +#if SANITIZER_LINUX && !SANITIZER_ANDROID int cnt = 0; __res_state *statp = (__res_state*)state; for (int i = 0; i < MAXNS && cnt < nfd; i++) { Index: lib/tsan/rtl/tsan_rtl.h =================================================================== --- lib/tsan/rtl/tsan_rtl.h +++ lib/tsan/rtl/tsan_rtl.h @@ -34,6 +34,9 @@ #include "sanitizer_common/sanitizer_libignore.h" #include "sanitizer_common/sanitizer_suppressions.h" #include "sanitizer_common/sanitizer_thread_registry.h" + +// this needs to be pulled in first +#include "tsan_aarch64_tls_workaround.h" #include "tsan_clock.h" #include "tsan_defs.h" #include "tsan_flags.h" @@ -410,11 +413,19 @@ }; #ifndef SANITIZER_GO +#if !SANITIZER_TLS_WORKAROUND_NEEDED __attribute__((tls_model("initial-exec"))) extern THREADLOCAL char cur_thread_placeholder[]; INLINE ThreadState *cur_thread() { - return reinterpret_cast(&cur_thread_placeholder); + return reinterpret_cast(&GetFromTLS(cur_thread_placeholder)); } +#else +extern char &get_from_tls_cur_thread_placeholder(); +INLINE ThreadState *cur_thread() { + return reinterpret_cast + (&get_from_tls_cur_thread_placeholder()); +} +#endif #endif class ThreadContext : public ThreadContextBase { Index: lib/tsan/rtl/tsan_rtl.cc =================================================================== --- lib/tsan/rtl/tsan_rtl.cc +++ lib/tsan/rtl/tsan_rtl.cc @@ -45,7 +45,11 @@ namespace __tsan { #ifndef SANITIZER_GO +#if !SANITIZER_TLS_WORKAROUND_NEEDED THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64); +// these are the real accessor functions +extern char &get_from_tls_cur_thread_placeholder(); +#endif #endif static char ctx_placeholder[sizeof(Context)] ALIGNED(64); Context *ctx; @@ -294,7 +298,9 @@ continue; const uptr s = MemToShadow(p); const uptr m = (uptr)MemToMeta(p); - VPrintf(3, " checking pointer %p: shadow=%p meta=%p\n", p, s, m); + const uptr s1 = ShadowToMem(s); + VPrintf(3, " checking pointer %p: shadow=%p meta=%p s2m=%p\n", \ + p, s, m, s1); CHECK(IsAppMem(p)); CHECK(IsShadowMem(s)); CHECK_EQ(p & ~(kShadowCell - 1), ShadowToMem(s)); @@ -340,7 +346,7 @@ // On MIPS, TSan initialization is run before // __pthread_initialize_minimal_internal() is finished, so we can not spawn // new threads. -#ifndef __mips__ +#if !defined(__mips__) && !SANITIZER_TLS_WORKAROUND_NEEDED StartBackgroundThread(); SetSandboxingCallback(StopBackgroundThread); #endif Index: test/lit.common.configured.in =================================================================== --- test/lit.common.configured.in +++ test/lit.common.configured.in @@ -27,6 +27,8 @@ set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@) set_default("compiler_rt_libdir", "@COMPILER_RT_LIBRARY_OUTPUT_DIR@") set_default("emulator", "@COMPILER_RT_EMULATOR@") +set_default("is_cross_compiling", "@COMPILER_RT_CROSS_COMPILING@") +set_default("test_compiler_cflags", "@COMPILER_RT_TEST_COMPILER_CFLAGS@") set_default("sanitizer_can_use_cxxabi", @SANITIZER_CAN_USE_CXXABI_PYBOOL@) set_default("has_lld", @COMPILER_RT_HAS_LLD_SOURCES_PYBOOL@) Index: test/tsan/Linux/mutex_robust.cc =================================================================== --- test/tsan/Linux/mutex_robust.cc +++ test/tsan/Linux/mutex_robust.cc @@ -1,4 +1,5 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// UNSUPPORTED: aarch64-linux-androideabi #include #include #include Index: test/tsan/Linux/mutex_robust2.cc =================================================================== --- test/tsan/Linux/mutex_robust2.cc +++ test/tsan/Linux/mutex_robust2.cc @@ -1,4 +1,5 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +// UNSUPPORTED: aarch64-linux-androideabi #include #include #include Index: test/tsan/allocator_returns_null.cc =================================================================== --- test/tsan/allocator_returns_null.cc +++ test/tsan/allocator_returns_null.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // Test the behavior of malloc/calloc/realloc when the allocation size is huge. // By default (allocator_may_return_null=0) the process should crash. // With allocator_may_return_null=1 the allocator should return 0. Index: test/tsan/annotate_happens_before.cc =================================================================== --- test/tsan/annotate_happens_before.cc +++ test/tsan/annotate_happens_before.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/atexit.cc =================================================================== --- test/tsan/atexit.cc +++ test/tsan/atexit.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include Index: test/tsan/atomic_norace.cc =================================================================== --- test/tsan/atomic_norace.cc +++ test/tsan/atomic_norace.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/atomic_race.cc =================================================================== --- test/tsan/atomic_race.cc +++ test/tsan/atomic_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/atomic_stack.cc =================================================================== --- test/tsan/atomic_stack.cc +++ test/tsan/atomic_stack.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/barrier.cc =================================================================== --- test/tsan/barrier.cc +++ test/tsan/barrier.cc @@ -1,4 +1,5 @@ // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s +// UNSUPPORTED: aarch64-linux-androideabi // CHECK-NOT: ThreadSanitizer: data race // CHECK: DONE Index: test/tsan/bench_acquire_only.cc =================================================================== --- test/tsan/bench_acquire_only.cc +++ test/tsan/bench_acquire_only.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_acquire_release.cc =================================================================== --- test/tsan/bench_acquire_release.cc +++ test/tsan/bench_acquire_release.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_local_mutex.cc =================================================================== --- test/tsan/bench_local_mutex.cc +++ test/tsan/bench_local_mutex.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_mutex.cc =================================================================== --- test/tsan/bench_mutex.cc +++ test/tsan/bench_mutex.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_release_only.cc =================================================================== --- test/tsan/bench_release_only.cc +++ test/tsan/bench_release_only.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_rwmutex.cc =================================================================== --- test/tsan/bench_rwmutex.cc +++ test/tsan/bench_rwmutex.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_single_writer.cc =================================================================== --- test/tsan/bench_single_writer.cc +++ test/tsan/bench_single_writer.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/bench_ten_mutexes.cc =================================================================== --- test/tsan/bench_ten_mutexes.cc +++ test/tsan/bench_ten_mutexes.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: %run %t 2>&1 | FileCheck %s Index: test/tsan/benign_race.cc =================================================================== --- test/tsan/benign_race.cc +++ test/tsan/benign_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/blacklist2.cc =================================================================== --- test/tsan/blacklist2.cc +++ test/tsan/blacklist2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // Test that blacklisted functions are still contained in the stack trace. // RUN: echo "fun:*Blacklisted_Thread2*" > %t.blacklist Index: test/tsan/cond_cancel.c =================================================================== --- test/tsan/cond_cancel.c +++ test/tsan/cond_cancel.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // CHECK-NOT: WARNING // CHECK: OK Index: test/tsan/cond_destruction.cc =================================================================== --- test/tsan/cond_destruction.cc +++ test/tsan/cond_destruction.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t // RUN: %run %t 2>&1 | FileCheck %s // RUN: %run %t arg 2>&1 | FileCheck %s Index: test/tsan/cond_race.cc =================================================================== --- test/tsan/cond_race.cc +++ test/tsan/cond_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s // CHECK-NOT: unlock of unlocked mutex // CHECK: ThreadSanitizer: data race Index: test/tsan/cond_version.c =================================================================== --- test/tsan/cond_version.c +++ test/tsan/cond_version.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t -lrt && %run %t 2>&1 | FileCheck %s // Test that pthread_cond is properly intercepted, // previously there were issues with versioned symbols. Index: test/tsan/deadlock_detector_stress_test.cc =================================================================== --- test/tsan/deadlock_detector_stress_test.cc +++ test/tsan/deadlock_detector_stress_test.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex // RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND // RUN: TSAN_OPTIONS="detect_deadlocks=1 second_deadlock_stack=1" %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND Index: test/tsan/deep_stack1.cc =================================================================== --- test/tsan/deep_stack1.cc +++ test/tsan/deep_stack1.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s // RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/deflake.bash.emulator =================================================================== --- /dev/null +++ test/tsan/deflake.bash.emulator @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# This script is used to deflake inherently flaky tsan tests. +# It is invoked from lit tests as: +# %deflake mybinary +# which is then substituted by lit to: +# $(dirname %s)/deflake.bash mybinary +# The script runs the target program up to 10 times, +# until it fails (i.e. produces a race report). +# but if the emulator (such as adb shell) does not reliably +# return an exit code, then we have to grep the output for 'ThreadSanitizer: ' + +for i in $(seq 1 10); do + OUT=`$@ 2>&1` + if echo "$OUT" | grep -e 'ThreadSanitizer: '; then + echo "$OUT" + exit 0 + fi + if [[ $? != 0 ]]; then + echo "$OUT" + exit 0 + fi +done +exit 1 Index: test/tsan/dl_iterate_phdr.cc =================================================================== --- test/tsan/dl_iterate_phdr.cc +++ test/tsan/dl_iterate_phdr.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s Index: test/tsan/dlclose.cc =================================================================== --- test/tsan/dlclose.cc +++ test/tsan/dlclose.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s Index: test/tsan/fd_close_norace.cc =================================================================== --- test/tsan/fd_close_norace.cc +++ test/tsan/fd_close_norace.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" #include Index: test/tsan/fd_location.cc =================================================================== --- test/tsan/fd_location.cc +++ test/tsan/fd_location.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/fd_pipe_race.cc =================================================================== --- test/tsan/fd_pipe_race.cc +++ test/tsan/fd_pipe_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/fd_stdout_race.cc =================================================================== --- test/tsan/fd_stdout_race.cc +++ test/tsan/fd_stdout_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/fork_atexit.cc =================================================================== --- test/tsan/fork_atexit.cc +++ test/tsan/fork_atexit.cc @@ -1,3 +1,5 @@ +// UNSUPPORTED: aarch64-linux-androideabi +// this test hangs on android, and requires a timeout mechanism // RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="atexit_sleep_ms=50" %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/fork_multithreaded.cc =================================================================== --- test/tsan/fork_multithreaded.cc +++ test/tsan/fork_multithreaded.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE // RUN: %clangxx_tsan -O1 %s -o %t && TSAN_OPTIONS="die_after_fork=0" %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE #include "test.h" Index: test/tsan/free_race.c =================================================================== --- test/tsan/free_race.c +++ test/tsan/free_race.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t // RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOZUPP // RUN: TSAN_OPTIONS="suppressions='%s.supp' print_suppressions=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPP Index: test/tsan/free_race2.c =================================================================== --- test/tsan/free_race2.c +++ test/tsan/free_race2.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include Index: test/tsan/global_race.cc =================================================================== --- test/tsan/global_race.cc +++ test/tsan/global_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %T/global_race.cc.exe && %deflake %run %T/global_race.cc.exe | FileCheck %s #include "test.h" Index: test/tsan/global_race2.cc =================================================================== --- test/tsan/global_race2.cc +++ test/tsan/global_race2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/global_race3.cc =================================================================== --- test/tsan/global_race3.cc +++ test/tsan/global_race3.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/halt_on_error.cc =================================================================== --- test/tsan/halt_on_error.cc +++ test/tsan/halt_on_error.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/ignore_free.cc =================================================================== --- test/tsan/ignore_free.cc +++ test/tsan/ignore_free.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/ignore_lib0.cc =================================================================== --- test/tsan/ignore_lib0.cc +++ test/tsan/ignore_lib0.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib0.so // RUN: %clangxx_tsan -O1 %s -L%T -lignore_lib0 -o %t // RUN: echo running w/o suppressions: @@ -9,7 +10,7 @@ // suppression are ignored. // Some aarch64 kernels do not support non executable write pages -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #ifndef LIB Index: test/tsan/ignore_lib1.cc =================================================================== --- test/tsan/ignore_lib1.cc +++ test/tsan/ignore_lib1.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib1.so // RUN: %clangxx_tsan -O1 %s -o %t // RUN: echo running w/o suppressions: @@ -8,7 +9,7 @@ // Tests that interceptors coming from a dynamically loaded library specified // in called_from_lib suppression are ignored. -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #ifndef LIB Index: test/tsan/ignore_lib2.cc =================================================================== --- test/tsan/ignore_lib2.cc +++ test/tsan/ignore_lib2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_0.so // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_1.so // RUN: %clangxx_tsan -O1 %s -o %t Index: test/tsan/ignore_lib3.cc =================================================================== --- test/tsan/ignore_lib3.cc +++ test/tsan/ignore_lib3.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib3.so // RUN: %clangxx_tsan -O1 %s -o %t // RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %deflake %run %t | FileCheck %s @@ -6,7 +7,7 @@ // causes program crash (this is not supported). // Some aarch64 kernels do not support non executable write pages -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #ifndef LIB Index: test/tsan/ignore_race.cc =================================================================== --- test/tsan/ignore_race.cc +++ test/tsan/ignore_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/inlined_memcpy_race.cc =================================================================== --- test/tsan/inlined_memcpy_race.cc +++ test/tsan/inlined_memcpy_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/inlined_memcpy_race2.cc =================================================================== --- test/tsan/inlined_memcpy_race2.cc +++ test/tsan/inlined_memcpy_race2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/java_finalizer.cc =================================================================== --- test/tsan/java_finalizer.cc +++ test/tsan/java_finalizer.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/java_lock.cc =================================================================== --- test/tsan/java_lock.cc +++ test/tsan/java_lock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/java_lock_move.cc =================================================================== --- test/tsan/java_lock_move.cc +++ test/tsan/java_lock_move.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/java_lock_rec.cc =================================================================== --- test/tsan/java_lock_rec.cc +++ test/tsan/java_lock_rec.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/java_move_overlap.cc =================================================================== --- test/tsan/java_move_overlap.cc +++ test/tsan/java_move_overlap.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t // RUN: %run %t 2>&1 | FileCheck %s // RUN: %run %t arg 2>&1 | FileCheck %s Index: test/tsan/java_move_overlap_race.cc =================================================================== --- test/tsan/java_move_overlap_race.cc +++ test/tsan/java_move_overlap_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t // RUN: %deflake %run %t | FileCheck %s // RUN: %deflake %run %t arg | FileCheck %s Index: test/tsan/java_race_pc.cc =================================================================== --- test/tsan/java_race_pc.cc +++ test/tsan/java_race_pc.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "java.h" Index: test/tsan/java_rwlock.cc =================================================================== --- test/tsan/java_rwlock.cc +++ test/tsan/java_rwlock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/java_symbolization.cc =================================================================== --- test/tsan/java_symbolization.cc +++ test/tsan/java_symbolization.cc @@ -1,3 +1,5 @@ +// UNSUPPORTED: aarch64-linux-androideabi +// UNSUPPORTED: *android* // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "java.h" #include Index: test/tsan/java_volatile.cc =================================================================== --- test/tsan/java_volatile.cc +++ test/tsan/java_volatile.cc @@ -1,3 +1,5 @@ +// UNSUPPORTED: aarch64-linux-androideabi +// UNSUPPORTED: *android* // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "java.h" Index: test/tsan/lit.cfg =================================================================== --- test/tsan/lit.cfg +++ test/tsan/lit.cfg @@ -29,9 +29,21 @@ extra_cflags = [] # Setup default compiler flags used with -fsanitize=thread option. +tsan_test_cflags = [] +if config.is_cross_compiling and config.target_triple == "aarch64-linux-androideabi": + tsan_test_cflags = config.test_compiler_cflags.split(" ") + +# get the target triple components in config.available_features +for word in config.target_triple.split("-"): + if len(word) > 0: + config.available_features.add(word) + +config.available_features.add(config.target_triple) + + clang_tsan_cflags = ["-fsanitize=thread", "-Wall", - "-m64"] + config.debug_info_flags + extra_cflags + "-m64"] + config.debug_info_flags + extra_cflags + tsan_test_cflags clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags # Add additional flags if we're using instrumented libc++. if config.has_libcxx: @@ -55,7 +67,10 @@ # Define CHECK-%os to check for OS-dependent output. config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) -config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash")) ) +if config.is_cross_compiling and config.emulator: + config.substitutions.append( ("%deflake", os.path.join(os.path.dirname(__file__), "deflake.bash.emulator")) ) +else: + config.substitutions.append( ("%deflake", os.path.join(os.path.dirname(__file__), "deflake.bash")) ) # Default test suffixes. config.suffixes = ['.c', '.cc', '.cpp'] @@ -63,3 +78,8 @@ # ThreadSanitizer tests are currently supported on FreeBSD and Linux only. if config.host_os not in ['FreeBSD', 'Linux']: config.unsupported = True +# FIXME: android tests are not yet stable! +# there are a few tests that are flaky in ways that are unexpected +# until they are fixed. rule it out for now. +# if config.target_triple == 'aarch64-linux-androideabi': +# config.unsupported = True Index: test/tsan/load_shared_lib.cc =================================================================== --- test/tsan/load_shared_lib.cc +++ test/tsan/load_shared_lib.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // Check that if the list of shared libraries changes between the two race // reports, the second report occurring in a new shared library is still // symbolized correctly. Index: test/tsan/longjmp.cc =================================================================== --- test/tsan/longjmp.cc +++ test/tsan/longjmp.cc @@ -1,8 +1,10 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // Longjmp assembly has not been implemented for mips64 or aarch64 yet // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi + #include #include Index: test/tsan/longjmp2.cc =================================================================== --- test/tsan/longjmp2.cc +++ test/tsan/longjmp2.cc @@ -1,8 +1,9 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // Longjmp assembly has not been implemented for mips64 or aarch64 yet // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #include #include Index: test/tsan/longjmp3.cc =================================================================== --- test/tsan/longjmp3.cc +++ test/tsan/longjmp3.cc @@ -1,8 +1,9 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s // Longjmp assembly has not been implemented for mips64 or aarch64 yet // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #include #include Index: test/tsan/longjmp4.cc =================================================================== --- test/tsan/longjmp4.cc +++ test/tsan/longjmp4.cc @@ -1,8 +1,9 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s // Longjmp assembly has not been implemented for mips64 or aarch64 yet // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #include #include Index: test/tsan/malloc_stack.cc =================================================================== --- test/tsan/malloc_stack.cc +++ test/tsan/malloc_stack.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/map32bit.cc =================================================================== --- test/tsan/map32bit.cc +++ test/tsan/map32bit.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s #include "test.h" #include @@ -9,7 +10,7 @@ // MAP_32BIT flag for mmap is supported only for x86_64. // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi void *Thread(void *ptr) { *(int*)ptr = 42; Index: test/tsan/memcmp_race.cc =================================================================== --- test/tsan/memcmp_race.cc +++ test/tsan/memcmp_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/memcpy_race.cc =================================================================== --- test/tsan/memcpy_race.cc +++ test/tsan/memcpy_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/mmap_large.cc =================================================================== --- test/tsan/mmap_large.cc +++ test/tsan/mmap_large.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/mmap_stress.cc =================================================================== --- test/tsan/mmap_stress.cc +++ test/tsan/mmap_stress.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" #include Index: test/tsan/mop_with_offset.cc =================================================================== --- test/tsan/mop_with_offset.cc +++ test/tsan/mop_with_offset.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mop_with_offset2.cc =================================================================== --- test/tsan/mop_with_offset2.cc +++ test/tsan/mop_with_offset2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutex_bad_read_lock.cc =================================================================== --- test/tsan/mutex_bad_read_lock.cc +++ test/tsan/mutex_bad_read_lock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw); Index: test/tsan/mutex_bad_read_unlock.cc =================================================================== --- test/tsan/mutex_bad_read_unlock.cc +++ test/tsan/mutex_bad_read_unlock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw); extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw); Index: test/tsan/mutex_bad_unlock.cc =================================================================== --- test/tsan/mutex_bad_unlock.cc +++ test/tsan/mutex_bad_unlock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw); Index: test/tsan/mutex_cycle2.c =================================================================== --- test/tsan/mutex_cycle2.c +++ test/tsan/mutex_cycle2.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan %s -o %t // RUN: not %run %t 2>&1 | FileCheck %s // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s Index: test/tsan/mutex_destroy_locked.cc =================================================================== --- test/tsan/mutex_destroy_locked.cc +++ test/tsan/mutex_destroy_locked.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include #include Index: test/tsan/mutex_double_lock.cc =================================================================== --- test/tsan/mutex_double_lock.cc +++ test/tsan/mutex_double_lock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include #include Index: test/tsan/mutexset1.cc =================================================================== --- test/tsan/mutexset1.cc +++ test/tsan/mutexset1.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset2.cc =================================================================== --- test/tsan/mutexset2.cc +++ test/tsan/mutexset2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset3.cc =================================================================== --- test/tsan/mutexset3.cc +++ test/tsan/mutexset3.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset4.cc =================================================================== --- test/tsan/mutexset4.cc +++ test/tsan/mutexset4.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset5.cc =================================================================== --- test/tsan/mutexset5.cc +++ test/tsan/mutexset5.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset6.cc =================================================================== --- test/tsan/mutexset6.cc +++ test/tsan/mutexset6.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset7.cc =================================================================== --- test/tsan/mutexset7.cc +++ test/tsan/mutexset7.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/mutexset8.cc =================================================================== --- test/tsan/mutexset8.cc +++ test/tsan/mutexset8.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/pthread_atfork_deadlock.c =================================================================== --- test/tsan/pthread_atfork_deadlock.c +++ test/tsan/pthread_atfork_deadlock.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -lpthread -o %t && %deflake %run %t | FileCheck %s // Regression test for // https://code.google.com/p/thread-sanitizer/issues/detail?id=61 Index: test/tsan/race_on_barrier.c =================================================================== --- test/tsan/race_on_barrier.c +++ test/tsan/race_on_barrier.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/race_on_barrier2.c =================================================================== --- test/tsan/race_on_barrier2.c +++ test/tsan/race_on_barrier2.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include #include Index: test/tsan/race_on_heap.cc =================================================================== --- test/tsan/race_on_heap.cc +++ test/tsan/race_on_heap.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include #include Index: test/tsan/race_on_mutex.c =================================================================== --- test/tsan/race_on_mutex.c +++ test/tsan/race_on_mutex.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/race_on_read.cc =================================================================== --- test/tsan/race_on_read.cc +++ test/tsan/race_on_read.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/race_on_speculative_load.cc =================================================================== --- test/tsan/race_on_speculative_load.cc +++ test/tsan/race_on_speculative_load.cc @@ -1,4 +1,5 @@ // RUN: %clangxx_tsan -O1 %s -o %t && %run %t | FileCheck %s +// UNSUPPORTED: aarch64-linux-androideabi // Regtest for https://code.google.com/p/thread-sanitizer/issues/detail?id=40 // This is a correct program and tsan should not report a race. #include "test.h" Index: test/tsan/race_on_write.cc =================================================================== --- test/tsan/race_on_write.cc +++ test/tsan/race_on_write.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/race_top_suppression.cc =================================================================== --- test/tsan/race_top_suppression.cc +++ test/tsan/race_top_suppression.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: echo "race_top:TopFunction" > %t.supp // RUN: %clangxx_tsan -O1 %s -o %t // RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%t.supp'" %run %t 2>&1 | FileCheck %s Index: test/tsan/race_with_finished_thread.cc =================================================================== --- test/tsan/race_with_finished_thread.cc +++ test/tsan/race_with_finished_thread.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/real_deadlock_detector_stress_test.cc =================================================================== --- test/tsan/real_deadlock_detector_stress_test.cc +++ test/tsan/real_deadlock_detector_stress_test.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include Index: test/tsan/restore_stack.cc =================================================================== --- test/tsan/restore_stack.cc +++ test/tsan/restore_stack.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/signal_cond.cc =================================================================== --- test/tsan/signal_cond.cc +++ test/tsan/signal_cond.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" #include Index: test/tsan/signal_errno.cc =================================================================== --- test/tsan/signal_errno.cc +++ test/tsan/signal_errno.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/signal_longjmp.cc =================================================================== --- test/tsan/signal_longjmp.cc +++ test/tsan/signal_longjmp.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // Test case for longjumping out of signal handler: @@ -5,7 +6,7 @@ // Longjmp assembly has not been implemented for mips64 or aarch64 yet // XFAIL: mips64 -// XFAIL: aarch64 +// UNSUPPORTED: aarch64-linux-androideabi #include #include Index: test/tsan/signal_malloc.cc =================================================================== --- test/tsan/signal_malloc.cc +++ test/tsan/signal_malloc.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/signal_reset.cc =================================================================== --- test/tsan/signal_reset.cc +++ test/tsan/signal_reset.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/signal_sync.cc =================================================================== --- test/tsan/signal_sync.cc +++ test/tsan/signal_sync.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" #include Index: test/tsan/signal_thread.cc =================================================================== --- test/tsan/signal_thread.cc +++ test/tsan/signal_thread.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/signal_write.cc =================================================================== --- test/tsan/signal_write.cc +++ test/tsan/signal_write.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/sigsuspend.cc =================================================================== --- test/tsan/sigsuspend.cc +++ test/tsan/sigsuspend.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s // Always enable asserts. Index: test/tsan/simple_race.cc =================================================================== --- test/tsan/simple_race.cc +++ test/tsan/simple_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/simple_stack.c =================================================================== --- test/tsan/simple_stack.c +++ test/tsan/simple_stack.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/simple_stack2.cc =================================================================== --- test/tsan/simple_stack2.cc +++ test/tsan/simple_stack2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %T/simple_stack2.cc.exe && %deflake %run %T/simple_stack2.cc.exe | FileCheck %s #include "test.h" Index: test/tsan/sleep_sync.cc =================================================================== --- test/tsan/sleep_sync.cc +++ test/tsan/sleep_sync.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/stack_race.cc =================================================================== --- test/tsan/stack_race.cc +++ test/tsan/stack_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/stack_race2.cc =================================================================== --- test/tsan/stack_race2.cc +++ test/tsan/stack_race2.cc @@ -1,3 +1,5 @@ +// UNSUPPORTED: aarch64-linux-androideabi +// Fails on android due to not detecting the race is from stack // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/sunrpc.cc =================================================================== --- test/tsan/sunrpc.cc +++ test/tsan/sunrpc.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include Index: test/tsan/suppress_same_address.cc =================================================================== --- test/tsan/suppress_same_address.cc +++ test/tsan/suppress_same_address.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/suppress_same_stacks.cc =================================================================== --- test/tsan/suppress_same_stacks.cc +++ test/tsan/suppress_same_stacks.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include Index: test/tsan/suppressions_global.cc =================================================================== --- test/tsan/suppressions_global.cc +++ test/tsan/suppressions_global.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %run %t 2>&1 | FileCheck %s #include #include Index: test/tsan/suppressions_race.cc =================================================================== --- test/tsan/suppressions_race.cc +++ test/tsan/suppressions_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/suppressions_race2.cc =================================================================== --- test/tsan/suppressions_race2.cc +++ test/tsan/suppressions_race2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS suppressions='%s.supp'" %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/test.h =================================================================== --- test/tsan/test.h +++ test/tsan/test.h @@ -5,6 +5,53 @@ #include #include +#if defined(__ANDROID__) && defined(__aarch64__) + +// hack up a pthread_barrier_wait from sanitizer_clang.h +#if defined(__clang__) || defined(__GNUC_) + +struct atomic_uint32_t { + volatile unsigned count; + volatile unsigned max; + volatile unsigned reset; +}; + + +typedef struct atomic_uint32_t pthread_barrier_t; + +void barrier_init(pthread_barrier_t *barrier, unsigned count) { + __sync_synchronize(); + barrier->count = 0; + barrier->max = count; + barrier->reset = 0; + __sync_synchronize(); +} + +int barrier_wait(pthread_barrier_t *barrier) { + volatile unsigned k = 0; + __sync_fetch_and_add(&barrier->count, 1); + do { + k = barrier->count; + } while (k < barrier->max); + // FIXME: putting a __sync_synchronize() here or using a full barrier + // on the above comparison changes which tests + // fail and pass + + if (__sync_lock_test_and_set(&barrier->reset, 1)) { + __sync_lock_release(&barrier->reset, 0); + return 1; + } + return 0; +} + +pthread_barrier_t barrier; + +#else +#error "Unsupported compiler. You need to implement pthread_barrier and friends" +#endif // defined(__clang__) || defined(__GNUC_) + +#else + // TSan-invisible barrier. // Tests use it to establish necessary execution order in a way that does not // interfere with tsan (does not establish synchronization between threads). @@ -44,3 +91,4 @@ fprintf(stderr, "0x%010lx", (unsigned long) address); #endif } +#endif // defined(__ANDROID__) && defined(__aarch64__) Index: test/tsan/thread_detach2.c =================================================================== --- test/tsan/thread_detach2.c +++ test/tsan/thread_detach2.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s #include "test.h" Index: test/tsan/thread_end_with_ignore.cc =================================================================== --- test/tsan/thread_end_with_ignore.cc +++ test/tsan/thread_end_with_ignore.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include #include Index: test/tsan/thread_end_with_ignore2.cc =================================================================== --- test/tsan/thread_end_with_ignore2.cc +++ test/tsan/thread_end_with_ignore2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l); Index: test/tsan/thread_end_with_ignore3.cc =================================================================== --- test/tsan/thread_end_with_ignore3.cc +++ test/tsan/thread_end_with_ignore3.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l); extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l); Index: test/tsan/thread_leak3.c =================================================================== --- test/tsan/thread_leak3.c +++ test/tsan/thread_leak3.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/thread_leak5.c =================================================================== --- test/tsan/thread_leak5.c +++ test/tsan/thread_leak5.c @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/thread_name.cc =================================================================== --- test/tsan/thread_name.cc +++ test/tsan/thread_name.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/thread_name2.cc =================================================================== --- test/tsan/thread_name2.cc +++ test/tsan/thread_name2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/tls_race.cc =================================================================== --- test/tsan/tls_race.cc +++ test/tsan/tls_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/tls_race2.cc =================================================================== --- test/tsan/tls_race2.cc +++ test/tsan/tls_race2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" Index: test/tsan/unaligned_race.cc =================================================================== --- test/tsan/unaligned_race.cc +++ test/tsan/unaligned_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/vptr_harmful_race.cc =================================================================== --- test/tsan/vptr_harmful_race.cc +++ test/tsan/vptr_harmful_race.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/vptr_harmful_race2.cc =================================================================== --- test/tsan/vptr_harmful_race2.cc +++ test/tsan/vptr_harmful_race2.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/vptr_harmful_race3.cc =================================================================== --- test/tsan/vptr_harmful_race3.cc +++ test/tsan/vptr_harmful_race3.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h" #include Index: test/tsan/write_in_reader_lock.cc =================================================================== --- test/tsan/write_in_reader_lock.cc +++ test/tsan/write_in_reader_lock.cc @@ -1,3 +1,4 @@ +// UNSUPPORTED: aarch64-linux-androideabi // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s #include "test.h"