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 @@ -21,6 +21,19 @@ #include "sanitizer_common/sanitizer_stoptheworld.h" #include "sanitizer_common/sanitizer_symbolizer.h" +// LeakSanitizer on Android requires at least ELF TLS supports(API 29) to +// *compile* and thread-properties API (API 31) to actually work. But there is +// no release branch for Android-S yet, so we cannot set this limit to be 31 +// here because it will prevent testing/running the code with local/master +// builds. This is fine for now because we have additional runtime check to +// ensure the API needed is present. +// FIXME: Change this to 31 once the branch is available. +#if SANITIZER_ANDROID && __ANDROID_API__ > 28 +#define CAN_SANITIZE_LEAKS_ANDROID 1 +#else +#define CAN_SANITIZE_LEAKS_ANDROID 0 +#endif + // LeakSanitizer relies on some Glibc's internals (e.g. TLS machinery) on Linux. // Also, LSan doesn't like 32 bit architectures // because of "small" (4 bytes) pointer size that leads to high false negative @@ -29,13 +42,15 @@ // 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_MAC) && (SANITIZER_WORDSIZE == 64) && \ +#if (SANITIZER_LINUX || SANITIZER_MAC || CAN_SANITIZE_LEAKS_ANDROID) && \ + (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_MAC) +#elif defined(__i386__) && \ + (SANITIZER_LINUX || SANITIZER_MAC || CAN_SANITIZE_LEAKS_ANDROID) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__arm__) && SANITIZER_LINUX +#elif defined(__arm__) && (SANITIZER_LINUX || CAN_SANITIZE_LEAKS_ANDROID) #define CAN_SANITIZE_LEAKS 1 #elif SANITIZER_NETBSD || SANITIZER_FUCHSIA #define CAN_SANITIZE_LEAKS 1