diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -164,7 +164,7 @@ set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers) file(WRITE ${DUMMY_VERS} "{};") set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}") -if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) +if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT AND NOT ANDROID) # Solaris 11.4 ld only supports --version-script with # -z gnu-version-script-compat. string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}") @@ -292,9 +292,9 @@ set(X86_64 x86_64 x86_64h) endif() -set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64} +set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH i686 ${X86} ${X86_64} ${PPC64} ${RISCV64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} +set(ALL_ASAN_SUPPORTED_ARCH i686 ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9}) set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) @@ -319,7 +319,7 @@ if(APPLE) set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64}) else() - set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32} ${PPC64} ${S390X}) + set(ALL_LSAN_SUPPORTED_ARCH i686 ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32} ${PPC64} ${S390X}) endif() set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}) set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64}) @@ -681,7 +681,7 @@ endif() if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND - OS_NAME MATCHES "Darwin|Linux|NetBSD|Fuchsia") + OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|Fuchsia") set(COMPILER_RT_HAS_LSAN TRUE) else() set(COMPILER_RT_HAS_LSAN FALSE) diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -86,6 +86,8 @@ set(ASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) if(ANDROID) + list(APPEND ASAN_CFLAGS -fno-emulated-tls) + list(APPEND ASAN_DYNAMIC_LINK_FLAGS -fuse-ld=lld) # Put most Sanitizer shared libraries in the global group. For more details, see # android-changes-for-ndk-developers.md#changes-to-library-search-order if (COMPILER_RT_HAS_Z_GLOBAL) @@ -231,8 +233,8 @@ set(VERSION_SCRIPT_FLAG -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers) # The Solaris 11.4 linker supports a subset of GNU ld version scripts, - # but requires a special option to enable it. - if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + # but requires a special option to enable it. Flag not used/compatible with ANDROID. + if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT AND NOT ANDROID) list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat) endif() set_property(SOURCE diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -91,6 +91,7 @@ endif() if(ANDROID) list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -pie) + list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -fuse-ld=lld) endif() set(ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS @@ -288,6 +289,7 @@ $ $ $ + $ $ $ ${COMPILER_RT_GTEST_SOURCE} diff --git a/compiler-rt/lib/lsan/CMakeLists.txt b/compiler-rt/lib/lsan/CMakeLists.txt --- a/compiler-rt/lib/lsan/CMakeLists.txt +++ b/compiler-rt/lib/lsan/CMakeLists.txt @@ -33,6 +33,10 @@ set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +if(ANDROID) + list(APPEND LSAN_CFLAGS -fno-emulated-tls) +endif() + add_compiler_rt_object_libraries(RTLSanCommon OS ${SANITIZER_COMMON_SUPPORTED_OS} ARCHS ${LSAN_COMMON_SUPPORTED_ARCH} diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -29,16 +29,13 @@ // To enable LeakSanitizer on a new architecture, one needs to implement the // internal_clone function as well as (probably) adjust the TLS machinery for // the new architecture inside the sanitizer library. -#if (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) && \ - (SANITIZER_WORDSIZE == 64) && \ +#if (SANITIZER_LINUX || SANITIZER_MAC) && (SANITIZER_WORDSIZE == 64) && \ (defined(__x86_64__) || defined(__mips64) || defined(__aarch64__) || \ defined(__powerpc64__) || defined(__s390x__)) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__i386__) && \ - (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) +#elif defined(__i386__) && (SANITIZER_LINUX || SANITIZER_MAC) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__arm__) && \ - SANITIZER_LINUX && !SANITIZER_ANDROID +#elif defined(__arm__) && SANITIZER_LINUX #define CAN_SANITIZE_LEAKS 1 #elif SANITIZER_NETBSD || SANITIZER_FUCHSIA #define CAN_SANITIZE_LEAKS 1 diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -71,17 +71,23 @@ static const char *kSuppressionTypes[] = { kSuppressionLeak }; static const char kStdSuppressions[] = #if SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT - // For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT - // definition. - "leak:*pthread_exit*\n" + // For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT + // definition. + "leak:*pthread_exit*\n" #endif // SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT #if SANITIZER_MAC - // For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173 - "leak:*_os_trace*\n" + // For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173 + "leak:*_os_trace*\n" #endif - // TLS leak in some glibc versions, described in - // https://sourceware.org/bugzilla/show_bug.cgi?id=12650. - "leak:*tls_get_addr*\n"; +#if SANITIZER_ANDROID + // Known leaks from bionic and libc++. + "leak:*std::__ndk1::*\n" + "leak:*__libc_preinit_impl*\n" + "leak:std::*::ios_base\n" +#endif + // TLS leak in some glibc versions, described in + // https://sourceware.org/bugzilla/show_bug.cgi?id=12650. + "leak:*tls_get_addr*\n"; void InitializeSuppressions() { CHECK_EQ(nullptr, suppression_ctx); @@ -294,6 +300,22 @@ kReachable); } } +#if SANITIZER_ANDROID + if (HAS_ANDROID_THREAD_PROPERTIES_API) { + auto *cb = +[](void *dtls_begin, void *dtls_end, uptr /*dso_idd*/, + void *arg) -> void { + ScanRangeForPointers(reinterpret_cast(dtls_begin), + reinterpret_cast(dtls_end), + reinterpret_cast(arg), "DTLS", + kReachable); + }; + + // FIXME: There might be a race-condition here (and in Bionic) if the + // thread is suspended in the middle of updating its DTLS. IOWs, we + // could scan already freed memory. (probably fine for now) + __libc_iterate_dynamic_tls(os_id, cb, frontier); + } +#else if (dtls && !DTLSInDestruction(dtls)) { for (uptr j = 0; j < dtls->dtv_size; ++j) { uptr dtls_beg = dtls->dtv[j].beg; @@ -309,6 +331,7 @@ // this and continue. LOG_THREADS("Thread %d has DTLS under destruction.\n", os_id); } +#endif } } } @@ -575,8 +598,16 @@ } static bool CheckForLeaks() { +#if SANITIZER_ANDROID + // Presence of the ThreadProperties API implies the presence of + // TLS support, which is required for calling __lsan_is_turned_off(). + // Therefore, this check must preceed that. + if (!HAS_ANDROID_THREAD_PROPERTIES_API) + return false; +#endif + if (&__lsan_is_turned_off && __lsan_is_turned_off()) - return false; + return false; EnsureMainThreadIDIsCorrect(); CheckForLeaksParam param; LockStuffAndStopTheWorld(CheckForLeaksCallback, ¶m); diff --git a/compiler-rt/lib/lsan/lsan_common_linux.cpp b/compiler-rt/lib/lsan/lsan_common_linux.cpp --- a/compiler-rt/lib/lsan/lsan_common_linux.cpp +++ b/compiler-rt/lib/lsan/lsan_common_linux.cpp @@ -41,9 +41,28 @@ __attribute__((tls_model("initial-exec"))) THREADLOCAL int disable_counter; -bool DisabledInThisThread() { return disable_counter > 0; } -void DisableInThisThread() { disable_counter++; } +bool DisabledInThisThread() { +#if SANITIZER_ANDROID + // LSAN is only enabled with Android-S and up. + if (!HAS_ANDROID_THREAD_PROPERTIES_API) + return true; +#endif + return disable_counter > 0; +} +void DisableInThisThread() { +#if SANITIZER_ANDROID + // LSAN is only enabled with Android-S and up. + if (!HAS_ANDROID_THREAD_PROPERTIES_API) + return; +#endif + disable_counter++; +} void EnableInThisThread() { +#if SANITIZER_ANDROID + // LSAN is only enabled with Android-S and up. + if (!HAS_ANDROID_THREAD_PROPERTIES_API) + return; +#endif if (disable_counter == 0) { DisableCounterUnderflow(); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h @@ -154,6 +154,16 @@ return reinterpret_cast(&__get_tls()[TLS_SLOT_SANITIZER]); } +// Bionic provides this API since 31. +extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_get_static_tls_bounds(void **, + void **); +extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls( + pid_t, void (*cb)(void *, void *, uptr, void *), void *); + +#define HAS_ANDROID_THREAD_PROPERTIES_API (&__libc_iterate_dynamic_tls != 0) + +#else +#define HAS_ANDROID_THREAD_PROPERTIES_API (0) #endif // SANITIZER_ANDROID } // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -427,7 +427,19 @@ #if !SANITIZER_GO static void GetTls(uptr *addr, uptr *size) { -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_ANDROID + if (HAS_ANDROID_THREAD_PROPERTIES_API) { + void *start_addr; + void *end_addr; + __libc_get_static_tls_bounds(&start_addr, &end_addr); + *addr = reinterpret_cast(start_addr); + *size = + reinterpret_cast(end_addr) - reinterpret_cast(start_addr); + } else { + *addr = 0; + *size = 0; + } +#elif SANITIZER_LINUX && !SANITIZER_ANDROID # if defined(__x86_64__) || defined(__i386__) || defined(__s390__) *addr = ThreadSelf(); *size = GetTlsSize(); @@ -471,9 +483,6 @@ #elif SANITIZER_OPENBSD *addr = 0; *size = 0; -#elif SANITIZER_ANDROID - *addr = 0; - *size = 0; #elif SANITIZER_SOLARIS // FIXME *addr = 0; diff --git a/compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp b/compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp --- a/compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp +++ b/compiler-rt/test/asan/TestCases/coverage-and-lsan.cpp @@ -9,7 +9,8 @@ // RUN: %sancov print %t-dir/*.sancov 2>&1 // // REQUIRES: leak-detection - +// FIXME: sancov paths not work with adb +// UNSUPPORTED: android int *g = new int; int main(int argc, char **argv) { g = 0; diff --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py --- a/compiler-rt/test/asan/lit.cfg.py +++ b/compiler-rt/test/asan/lit.cfg.py @@ -209,7 +209,7 @@ config.available_features.add('fast-unwinder-works') # Turn on leak detection on 64-bit Linux. -leak_detection_linux = (config.host_os == 'Linux') and (not config.android) and (config.target_arch == 'x86_64' or config.target_arch == 'i386') +leak_detection_linux = (config.host_os == 'Linux') and (not config.android or 'android-31' in config.available_features) and (config.target_arch == 'x86_64' or config.target_arch == 'i386' or config.target_arch == 'i686' or config.target_arch == 'aarch64' ) leak_detection_mac = (config.host_os == 'Darwin') and (config.target_arch == 'x86_64') leak_detection_netbsd = (config.host_os == 'NetBSD') and (config.target_arch in ['x86_64', 'i386']) if leak_detection_linux or leak_detection_mac or leak_detection_netbsd: @@ -249,6 +249,10 @@ if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'SunOS', 'Windows', 'NetBSD']: config.unsupported = True +# Only run the tests on Android, if required API level is present. +if config.android and 'android-31' not in config.available_features: + config.unsupported = True + if not config.parallelism_group: config.parallelism_group = 'shadow-memory' diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -61,6 +61,11 @@ # BFD linker in 64-bit android toolchains fails to find libc++_shared.so, which # is a transitive shared library dependency (via asan runtime). if config.android: + # device_rundir and push_to_device are needed for tests to upload temp + # files, such as suppression-files, to device. + config.substitutions.append( ('%device_rundir', "/data/local/tmp/Output") ) + # FIXME: May need to select specific device with `-s SERIAL` + config.substitutions.append( ('%push_to_device', "adb push ") ) # Prepend the flag so that it can be overridden. config.target_cflags = "-pie -fuse-ld=gold " + config.target_cflags if config.android_ndk_version < 19: @@ -69,7 +74,9 @@ # just contains a handful of ABI functions", which makes most C++ code fail # to link. In r19 and later we just use the default which is libc++. config.cxx_mode_flags.append('-stdlib=libstdc++') - +else: + config.substitutions.append( ('%device_rundir', "") ) + config.substitutions.append( ('%push_to_device', "echo ") ) config.environment = dict(os.environ) # Clear some environment variables that might affect Clang. @@ -341,7 +348,11 @@ if config.android_serial: env['ANDROID_SERIAL'] = config.android_serial config.environment['ANDROID_SERIAL'] = config.android_serial - + # Must use lld because Bionic's TLS layout is not compatible with the Gold convention. + # The buildbot script will guarantee lld is built/included. + # The check for `has_lld` somehow missed that it exists and always marked tests as "unsupported". + config.use_lld = True + config.has_lld = True adb = os.environ.get('ADB', 'adb') try: android_api_level_str = subprocess.check_output([adb, "shell", "getprop", "ro.build.version.sdk"], env=env).rstrip() @@ -355,6 +366,8 @@ config.available_features.add('android-26') if android_api_level >= 28: config.available_features.add('android-28') + if android_api_level >= 30: + config.available_features.add('android-31') # Prepare the device. android_tmpdir = '/data/local/tmp/Output' diff --git a/compiler-rt/test/lsan/TestCases/Linux/guard-page.c b/compiler-rt/test/lsan/TestCases/Linux/guard-page.c --- a/compiler-rt/test/lsan/TestCases/Linux/guard-page.c +++ b/compiler-rt/test/lsan/TestCases/Linux/guard-page.c @@ -1,6 +1,9 @@ // Check that if LSan finds that SP doesn't point into thread stack (e.g. // if swapcontext is used), LSan will not hit the guard page. // RUN: %clang_lsan %s -o %t && %run %t +// Missing 'getcontext' and 'makecontext' on Android. +// UNSUPPORTED: android + #include #include #include diff --git a/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp b/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp --- a/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp +++ b/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp @@ -9,6 +9,8 @@ // RUN: rm -f %t.log.* // RUN: %env_lsan_opts="use_stacks=0:log_path='"%t.log"'" not %run %t > %t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.* +// Log path don't work properly on Android +// UNSUPPORTED: android #include #include diff --git a/compiler-rt/test/lsan/TestCases/Linux/use_tls_dynamic.cpp b/compiler-rt/test/lsan/TestCases/Linux/use_tls_dynamic.cpp --- a/compiler-rt/test/lsan/TestCases/Linux/use_tls_dynamic.cpp +++ b/compiler-rt/test/lsan/TestCases/Linux/use_tls_dynamic.cpp @@ -1,8 +1,9 @@ // Test that dynamically allocated TLS space is included in the root set. // This is known to be broken with glibc-2.27+ +// but it should pass with Bionic // https://bugs.llvm.org/show_bug.cgi?id=37804 -// XFAIL: glibc-2.27 +// XFAIL: !android // RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0" // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so @@ -10,7 +11,7 @@ // RUN: %env_lsan_opts=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s // RUN: %env_lsan_opts=$LSAN_BASE:"use_tls=1" %run %t 2>&1 // RUN: %env_lsan_opts="" %run %t 2>&1 -// UNSUPPORTED: i386-linux,arm,powerpc +// UNSUPPORTED: arm,powerpc #ifndef BUILD_DSO #include diff --git a/compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_static.cpp b/compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_static.cpp --- a/compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_static.cpp +++ b/compiler-rt/test/lsan/TestCases/Linux/use_tls_pthread_specific_static.cpp @@ -19,7 +19,10 @@ int res; res = pthread_key_create(&key, NULL); assert(res == 0); +#if !defined(__ANDROID__) && !defined(__BIONIC__) + // Bionic doesn't have specific limit. assert(key < PTHREAD_KEY_2NDLEVEL_SIZE); +#endif void *p = malloc(1337); res = pthread_setspecific(key, p); assert(res == 0); diff --git a/compiler-rt/test/lsan/TestCases/large_allocation_leak.cpp b/compiler-rt/test/lsan/TestCases/large_allocation_leak.cpp --- a/compiler-rt/test/lsan/TestCases/large_allocation_leak.cpp +++ b/compiler-rt/test/lsan/TestCases/large_allocation_leak.cpp @@ -5,7 +5,7 @@ // For 32 bit LSan it's pretty likely that large chunks are "reachable" from some // internal data structures (e.g. Glibc global data). -// UNSUPPORTED: x86, arm +// UNSUPPORTED: x86, arm, i686 #include #include diff --git a/compiler-rt/test/lsan/TestCases/strace_test.cpp b/compiler-rt/test/lsan/TestCases/strace_test.cpp --- a/compiler-rt/test/lsan/TestCases/strace_test.cpp +++ b/compiler-rt/test/lsan/TestCases/strace_test.cpp @@ -2,6 +2,9 @@ // REQUIRES: strace // RUN: %clangxx_lsan %s -o %t // RUN: not strace -o /dev/null %run %t 2>&1 | FileCheck %s +// FIXME: This technically works in practice but cannot be tested because the +// fatal-error caused adb to failed. Could not be captured to stderr to lit-check. +// XFAIL: android #include #include diff --git a/compiler-rt/test/lsan/TestCases/suppressions_file.cpp b/compiler-rt/test/lsan/TestCases/suppressions_file.cpp --- a/compiler-rt/test/lsan/TestCases/suppressions_file.cpp +++ b/compiler-rt/test/lsan/TestCases/suppressions_file.cpp @@ -3,13 +3,16 @@ // RUN: rm -f %t.supp // RUN: touch %t.supp -// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%t.supp'" not %run %t 2>&1 | FileCheck %s --check-prefix=NOSUPP +// RUN: %push_to_device %t.supp %device_rundir/%t.supp +// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp'" not %run %t 2>&1 | FileCheck %s --check-prefix=NOSUPP // RUN: echo "leak:*LSanTestLeakingFunc*" > %t.supp -// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%t.supp'" not %run %t 2>&1 | FileCheck %s - +// RUN: %push_to_device %t.supp %device_rundir/%t.supp +// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp'" not %run %t 2>&1 | FileCheck %s +// // RUN: echo "leak:%t" > %t.supp -// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%t.supp':symbolize=false" %run %t +// RUN: %push_to_device %t.supp %device_rundir/%t.supp +// RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp':symbolize=false" %run %t #include #include diff --git a/compiler-rt/test/lsan/TestCases/swapcontext.cpp b/compiler-rt/test/lsan/TestCases/swapcontext.cpp --- a/compiler-rt/test/lsan/TestCases/swapcontext.cpp +++ b/compiler-rt/test/lsan/TestCases/swapcontext.cpp @@ -4,7 +4,8 @@ // RUN: %clangxx_lsan %s -o %t // RUN: %env_lsan_opts= %run %t 2>&1 // RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s -// UNSUPPORTED: arm,powerpc64 +// Missing 'getcontext' and 'makecontext' on Android. +// UNSUPPORTED: arm,powerpc64,android #include "sanitizer_common/sanitizer_ucontext.h" #include diff --git a/compiler-rt/test/lsan/TestCases/use_registers.cpp b/compiler-rt/test/lsan/TestCases/use_registers.cpp --- a/compiler-rt/test/lsan/TestCases/use_registers.cpp +++ b/compiler-rt/test/lsan/TestCases/use_registers.cpp @@ -21,11 +21,10 @@ // To store the pointer, choose a register which is unlikely to be reused by // a function call. -#if defined(__i386__) - asm ( "mov %0, %%esi" +#if defined(__i386__) || defined(__i686__) + asm("mov %0, %%edi" : - : "r" (p) - ); + : "r"(p)); #elif defined(__x86_64__) asm ( "mov %0, %%r15" : @@ -41,6 +40,12 @@ : : "r" (p) ); +#elif defined(__aarch64__) + // x9-10are used. x11-12 are probably used. + // So we pick x13 to be safe. + asm("mov x13, %0" + : + : "r"(p)); #elif defined(__powerpc__) asm ( "mr 30, %0" : diff --git a/compiler-rt/test/lsan/lit.common.cfg.py b/compiler-rt/test/lsan/lit.common.cfg.py --- a/compiler-rt/test/lsan/lit.common.cfg.py +++ b/compiler-rt/test/lsan/lit.common.cfg.py @@ -21,6 +21,10 @@ # Choose between standalone and LSan+ASan modes. lsan_lit_test_mode = get_required_attr(config, 'lsan_lit_test_mode') +# Standalone LSAN segfaults on android, for some reason. So just use lsan+asan +if config.android: + lsan_lit_test_mode = "AddressSanitizer" + if lsan_lit_test_mode == "Standalone": config.name = "LeakSanitizer-Standalone" lsan_cflags = ["-fsanitize=leak"] @@ -35,7 +39,8 @@ config.name += config.name_suffix # Platform-specific default LSAN_OPTIONS for lit tests. -default_lsan_opts = 'detect_leaks=1' +default_common_opts_str = ':'.join(list(config.default_sanitizer_opts)) +default_lsan_opts = default_common_opts_str + ':detect_leaks=1' 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'. @@ -76,6 +81,10 @@ if not (supported_linux or supported_darwin or supported_netbsd): config.unsupported = True +# Only run the tests on Android, if required API level is present. +if config.android and 'android-31' not in config.available_features: + config.unsupported = True + # Don't support Thumb due to broken fast unwinder if re.search('mthumb', config.target_cflags) is not None: config.unsupported = True