summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/lsan/lsan_common.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/lsan to .cppNico Weber2019-08-011-904/+0
| | | | | | Like r367463, but for lsan. llvm-svn: 367561
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Revert "[lsan] Do not check for leaks in the forked process"Vitaly Buka2018-08-271-9/+0
| | | | | | | | Users need leak reports in forks. This reverts commit r334036. llvm-svn: 340758
* [lsan] Do not check for leaks in the forked processVitaly Buka2018-06-051-0/+9
| | | | | | | | | | | | | | | | Summary: If calling process had threads then forked process will fail to detect references from them. Fixes https://github.com/google/sanitizers/issues/836 Reviewers: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47751 llvm-svn: 334036
* [lsan] Report unsuspended threadsVitaly Buka2018-05-091-2/+28
| | | | | | | | | | | | | | | Summary: Leak checker needs to suspend all process threads. If we have some running thread in registry but not suspended we can have false leak report. So we will report this case here for future debugging. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D46663 llvm-svn: 331936
* [sanitizer] Cleanup sorting functionsVitaly Buka2018-05-091-1/+1
| | | | llvm-svn: 331915
* [sanitizer] Replace InternalScopedBuffer with InternalMmapVectorVitaly Buka2018-05-071-1/+1
| | | | llvm-svn: 331618
* [sanitizer] Remove reserving constructor from InternalMmapVectorVitaly Buka2018-05-071-3/+3
| | | | llvm-svn: 331617
* [sanitizer] Make InternalScopedBuffer::size() behavior similar to vector.Vitaly Buka2018-05-071-1/+2
| | | | llvm-svn: 331612
* [lsan] Remove semicolon after do {} while (0)Tom de Vries2017-11-131-2/+2
| | | | | | | | Remove semicolon after "do {} while (0)" in LOG_POINTERS and LOG_THREADS. Reviewed by: kcc llvm-svn: 318085
* [LSan] Detect dynamic loader by its base address.Alex Shlyapnikov2017-11-061-2/+3
| | | | | | | | | | | | | | | | | | | | | Summary: Relanding D38600, which was reverted due to various PPC bot failures. If it breaks something again, please provide some pointers to broken bots, not just revert it, otherwise it's very hard to reason what's wrong with this commit. Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by its base address, not by the module name matching. The current name matching approach fails on some configurations. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D39275 llvm-svn: 317512
* Revert "[LSan] Detect dynamic loader by its base address."Alex Shlyapnikov2017-10-051-3/+2
| | | | | | | | This reverts commit r315024. Breaks sysconf_interceptor_bypass_test.cc llvm-svn: 315031
* [LSan] Detect dynamic loader by its base address.Alex Shlyapnikov2017-10-051-2/+3
| | | | | | | | | | | | | | | | | | | | | | Summary: Relanding D33859, which was reverted because it has "broken LOTS of ARM/AArch64 bots for two days". If it breaks something again, please provide some pointers to broken bots, not just revert it, otherwise it's very hard to reason what's wrong with this commit. Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by its base address, not by the module name matching. The current name matching approach fails on some configurations. Reviewers: eugenis Subscribers: aemerson, kubamracek, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D38600 llvm-svn: 315024
* [lsan] Add __lsan_default_optionsVitaly Buka2017-09-221-0/+9
| | | | | | For consistency with asan, msan, tsan and ubsan. llvm-svn: 314048
* [asan/lsan] Make LSan compliant with recovery mode when running on top of ASanMaxim Ostapenko2017-09-221-0/+3
| | | | | | | | | | | Don't overwrite exit code in LSan when running on top of ASan in recovery mode to avoid breakage of users code due to found leaks. Patch by Slava Barinov. Differential Revision: https://reviews.llvm.org/D38026 llvm-svn: 313966
* [compiler-rt] Cleanup decoratorsVitaly Buka2017-09-111-3/+2
| | | | | | | | | | | | | | Summary: Removed redundant End*() methods which defined same way. Removed redundant Warning() methods. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, dberris Differential Revision: https://reviews.llvm.org/D37549 llvm-svn: 312950
* Don't call exit() from atexit handlers on DarwinFrancis Ricci2017-07-181-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Calling exit() from an atexit handler is undefined behavior. On Linux, it's unavoidable, since we cannot intercept exit (_exit isn't called if a user program uses return instead of exit()), and I haven't seen it cause issues regardless. However, on Darwin, I have a fairly complex internal test that hangs roughly once in every 300 runs after leak reporting finishes, which is resolved with this patch, and is presumably due to the undefined behavior (since the Die() is the only thing that happens after the end of leak reporting). In addition, this is the way TSan works as well, where an atexit handler+Die() is used on Linux, and an _exit() interceptor is used on Darwin. I'm not sure if it's intentionally structured that way in TSan, since TSan sets up the atexit handler and the _exit() interceptor on both platforms, but I have observed that on Darwin, only the _exit() interceptor is used, and on Linux the atexit handler is used. There is some additional related discussion here: https://reviews.llvm.org/D35085 Reviewers: alekseyshl, kubamracek Subscribers: eugenis, vsk, llvm-commits Differential Revision: https://reviews.llvm.org/D35513 llvm-svn: 308353
* Refactor MemoryMappingLayout::Next to use a single struct instead of output ↵Francis Ricci2017-07-111-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | parameters. NFC. Summary: This is the first in a series of patches to refactor sanitizer_procmaps to allow MachO section information to be exposed on darwin. In addition, grouping all segment information in a single struct is cleaner than passing it through a large set of output parameters, and avoids the need for annotations of NULL parameters for unneeded information. The filename string is optional and must be managed and supplied by the calling function. This is to allow the MemoryMappedSegment struct to be stored on the stack without causing overly large stack sizes. Reviewers: alekseyshl, kubamracek, glider Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D35135 llvm-svn: 307688
* Add an #if SANITIZER_MAC and a comment to lsan_common's suppression for ↵Kuba Mracek2017-07-101-3/+5
| | | | | | "_os_trace". llvm-svn: 307567
* [lsan] Add _os_trace into LSan's suppression listKuba Mracek2017-07-101-1/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D35173 llvm-svn: 307548
* Reverting an accidentally landed change.Kuba Mracek2017-07-101-1/+0
| | | | llvm-svn: 307539
* [tsan] Add support for running TSan tests on iOS simulator and devicesKuba Mracek2017-07-101-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D35157 llvm-svn: 307537
* Revert "[sanitizer-coverage] test for -fsanitize-coverage=inline-8bit-counters"Renato Golin2017-06-051-3/+0
| | | | | | | | | | | | | Revert "Mark sancov test as unsupported on Darwin" Revert "[LSan] Detect dynamic loader by its base address." This reverts commit r304633. This reverts commit r304673. This reverts commit r304632. Those commit have broken LOTS of ARM/AArch64 bots for two days. llvm-svn: 304699
* [LSan] Detect dynamic loader by its base address.Alex Shlyapnikov2017-06-031-0/+3
| | | | | | | | | | | | | | | Summary: Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by its base address, not by the module name matching. The current name matching approach fails on some configurations. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D33859 llvm-svn: 304633
* Fix typo in tls patchFrancis Ricci2017-05-251-1/+1
| | | | llvm-svn: 303906
* Implement tls scanning for darwin LSanFrancis Ricci2017-05-251-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 303887
* Revert "Implement tls scanning for darwin LSan"Francis Ricci2017-05-171-15/+13
| | | | | | This reverts r303262, due to TSan buildbot breakages. llvm-svn: 303266
* Implement tls scanning for darwin LSanFrancis Ricci2017-05-171-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 303262
* [lsan] When necessary, define LSan suppression for tls_get_addr.Alex Shlyapnikov2017-04-261-1/+1
| | | | | | | | | | | | | | | 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 llvm-svn: 301434
* [lsan] When necessary, define LSan suppression for pthread_exit.Alex Shlyapnikov2017-04-251-3/+3
| | | | | | | | | | | | | | | 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 llvm-svn: 301335
* Suppress DTLS leak happening in some glibc versions.Alex Shlyapnikov2017-04-211-3/+4
| | | | | | | | | | | | 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 llvm-svn: 301043
* Define standard suppressions for LSan, start with this one.Alex Shlyapnikov2017-04-201-6/+9
| | | | llvm-svn: 300887
* Define a suppression for known leaks on pthread_exit call.Alex Shlyapnikov2017-04-201-0/+6
| | | | | | | | | | | | Summary: Refer to D32194 for the context. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D32303 llvm-svn: 300886
* Fixup style from r300760Francis Ricci2017-04-191-3/+3
| | | | llvm-svn: 300765
* Make sure to scan mmap'd memory regions for root pointers on OS XFrancis Ricci2017-04-191-23/+24
| | | | | | | | | | | | | | | | | | | 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 llvm-svn: 300760
* Move valid caller-pc checks out of platform-specific checksFrancis Ricci2017-04-191-1/+69
| | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 300690
* Update suspended threads info to be compatible with darwinFrancis Ricci2017-04-171-2/+2
| | | | | | | | | | | | | | | 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 llvm-svn: 300491
* [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDsKuba Mracek2017-04-171-1/+1
| | | | | | | | 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 llvm-svn: 300473
* Implement global pointer scanning for darwin leak sanitizerFrancis Ricci2017-04-131-0/+17
| | | | | | | | | | Reviewers: kubamracek, kcc, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32012 llvm-svn: 300234
* [lsan] Avoid segfaults during threads destruction under high loadMaxim Ostapenko2017-04-061-6/+12
| | | | | | | | | | | | | | | | | 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 llvm-svn: 299630
* Use pthreads to manage thread-local storage on darwin for leak sanitizerFrancis Ricci2017-02-131-9/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: __thread is supported on Darwin, but is implemented dynamically via function calls to __tls_get_addr. This causes two issues when combined with leak sanitizer, due to malloc() interception. - The dynamic loader calls malloc during the process of loading the sanitizer dylib, while swapping a placeholder tlv_boostrap function for __tls_get_addr. This will cause tlv_bootstrap to be called in DisabledInThisThread() via the asan allocator. - The first time __tls_get_addr is called, it allocates memory for the thread-local object, during which it calls malloc(). This call will be intercepted, leading to an infinite loop in the asan allocator, in which the allocator calls DisabledInThisThread, which calls tls_get_addr, which calls into the allocator again. Reviewers: kcc, glider, kubamracek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29786 llvm-svn: 294994
* Provide default implementations for sanitizer interface functionsFrancis Ricci2017-01-071-0/+5
| | | | | | | | | | | | | | Summary: Adds a few default implementations for weak interface functions on platforms where weak hooks are not supported. Reviewers: eugenis, samsonov, timurrrr Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28201 llvm-svn: 291313
* [asan/lsan] Avoid possible deadlock in dynamic ASan runtime thread ↵Maxim Ostapenko2016-10-281-0/+1
| | | | | | | | | | | | | | | | | | | | initialization. There is possible deadlock in dynamic ASan runtime when we dlopen() shared lib which creates a thread at the global initialization stage. The scenario: 1) dlopen grabs a GI_pthread_mutex_lock in main thread. 2) main thread calls pthread_create, ASan intercepts it, calls real pthread_create and waits for the second thread to be "fully initialized". 3) Newly created thread tries to access a thread local disable_counter in LSan (to complete its "full initialization") and hangs in tls_get_addr_tail, because it also tries to acquire GI_pthread_mutex_lock. The issue is reproducible on relative recent Glibc versions e.g. 2.23. Differential Revision: https://reviews.llvm.org/D26028 llvm-svn: 285385
* Make lsan complain loudly when running under ptraceKostya Serebryany2016-10-131-0/+2
| | | | | | | | | | | | | | | | | | Summary: LeakSanitizer does not work with ptrace but currently it will print warnings (only under verbosity=1) and then proceed to print tons of false reports. This patch makes lsan fail hard under ptrace with a verbose message. https://github.com/google/sanitizers/issues/728 Reviewers: eugenis, vitalybuka, aizatsky Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D25538 llvm-svn: 284171
* [asan] Turn LSan-related #if’s into regular if’s in ASan initializerKuba Brecka2016-06-071-0/+7
| | | | | | | | Removing some preprocessor #if’s in favor of regular if’s. However, we need to declare empty stub functions to avoid linker errors. Differential Revision: http://reviews.llvm.org/D20911 llvm-svn: 272047
* [LSan] Print more helpful error message if LSan crashes during leak detection.Alexey Samsonov2016-02-121-0/+3
| | | | llvm-svn: 260717
* [LSan] Fix a crash when LSan hits a guard page while scanning thread stack ↵Alexey Samsonov2016-02-111-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | for pointers. Summary: In some cases stack pointer register (SP) doesn't point into the thread stack: e.g. if one is using swapcontext(). In this case LSan conservatively tries to scan the whole thread stack for pointers. However, thread stack (at least in glibc implementation) may also include guard pages, causing LSan to crash when it's reading from them. One of the solutions is to use a pthread_attr_getguardsize() to adjust the calculated stack boundaries. However, here we're just using IsAccessibleMemoryRange to skip guard pages and make the code (slightly) less platform-specific. Reviewers: kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D17116 llvm-svn: 260554
* [LSan] Ignore all allocations made inside pthread_create.Alexey Samsonov2016-01-161-6/+10
| | | | | | | | | | | | | Thread stack/TLS may be stored by libpthread for future reuse after thread destruction, and the linked list it's stored in doesn't even hold valid pointers to the objects, the latter are calculated by obscure pointer arithmetic. With this change applied, LSan test suite passes with "use_ld_allocations" flag defaulted to "false". It still requires more testing to check if the default can be switched. llvm-svn: 257975
* [LSan] Use __tls_get_addr interceptor to keep track of dynamic TLS.Alexey Samsonov2016-01-141-1/+14
| | | | | | | | | | | | | | | | | | | | Summary: We have a way to keep track of allocated DTLS segments: let's use it in LSan. Although this code is fragile and relies on glibc implementation details, in some cases it proves to be better than existing way of tracking DTLS in LSan: marking as "reachable" all memory chunks allocated directly by "ld". The plan is to eventually get rid of the latter, once we are sure it's safe to remove. Reviewers: kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16164 llvm-svn: 257785
* [compiler-rt] [asan] Use same shadow offset for aarch64Adhemerval Zanella2015-11-091-1/+3
| | | | | | | | This patch makes ASAN for aarch64 use the same shadow offset for all currently supported VMAs (39 and 42 bits). The shadow offset is the same for 39-bit (36). llvm-svn: 252497
OpenPOWER on IntegriCloud