Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -171,7 +171,7 @@ if(APPLE) set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${ARM64}) else() - set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64}) + set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32}) endif() set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64}) set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64} Index: lib/lsan/lsan_allocator.cc =================================================================== --- lib/lsan/lsan_allocator.cc +++ lib/lsan/lsan_allocator.cc @@ -37,8 +37,9 @@ u32 stack_trace_id; }; -#if defined(__mips64) || defined(__aarch64__) || defined(__i386__) -#if defined(__i386__) +#if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \ + defined(__arm__) +#if defined(__i386__) || defined(__arm__) static const uptr kMaxAllowedMallocSize = 1UL << 30; #else static const uptr kMaxAllowedMallocSize = 4UL << 30; Index: lib/lsan/lsan_common.h =================================================================== --- lib/lsan/lsan_common.h +++ lib/lsan/lsan_common.h @@ -34,7 +34,8 @@ && (SANITIZER_WORDSIZE == 64) && (defined(__x86_64__) \ || defined(__mips64) || defined(__aarch64__)) #define CAN_SANITIZE_LEAKS 1 -#elif SANITIZER_LINUX && !SANITIZER_ANDROID && defined(__i386__) +#elif SANITIZER_LINUX && !SANITIZER_ANDROID \ + && (defined(__i386__) || defined(__arm__)) #define CAN_SANITIZE_LEAKS 1 #else #define CAN_SANITIZE_LEAKS 0 @@ -141,13 +142,35 @@ ~ScopedInterceptorDisabler() { EnableInThisThread(); } }; +// According to Itanium C++ ABI array cookie is a one word containing +// size of allocated array. +static inline bool IsItaniumABICookie(uptr chunk_beg, uptr chunk_size, + uptr addr) { + return chunk_size == sizeof(uptr) && chunk_beg + chunk_size == addr && + *reinterpret_cast(chunk_beg) == 0; +} + +// According to ARM C++ ABI array cookie consists of two words: +// struct array_cookie { +// std::size_t element_size; // element_size != 0 +// std::size_t element_count; +// }; +static inline bool IsARMABICookie(uptr chunk_beg, uptr chunk_size, uptr addr) { + return chunk_size == 2 * sizeof(uptr) && chunk_beg + chunk_size == addr && + *reinterpret_cast(chunk_beg + sizeof(uptr)) == 0; +} + // Special case for "new T[0]" where T is a type with DTOR. -// new T[0] will allocate one word for the array size (0) and store a pointer -// to the end of allocated chunk. +// new T[0] will allocate a cookie (one or two words) for the array size (0) +// and store a pointer to the end of allocated chunk. The actual cookie layout +// varies between platforms according to their C++ ABI implementation. inline bool IsSpecialCaseOfOperatorNew0(uptr chunk_beg, uptr chunk_size, uptr addr) { - return chunk_size == sizeof(uptr) && chunk_beg + chunk_size == addr && - *reinterpret_cast(chunk_beg) == 0; +#if defined(__arm__) + return IsARMABICookie(chunk_beg, chunk_size, addr); +#else + return IsItaniumABICookie(chunk_beg, chunk_size, addr); +#endif } // The following must be implemented in the parent tool. Index: lib/sanitizer_common/sanitizer_linux.h =================================================================== --- lib/sanitizer_common/sanitizer_linux.h +++ lib/sanitizer_common/sanitizer_linux.h @@ -48,7 +48,8 @@ #endif void internal_sigdelset(__sanitizer_sigset_t *set, int signum); #if defined(__x86_64__) || defined(__mips__) || defined(__aarch64__) \ - || defined(__powerpc64__) || defined(__s390__) || defined(__i386__) + || defined(__powerpc64__) || defined(__s390__) || defined(__i386__) \ + || defined(__arm__) uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, int *parent_tidptr, void *newtls, int *child_tidptr); #endif Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -1240,6 +1240,67 @@ : "memory"); return res; } +#elif defined(__arm__) && SANITIZER_LINUX +uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg, + int *parent_tidptr, void *newtls, int *child_tidptr) { + unsigned int res; + if (!fn || !child_stack) + return -EINVAL; + CHECK_EQ(0, (uptr)child_stack % 16); + child_stack = (char *)child_stack - 2 * sizeof(unsigned int); + ((unsigned int *)child_stack)[0] = (uptr)fn; + ((unsigned int *)child_stack)[1] = (uptr)arg; + register int r0 __asm__("r0") = flags; + register void *r1 __asm__("r1") = child_stack; + register int *r2 __asm__("r2") = parent_tidptr; + register void *r3 __asm__("r3") = newtls; + register int *r4 __asm__("r4") = child_tidptr; + register int r7 __asm__("r7") = __NR_clone; + +#if __ARM_ARCH > 4 || defined (__ARM_ARCH_4T__) +# define ARCH_HAS_BX +#endif +#if __ARM_ARCH > 4 +# define ARCH_HAS_BLX +#endif + +#ifdef ARCH_HAS_BX +# ifdef ARCH_HAS_BLX +# define BLX(R) "blx " #R "\n" +# else +# define BLX(R) "mov lr, pc; bx" #R "\n" +# endif +#else +# define BLX(R) "mov lr, pc; mov pc," #R "\n" +#endif + + __asm__ __volatile__("push {r4, r7}\n" + + /* Do the system call */ + "swi 0x0\n" + + /* if (%r0 != 0) + * return %r0; + */ + "cmp r0, #0\n" + "bne 1f\n" + + /* In the child, now. Call "fn(arg)". */ + "ldr r0, [sp, #4]\n" + "ldr ip, [sp], #8\n" + BLX(ip) + /* Call _exit(%r0). */ + "mov r7, %7\n" + "swi 0x0\n" + "1:\n" + "pop {r4, r7}\n" + "mov %0, r0\n" + : "=r"(res) + : "r"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r7), + "i"(__NR_exit) + : "memory"); + return res; +} #endif // defined(__x86_64__) && SANITIZER_LINUX #if SANITIZER_ANDROID Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -183,8 +183,8 @@ #endif // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO #if (defined(__x86_64__) || defined(__i386__) || defined(__mips__) \ - || defined(__aarch64__) || defined(__powerpc64__) || defined(__s390__)) \ - && SANITIZER_LINUX && !SANITIZER_ANDROID + || defined(__aarch64__) || defined(__powerpc64__) || defined(__s390__) \ + || defined(__arm__)) && SANITIZER_LINUX && !SANITIZER_ANDROID // sizeof(struct pthread) from glibc. static atomic_uintptr_t kThreadDescriptorSize; @@ -192,14 +192,14 @@ uptr val = atomic_load(&kThreadDescriptorSize, memory_order_relaxed); if (val) return val; -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) #ifdef _CS_GNU_LIBC_VERSION char buf[64]; uptr len = confstr(_CS_GNU_LIBC_VERSION, buf, sizeof(buf)); if (len < sizeof(buf) && internal_strncmp(buf, "glibc 2.", 8) == 0) { char *end; int minor = internal_simple_strtoll(buf + 8, &end, 10); - if (end != buf + 8 && (*end == '\0' || *end == '.')) { + if (end != buf + 8 && (*end == '\0' || *end == '.' || *end == '-')) { int patch = 0; if (*end == '.') // strtoll will return 0 if no valid conversion could be performed @@ -208,6 +208,9 @@ /* sizeof(struct pthread) values from various glibc versions. */ if (SANITIZER_X32) val = 1728; // Assume only one particular version for x32. + // For ARM sizeof(struct pthread) changed in Glibc 2.23. + else if (SANITIZER_ARM) + val = minor <= 22 ? 1120 : 1216; else if (minor <= 3) val = FIRST_32_SECOND_64(1104, 1696); else if (minor == 4) @@ -293,7 +296,7 @@ rdhwr %0,$29;\ .set pop" : "=r" (thread_pointer)); descr_addr = thread_pointer - kTlsTcbOffset - TlsPreTcbSize(); -# elif defined(__aarch64__) +# elif defined(__aarch64__) || defined(__arm__) descr_addr = reinterpret_cast(__builtin_thread_pointer()) - ThreadDescriptorSize(); # elif defined(__s390__) @@ -342,7 +345,8 @@ *size = GetTlsSize(); *addr -= *size; *addr += ThreadDescriptorSize(); -# elif defined(__mips__) || defined(__aarch64__) || defined(__powerpc64__) +# elif defined(__mips__) || defined(__aarch64__) || defined(__powerpc64__) \ + || defined(__arm__) *addr = ThreadSelf(); *size = GetTlsSize(); # else Index: lib/sanitizer_common/sanitizer_platform.h =================================================================== --- lib/sanitizer_common/sanitizer_platform.h +++ lib/sanitizer_common/sanitizer_platform.h @@ -162,6 +162,12 @@ # define SANITIZER_PPC64V2 0 #endif +#if defined(__arm__) +# define SANITIZER_ARM 1 +#else +# define SANITIZER_ARM 0 +#endif + // By default we allow to use SizeClassAllocator64 on 64-bit platform. // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64 // does not work well and we need to fallback to SizeClassAllocator32. Index: lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc @@ -16,7 +16,8 @@ #if SANITIZER_LINUX && (defined(__x86_64__) || defined(__mips__) || \ defined(__aarch64__) || defined(__powerpc64__) || \ - defined(__s390__) || defined(__i386__)) + defined(__s390__) || defined(__i386__) || \ + defined(__arm__)) #include "sanitizer_stoptheworld.h" @@ -528,4 +529,4 @@ #endif // SANITIZER_LINUX && (defined(__x86_64__) || defined(__mips__) // || defined(__aarch64__) || defined(__powerpc64__) - // || defined(__s390__) || defined(__i386__) + // || defined(__s390__) || defined(__i386__) || defined(__arm__) Index: test/lsan/TestCases/cleanup_in_tsd_destructor.c =================================================================== --- test/lsan/TestCases/cleanup_in_tsd_destructor.c +++ test/lsan/TestCases/cleanup_in_tsd_destructor.c @@ -3,7 +3,7 @@ // user-installed TSD destructors have finished running (since they may contain // additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it // makes its best effort. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:report_objects=1:use_registers=0:use_stacks=0:use_globals=0" // RUN: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %run %t // RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/disabler.c =================================================================== --- test/lsan/TestCases/disabler.c +++ test/lsan/TestCases/disabler.c @@ -1,5 +1,5 @@ // Test for __lsan_disable() / __lsan_enable(). -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" // RUN: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/disabler.cc =================================================================== --- test/lsan/TestCases/disabler.cc +++ test/lsan/TestCases/disabler.cc @@ -1,5 +1,5 @@ // Test for ScopedDisabler. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/disabler_in_tsd_destructor.c =================================================================== --- test/lsan/TestCases/disabler_in_tsd_destructor.c +++ test/lsan/TestCases/disabler_in_tsd_destructor.c @@ -1,5 +1,5 @@ // Regression test. Disabler should not depend on TSD validity. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1:use_ld_allocations=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1:use_ld_allocations=0" // RUN: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t Index: test/lsan/TestCases/do_leak_check_override.cc =================================================================== --- test/lsan/TestCases/do_leak_check_override.cc +++ test/lsan/TestCases/do_leak_check_override.cc @@ -1,7 +1,7 @@ // Test for __lsan_do_leak_check(). We test it by making the leak check run // before global destructors, which also tests compatibility with HeapChecker's // "normal" mode (LSan runs in "strict" mode by default). -// RUN: LSAN_BASE="detect_leaks=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck --check-prefix=CHECK-strict %s // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck --check-prefix=CHECK-normal %s Index: test/lsan/TestCases/high_allocator_contention.cc =================================================================== --- test/lsan/TestCases/high_allocator_contention.cc +++ test/lsan/TestCases/high_allocator_contention.cc @@ -1,6 +1,6 @@ // A benchmark that executes malloc/free pairs in parallel. // Usage: ./a.out number_of_threads total_number_of_allocations -// RUN: LSAN_BASE="detect_leaks=1:use_ld_allocations=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_ld_allocations=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 5 1000000 2>&1 #include Index: test/lsan/TestCases/ignore_object.c =================================================================== --- test/lsan/TestCases/ignore_object.c +++ test/lsan/TestCases/ignore_object.c @@ -1,5 +1,5 @@ // Test for __lsan_ignore_object(). -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" // RUN: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/large_allocation_leak.cc =================================================================== --- test/lsan/TestCases/large_allocation_leak.cc +++ test/lsan/TestCases/large_allocation_leak.cc @@ -1,11 +1,11 @@ // Test that LargeMmapAllocator's chunks aren't reachable via some internal data structure. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s // 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 +// UNSUPPORTED: x86, arm #include #include Index: test/lsan/TestCases/leak_check_at_exit.cc =================================================================== --- test/lsan/TestCases/leak_check_at_exit.cc +++ test/lsan/TestCases/leak_check_at_exit.cc @@ -1,5 +1,5 @@ // Test for the leak_check_at_exit flag. -// RUN: LSAN_BASE="detect_leaks=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-do // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-do Index: test/lsan/TestCases/link_turned_off.cc =================================================================== --- test/lsan/TestCases/link_turned_off.cc +++ test/lsan/TestCases/link_turned_off.cc @@ -1,5 +1,5 @@ // Test for disabling LSan at link-time. -// RUN: LSAN_BASE="detect_leaks=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s Index: test/lsan/TestCases/pointer_to_self.cc =================================================================== --- test/lsan/TestCases/pointer_to_self.cc +++ test/lsan/TestCases/pointer_to_self.cc @@ -1,6 +1,6 @@ // Regression test: pointers to self should not confuse LSan into thinking the // object is indirectly leaked. Only external pointers count. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/print_suppressions.cc =================================================================== --- test/lsan/TestCases/print_suppressions.cc +++ test/lsan/TestCases/print_suppressions.cc @@ -1,6 +1,6 @@ // Print matched suppressions only if print_suppressions=1 AND at least one is // matched. Default is print_suppressions=true. -// RUN: LSAN_BASE="detect_leaks=1:use_registers=0:use_stacks=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_registers=0:use_stacks=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:print_suppressions=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont-print // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont-print Index: test/lsan/TestCases/recoverable_leak_check.cc =================================================================== --- test/lsan/TestCases/recoverable_leak_check.cc +++ test/lsan/TestCases/recoverable_leak_check.cc @@ -1,5 +1,5 @@ // Test for on-demand leak checking. -// RUN: LSAN_BASE="detect_leaks=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t foo 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/register_root_region.cc =================================================================== --- test/lsan/TestCases/register_root_region.cc +++ test/lsan/TestCases/register_root_region.cc @@ -1,5 +1,5 @@ // Test for __lsan_(un)register_root_region(). -// RUN: LSAN_BASE="detect_leaks=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s Index: test/lsan/TestCases/stale_stack_leak.cc =================================================================== --- test/lsan/TestCases/stale_stack_leak.cc +++ test/lsan/TestCases/stale_stack_leak.cc @@ -1,5 +1,5 @@ // Test that out-of-scope local variables are ignored by LSan. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0:use_stacks=1" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0:use_stacks=1" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE":exitcode=0" %run %t 2>&1 | FileCheck --check-prefix=CHECK-sanity %s Index: test/lsan/TestCases/suppressions_default.cc =================================================================== --- test/lsan/TestCases/suppressions_default.cc +++ test/lsan/TestCases/suppressions_default.cc @@ -1,4 +1,4 @@ -// RUN: LSAN_BASE="detect_leaks=1:use_registers=0:use_stacks=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_registers=0:use_stacks=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t 2>&1 | FileCheck %s Index: test/lsan/TestCases/suppressions_file.cc =================================================================== --- test/lsan/TestCases/suppressions_file.cc +++ test/lsan/TestCases/suppressions_file.cc @@ -1,4 +1,4 @@ -// RUN: LSAN_BASE="detect_leaks=1:use_registers=0:use_stacks=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:use_registers=0:use_stacks=0" // RUN: %clangxx_lsan %s -o %t // RUN: rm -f %t.supp Index: test/lsan/TestCases/swapcontext.cc =================================================================== --- test/lsan/TestCases/swapcontext.cc +++ test/lsan/TestCases/swapcontext.cc @@ -2,8 +2,10 @@ // memory. Make sure we don't report these leaks. // RUN: %clangxx_lsan %s -o %t -// RUN: %run %t 2>&1 -// RUN: not %run %t foo 2>&1 | FileCheck %s +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1" +// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 2>&1 +// RUN: LSAN_OPTIONS=$LSAN_BASE not %run %t foo 2>&1 | FileCheck %s +// UNSUPPORTED: arm #include #if defined(__APPLE__) @@ -23,7 +25,7 @@ } int main(int argc, char *argv[]) { - char stack_memory[kStackSize + 1]; + char stack_memory[kStackSize + 1] __attribute__((aligned(4))); char *heap_memory = new char[kStackSize + 1]; char *child_stack = (argc > 1) ? stack_memory : heap_memory; Index: test/lsan/TestCases/use_after_return.cc =================================================================== --- test/lsan/TestCases/use_after_return.cc +++ test/lsan/TestCases/use_after_return.cc @@ -1,6 +1,6 @@ // Test that fake stack (introduced by ASan's use-after-return mode) is included // in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0" // RUN: %clangxx_lsan %s -O2 -o %t // RUN: ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s // RUN: ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %run %t 2>&1 Index: test/lsan/TestCases/use_globals_initialized.cc =================================================================== --- test/lsan/TestCases/use_globals_initialized.cc +++ test/lsan/TestCases/use_globals_initialized.cc @@ -1,5 +1,5 @@ // Test that initialized globals are included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %run %t 2>&1 Index: test/lsan/TestCases/use_globals_uninitialized.cc =================================================================== --- test/lsan/TestCases/use_globals_uninitialized.cc +++ test/lsan/TestCases/use_globals_uninitialized.cc @@ -1,5 +1,5 @@ // Test that uninitialized globals are included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %run %t 2>&1 Index: test/lsan/TestCases/use_poisoned_asan.cc =================================================================== --- test/lsan/TestCases/use_poisoned_asan.cc +++ test/lsan/TestCases/use_poisoned_asan.cc @@ -1,6 +1,6 @@ // ASan-poisoned memory should be ignored if use_poisoned is false. // REQUIRES: asan -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_poisoned=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_poisoned=1" %run %t 2>&1 Index: test/lsan/TestCases/use_registers.cc =================================================================== --- test/lsan/TestCases/use_registers.cc +++ test/lsan/TestCases/use_registers.cc @@ -1,5 +1,5 @@ // Test that registers of running threads are included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0" // RUN: %clangxx_lsan -pthread %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_registers=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_registers=1" %run %t 2>&1 @@ -33,6 +33,11 @@ : : "r" (p) ); +#elif defined(__arm__) + asm ( "mov r5, %0" + : + : "r" (p) + ); #else #error "Test is not supported on this architecture." #endif Index: test/lsan/TestCases/use_stacks.cc =================================================================== --- test/lsan/TestCases/use_stacks.cc +++ test/lsan/TestCases/use_stacks.cc @@ -1,5 +1,5 @@ // Test that stack of main thread is included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %run %t 2>&1 Index: test/lsan/TestCases/use_stacks_threaded.cc =================================================================== --- test/lsan/TestCases/use_stacks_threaded.cc +++ test/lsan/TestCases/use_stacks_threaded.cc @@ -1,5 +1,5 @@ // Test that stacks of non-main threads are included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_registers=0" // RUN: %clangxx_lsan -pthread %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %run %t 2>&1 Index: test/lsan/TestCases/use_tls_dynamic.cc =================================================================== --- test/lsan/TestCases/use_tls_dynamic.cc +++ test/lsan/TestCases/use_tls_dynamic.cc @@ -1,10 +1,14 @@ // Test that dynamically allocated TLS space is included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0" // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %run %t 2>&1 // RUN: LSAN_OPTIONS="" %run %t 2>&1 +// +// On ARM slow unwinder might be unable to get allocation trace for dynamic TLS chunk, thus LSan +// would treat it as reachable. In this case we will miss a memory leak coming from dynamic TLS. +// UNSUPPORTED: arm #ifndef BUILD_DSO #include Index: test/lsan/TestCases/use_tls_pthread_specific_dynamic.cc =================================================================== --- test/lsan/TestCases/use_tls_pthread_specific_dynamic.cc +++ test/lsan/TestCases/use_tls_pthread_specific_dynamic.cc @@ -1,9 +1,13 @@ // Test that dynamically allocated thread-specific storage is included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %run %t 2>&1 // RUN: LSAN_OPTIONS="" %run %t 2>&1 +// +// On ARM slow unwinder might be unable to get allocation trace for dynamic TLS chunk, thus LSan +// would treat it as reachable. In this case we will miss a memory leak coming from dynamic TLS. +// UNSUPPORTED: arm #include #include Index: test/lsan/TestCases/use_tls_pthread_specific_static.cc =================================================================== --- test/lsan/TestCases/use_tls_pthread_specific_static.cc +++ test/lsan/TestCases/use_tls_pthread_specific_static.cc @@ -1,5 +1,5 @@ // Test that statically allocated thread-specific storage is included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %run %t 2>&1 Index: test/lsan/TestCases/use_tls_static.cc =================================================================== --- test/lsan/TestCases/use_tls_static.cc +++ test/lsan/TestCases/use_tls_static.cc @@ -1,5 +1,5 @@ // Test that statically allocated TLS space is included in the root set. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %run %t 2>&1 Index: test/lsan/TestCases/use_unaligned.cc =================================================================== --- test/lsan/TestCases/use_unaligned.cc +++ test/lsan/TestCases/use_unaligned.cc @@ -1,5 +1,5 @@ // Test that unaligned pointers are detected correctly. -// RUN: LSAN_BASE="detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="%env_lsan_extra_opts:detect_leaks=1:report_objects=1:use_stacks=0:use_registers=0" // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=0" not %run %t 2>&1 | FileCheck %s // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=1" %run %t 2>&1 Index: test/lsan/lit.common.cfg =================================================================== --- test/lsan/lit.common.cfg +++ test/lsan/lit.common.cfg @@ -34,6 +34,10 @@ if lit.util.which('strace'): config.available_features.add('strace') +is_arm = config.host_arch in ['arm', 'armhf'] +if is_arm: + lsan_cflags += ["-funwind-tables"] + clang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags clang_cxxflags = config.cxx_mode_flags + clang_cflags lsan_incdir = config.test_source_root + "/../" @@ -51,8 +55,14 @@ config.substitutions.append( ("%clang_lsan ", build_invocation(clang_lsan_cflags)) ) config.substitutions.append( ("%clangxx_lsan ", build_invocation(clang_lsan_cxxflags)) ) +lsan_target_opts = '' +if is_arm: + lsan_target_opts = "fast_unwind_on_malloc=false" + +config.substitutions.append(('%env_lsan_extra_opts', lsan_target_opts)) + # LeakSanitizer tests are currently supported on x86-64 Linux and mips64 Linux only. -if config.host_os not in ['Linux'] or config.host_arch not in ['x86_64', 'mips64']: +if config.host_os not in ['Linux'] or config.host_arch not in ['x86_64', 'mips64', 'arm', 'armhf']: config.unsupported = True config.suffixes = ['.c', '.cc', '.cpp'] Index: test/sanitizer_common/print_address.h =================================================================== --- test/sanitizer_common/print_address.h +++ test/sanitizer_common/print_address.h @@ -11,7 +11,7 @@ // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not // match to the format used in the diagnotic message. fprintf(stderr, "0x%012lx ", (unsigned long) p); -#elif defined(__i386__) +#elif defined(__i386__) || defined(__arm__) fprintf(stderr, "0x%8lx ", (unsigned long) p); #elif defined(__mips64) fprintf(stderr, "0x%010lx ", (unsigned long) p);