summaryrefslogtreecommitdiff
path: root/lib/lsan
AgeCommit message (Collapse)Author
2017-05-17Revert "Implement tls scanning for darwin LSan"Francis Ricci
This reverts r303262, due to TSan buildbot breakages. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303266 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-17Implement tls scanning for darwin LSanFrancis Ricci
Summary: This required for any users who call exit() after creating thread-specific data, as tls destructors are only called when pthread_exit() or pthread_cancel() are used. This should also match tls behavior on linux. Getting the base address of the tls section is straightforward, as it's stored as a section offset in %gs. The size is a bit trickier to work out, as there doesn't appear to be any official documentation or source code referring to it. The size used in this patch was determined by taking the difference between the base address and the address of the subsequent memory region returned by vm_region_recurse_64, which was 1024 * sizeof(uptr) on all threads except the main thread, where it was larger. Since the section must be the same size on all of the threads, 1024 * sizeof(uptr) seemed to be a reasonable size to use, barring a more programtic way to get the size. 1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX is 512 on darwin, so pthread keys will fit inside the region while leaving space for other tls data. A larger size would overflow the memory region returned by vm_region_recurse_64, and a smaller size wouldn't leave room for all the pthread keys. In addition, the stress test added here passes, which means that we are scanning at least the full set of possible pthread keys, and probably the full tls section. Reviewers: alekseyshl, kubamracek Subscribers: krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D33215 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303262 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-15[lsan] Report the missing linker only when the linker is actually missing.Alex Shlyapnikov
Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33218 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303129 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-15[sanitizer] Change SizeClassAllocator32 to accept just one templateKostya Kortchinsky
Summary: With rL279771, SizeClassAllocator64 was changed to accept only one template instead of 5, for the following reasons: "First, this will make the mangled names shorter. Second, this will make adding more parameters simpler". This patch mirrors that work for SizeClassAllocator32. This is in preparation for introducing the randomization of chunks in the 32-bit SizeClassAllocator in a later patch. Reviewers: kcc, alekseyshl, dvyukov Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D33141 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303071 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-09Avoid unnecessary calls to vm_region_recurseFrancis Ricci
Summary: This should significantly improve darwin lsan performance in cases where root regions are not used. Reviewers: alekseyshl, kubamracek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32966 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302530 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-03[sanitizer] Intercept mcheck and mprobe on LinuxMaxim Ostapenko
This patch addresses https://github.com/google/sanitizers/issues/804. Users can use mcheck and mprobe functions to verify heap state so we should intercept them to avoid breakage of valid code. Differential Revision: https://reviews.llvm.org/D32589 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302001 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-26[lsan] When necessary, define LSan suppression for tls_get_addr.Alex Shlyapnikov
Summary: Generalize already defined LSan suppression for the leak on tls_get_addr, some envs do not have the entire call stack symbolized, so we have to be less specific. Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32545 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301434 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-25[lsan] When necessary, define LSan suppression for pthread_exit.Alex Shlyapnikov
Summary: Generalize already defined LSan suppression for the leak on pthread_exit, some envs do not have the entire call stack symbolized, so we have to be less specific. Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32497 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301335 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21[lsan] Enable LSan on PowerPC64.Alex Shlyapnikov
Summary: Re-landing reverted D31995 with suppressions defined in D32303 and D32377. Reviewers: eugenis Subscribers: nemanjai, llvm-commits Differential Revision: https://reviews.llvm.org/D32379 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301048 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21Suppress DTLS leak happening in some glibc versions.Alex Shlyapnikov
Summary: Refer to https://sourceware.org/bugzilla/show_bug.cgi?id=12650 for the context. Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32377 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301043 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-21Disable LSan on ppc64, some tests are failing.Alex Shlyapnikov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300933 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20Enable LSan on PowerPC64.Alex Shlyapnikov
Summary: Re-landing reverted D31995 with suppressions defined in D32303. Reviewers: eugenis Subscribers: nemanjai, llvm-commits Differential Revision: https://reviews.llvm.org/D32314 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300903 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20Define standard suppressions for LSan, start with this one.Alex Shlyapnikov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300887 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-20Define a suppression for known leaks on pthread_exit call.Alex Shlyapnikov
Summary: Refer to D32194 for the context. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D32303 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300886 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-19Fixup style from r300760Francis Ricci
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300765 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-19Make sure to scan mmap'd memory regions for root pointers on OS XFrancis Ricci
Summary: In the general case, we only need to check for root regions inside the memory map returned by procmaps. However, on Darwin, we also need to check inside mmap'd regions, which aren't returned in the list of modules we get from procmaps. This patch refactors memory region scanning on darwin to reduce code duplication with the kernel alloc once page scan. Reviewers: kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32190 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300760 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-19Implement StopTheWorld for DarwinFrancis Ricci
Reviewers: kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32189 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300759 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-19Move valid caller-pc checks out of platform-specific checksFrancis Ricci
Summary: ProcessPlatformSpecificAllocations for linux leak sanitizer iterated over memory chunks and ran two checks concurrently: 1) Ensured the pc was valid 2) Checked whether it was a linker allocation All platforms will need the valid pc check, so it is moved out of the platform- specific file. To prevent code and logic duplication, the linker allocation check is moved as well, with the name of the linker supplied by the platform-specific module. In cases where we don't need to check for linker allocations (ie Darwin), this name will be a nullptr, and we'll only run the caller pc checks. Reviewers: kubamracek, alekseyshl, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32130 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300690 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17Update suspended threads info to be compatible with darwinFrancis Ricci
Summary: On Darwin, we need to track thread and tid as separate values. This patch splits out the implementation of the suspended threads list to be OS-specific. Reviewers: glider, kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31474 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300491 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDsKuba Mracek
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD). Differential Revision: https://reviews.llvm.org/D31774 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300473 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17Don't read non-readable address ranges during lsan pointer scanningFrancis Ricci
Summary: This specifically addresses the Mach-O zero page, which we cannot read from. Reviewers: kubamracek, samsonov, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32044 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300456 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17Scan Kernel Alloc Once page for global pointersFrancis Ricci
Summary: libxpc stashes some pointers here. Reviewers: kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32045 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300450 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Disable use of tls scanning on darwin leak sanitizerFrancis Ricci
Summary: These checks appear linux-specific, disable them on darwin, at least for now. Reviewers: kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32013 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300248 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Revert "Enable LSan on PowerPC64."Alex Shlyapnikov
This reverts commit r300204. Breaks ASAN tests on PPC. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300237 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Implement global pointer scanning for darwin leak sanitizerFrancis Ricci
Reviewers: kubamracek, kcc, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32012 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300234 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Don't assume PTHREAD_CREATE_JOINABLE is 0 on all systemsFrancis Ricci
Summary: Lsan was using PTHREAD_CREATE_JOINABLE/PTHREAD_CREATE_DETACHED as truthy values, which works on Linux, where the values are 0 and 1, but this fails on OS X, where the values are 1 and 2. Set PTHREAD_CREATE_DETACHED to the correct value for a given system. Reviewers: kcc, glider, kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31883 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300221 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Enable LSan on PowerPC64.Alex Shlyapnikov
Summary: With D31555 commited, looks like basic LSan functionality works on PPC64. Time to enable LSan there. Reviewers: eugenis Subscribers: nemanjai, llvm-commits Differential Revision: https://reviews.llvm.org/D31995 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300204 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11Implement standalone lsan interceptors for OS XFrancis Ricci
Summary: Mimicks the existing tsan and asan implementations of Darwin interception. Reviewers: kubamracek, kcc, glider Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D31889 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299979 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11Don't delete lsan thread-local data until it's no longer requiredFrancis Ricci
Summary: The routines for thread destruction in the thread registry require the lsan thread index, which is stored in pthread tls on OS X. This means that we need to make sure that the lsan tls isn't destroyed until after the thread registry tls. This change ensures that we don't delete the lsan tls until we've finished destroying the thread in the registry, ensuring that the destructor for the lsan tls runs after the destructor for the thread registry tls. This patch also adds a check to ensure that the thread ID is valid before returning it in GetThreadID(), to ensure that the above behavior is working correctly. Reviewers: dvyukov, kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31884 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299978 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11Reapply "Enable LSan for arm Linux"Maxim Ostapenko
This patch reapplies r299923 with typo fixed in BLX macros. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299948 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11Revert r299923, it doesn't build in bootstrap builds.Nico Weber
FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.arm.dir/sanitizer_linux.cc.o lib/sanitizer_common/sanitizer_linux.cc:1340:24: error: invalid instruction BLX(ip) ^ lib/sanitizer_common/sanitizer_linux.cc:1313:19: note: expanded from macro 'BLX' # define BLX(R) "mov lr, pc; bx" #R "\n" ^ <inline asm>:6:13: note: instantiated into assembly here mov lr, pc; bxip ^~~~ git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299943 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11[lsan] Enable LSan for arm LinuxMaxim Ostapenko
This patch enables LSan for arm Linux. Differential Revision: https://reviews.llvm.org/D29586 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299923 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-06Enable builds of darwin lsan by defaultFrancis Ricci
Summary: Testing and asan leak detection are disabled by default. Reviewers: kubamracek, kcc Subscribers: srhines, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D31307 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299669 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-06[lsan] Avoid segfaults during threads destruction under high loadMaxim Ostapenko
This patch addresses two issues: * It turned out that suspended thread may have dtls->dtv_size == kDestroyedThread (-1) and LSan wrongly assumes that DTV is available. This leads to SEGV when LSan tries to iterate through DTV that is invalid. * In some rare cases GetRegistersAndSP can fail with errno 3 (ESRCH). In this case LSan assumes that the whole stack of a given thread is available. This is wrong because ESRCH can indicate that suspended thread was destroyed and its stack was unmapped. This patch properly handles ESRCH from GetRegistersAndSP in order to avoid invalid accesses to already unpapped threads stack. Differential Revision: https://reviews.llvm.org/D30818 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299630 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-29Move current thread data out of lsan_common on linuxFrancis Ricci
Summary: Now that we have a platform-specific non-common lsan file, use it to store non-common lsan data. Reviewers: kubamracek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31472 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299032 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-29Remove failing check from platform specific darwin lsan initializerFrancis Ricci
Summary: We currently don't have any platform specific darwin lsan modules, don't force failure if they don't exist. Reviewers: kubamracek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31473 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299031 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-28Postpone lsan tls allocation until requiredFrancis Ricci
Summary: This prevents InternalAlloc from being called before the sanitizers are fully initialized. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31306 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298947 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-28Enable i386 builds for darwin lsanFrancis Ricci
Summary: Now that __thread is no longer used for lsan on darwin, i386 builds can be enabled. Reviewers: kcc, kubamracek Subscribers: danalbert, srhines, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D29995 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298946 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27Fix missing sanitizer platform includeFrancis Ricci
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298884 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27Fix comment in lsan_linux.ccFrancis Ricci
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298879 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27Move lsan allocator cache from lsan_common_linux to lsan_linuxFrancis Ricci
Having this function in common seems to trigger a lot of unrelated test failures. Given that this isn't really common code anyway, move this to a new linux-specific lsan file. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298878 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27Use pthreads for thread-local lsan allocator cache on darwinFrancis Ricci
Summary: This patch allows us to move away from using __thread on darwin, which is requiring for building lsan for darwin on ios version 7 and on iossim i386. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31291 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298848 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-22Factor lsan allocator cache accesses into a functionFrancis Ricci
Summary: This patch is the first step towards allows us to move away from using __thread for the allocator cache on darwin, which is requiring for building lsan for darwin on ios version 7 and on iossim i386. This will be followed by patches to move the function into OS-specific files. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29994 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298537 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21Revert r298274: "Use pthreads for thread-local lsan allocator cache on darwin"Chandler Carruth
This fixes a failure currently present on the upstream linux boxes (and reproduces for me as well): http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1130/steps/64-bit%20check-asan-dynamic/logs/stdio git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298382 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-20Use pthreads for thread-local lsan allocator cache on darwinFrancis Ricci
Summary: This patch allows us to move away from using __thread on darwin, which is requiring for building lsan for darwin on ios version 7 and on iossim i386. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29994 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298274 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-20Revert "Use pthreads for thread-local lsan allocator cache on darwin"Francis Ricci
This is still failing stack-use-after-return on linux-aarch64. This reverts commit 5b350130fc4bf6f70c078a5d97096df98a17a057. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298246 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-19Use pthreads for thread-local lsan allocator cache on darwinFrancis Ricci
Summary: This patch allows us to move away from using __thread on darwin, which is requiring for building lsan for darwin on ios version 7 and on iossim i386. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29994 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298214 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-02Revert "Use pthreads for thread-local lsan allocator cache on darwin"Francis Ricci
Reverting due to revert of prerequisite patch r296706 This reverts commit 6e1f23078c1acc44295065d28167043c4d31ddd1. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@296720 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-01Use pthreads for thread-local lsan allocator cache on darwinFrancis Ricci
Summary: This patch allows us to move away from using __thread on darwin, which is requiring for building lsan for darwin on ios version 7 and on iossim i386. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29994 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@296707 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-17Revert "Use pthreads for thread-local lsan allocator cache on darwin"Francis Ricci
This caused a failure in Linux-x86_64 stack-use-after-return This reverts commit 1f9563141e999016d13ac3fc6a50fde690381e82. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295449 91177308-0d34-0410-b5e6-96231b3b80d8