summaryrefslogtreecommitdiff
path: root/lib/lsan/lsan_common.h
AgeCommit message (Collapse)Author
2017-11-15Fix some typos in a comment.Francis Ricci
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318336 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-22[lsan] Add __lsan_default_optionsVitaly Buka
For consistency with asan, msan, tsan and ubsan. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@314048 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-22[asan/lsan] Make LSan compliant with recovery mode when running on top of ASanMaxim Ostapenko
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313966 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-18Don't call exit() from atexit handlers on DarwinFrancis Ricci
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308353 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-11Refactor MemoryMappingLayout::Next to use a single struct instead of output ↵Francis Ricci
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307688 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-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-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-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-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-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-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-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-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-02-17Use pthreads to store current thread id on darwinFrancis Ricci
Summary: __thread is not supported by all darwin versions and architectures, use pthreads instead to allow for building darwin lsan on iossim. Reviewers: kubamracek, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29993 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295405 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-14Add cmake build support for lsan on OS XFrancis Ricci
Summary: Adds a new cmake flag 'COMPILER_RT_ENABLE_LSAN_OSX', which enables lsan compilation and is turned off by default. Patches to fix build errors when this flag is enabled will be uploaded soon. This is part of an effort to port LSan to OS X, but LSan on OS X does not currently work or pass tests currently. Reviewers: kubamracek, kcc, glider, alekseyshl Reviewed By: kubamracek Subscribers: danalbert, srhines, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D29783 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295012 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-13Use pthreads to manage thread-local storage on darwin for leak sanitizerFrancis Ricci
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294994 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-31[lsan] Renable LSan for x86 LinuxMaxim Ostapenko
The missed clang part was committed at https://reviews.llvm.org/rL293609 thus we can reenable LSan for x86 Linux. Differential Revision: https://reviews.llvm.org/D28609 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293610 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23Revert "[lsan] Enable LSan for x86 Linux."Evgeniy Stepanov
Breaks tests on i686/Linux due to missing clang driver support: error: unsupported option '-fsanitize=leak' for target 'i386-unknown-linux-gnu' git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@292844 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-23[lsan] Enable LSan for x86 Linux.Maxim Ostapenko
People keep asking LSan to be available on 32 bit targets (e.g. https://github.com/google/sanitizers/issues/403) despite the fact that false negative ratio might be huge (up to 85%). This happens for big real world applications that may contain random binary data (e.g. browser), but for smaller apps situation is not so terrible and LSan still might be useful. This patch adds initial support for x86 Linux (disabled by default), ARM32 is in TODO list. We used this patch (well, ported to GCC) on our 32 bit mobile emulators and it worked pretty fine thus I'm posting it here to initiate further discussion. Differential Revision: https://reviews.llvm.org/D28609 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@292775 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-16[LSan] Ignore all allocations made inside pthread_create.Alexey Samsonov
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257975 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-14[LSan] Use __tls_get_addr interceptor to keep track of dynamic TLS.Alexey Samsonov
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@257785 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-21[lsan] [aarch64] Add support for AArch64Adhemerval Zanella
This patch add support for leak sanitizer for aarch64. Similar to MIPS it uses a SizeClassAllocator32 due VMA constraints (aarch64 currently supports 39 and 42-bit VMA). It also fixes the android build issue. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@250898 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-08Revert "[lsan] [aarch64] Add support for AArch64"Evgeniy Stepanov
This reverts commit ea02fa45225c35613bfecab383fb526e24b74497 (r249337). Reason: broken "ninja AsanUnitTests" on Android/AArch64. http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/20675/steps/build%20compiler-rt%20android%2Faarch64/logs/stdio git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@249730 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-05[lsan] [aarch64] Add support for AArch64Adhemerval Zanella
This patch add support for leak sanitizer for aarch64. Similar to MIPS it uses a SizeClassAllocator32 due VMA constraints (aarch64 currently supports 39 and 42-bit VMA). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@249337 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-26LSan: fix a deadlock caused by dl_iterate_phdr().Sergey Matveev
Wrap the StopTheWorld call in a dl_iterate_phdr() callback. This ensures that no other threads are holding the libdl lock, and we can safely reenter it in the tracer thread. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230631 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-19[LSan] [MIPS] adding support of LSan for mips64/mips64el archMohit K. Bhakkad
Patch by Sagar Thakur Reviewers: petarj, earthdok, kcc. Subscribers: samsonov, dsanders, mohit.bhakkad, Anand.Takale, llvm-commits. Differential Revision: http://reviews.llvm.org/D7013 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@229830 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-17[LSan] Make parent tool responsible for initializing LSan flags.Alexey Samsonov
Summary: LSan can be combined with a parent tool (for now it's only ASan). Also, we allow LSAN_OPTIONS to override certain common flags. It means we have to parse LSAN_OPTIONS early enough, before the rest of the parent tool (including chunks of sanitizer_common) is initialized. In future, we can use the same approach for UBSan, after we embed it into ASan runtime in a similar way. Test Plan: regression test suite Reviewers: earthdok, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7577 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@229519 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-15[sanitizer] Flag parser rewrite.Evgeniy Stepanov
The new parser is a lot stricter about syntax, reports unrecognized flags, and will make it easier to implemented some of the planned features. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226169 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-07[Sanitizer] Change the runtime flag representation.Alexey Samsonov
This mirrors r225239 to all the rest sanitizers: ASan, DFSan, LSan, MSan, TSan, UBSan. Now the runtime flag type, name, default value and description is located in the single place in the .inc file. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225327 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-18[LSan] Parse common flags from LSAN_OPTIONS even if LSan is combined withAlexey Samsonov
another sanitizer. A user may run both LSan and LSan+ASan. It is weird to pass path to leak suppression file (or other common sanitizer flags, like "verbosity") in "LSAN_OPTIONS" in the first case and in "ASAN_OPTIONS" in the second case. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@215949 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-30[Sanitizer] Make "suppressions" and "print_suppressions" common runtime flags.Alexey Samsonov
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214343 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-21[lsan] disable lsan if wordsize is not 64Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209283 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-15[lsan] remove LeakSanitizerIsTurnedOffForTheCurrentProcess (this was a bad ↵Kostya Serebryany
idea), leave __lsan_is_turned_off git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@199304 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-10[lsan] handle 'new T[0]' where T is a type with DTOR; fixes ↵Kostya Serebryany
https://code.google.com/p/address-sanitizer/issues/detail?id=257 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@198932 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-10[lsan] rename __lsan_is_turned_off to ↵Kostya Serebryany
LeakSanitizerIsTurnedOffForTheCurrentProcess (leave the old variant for now for compatibility) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@198921 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-24[lsan] Refactor the LeakReport class.Sergey Matveev
Those methods were too damn bloated. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197978 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-24[lsan] Make the report_objects flag more useful.Sergey Matveev
Print the list of leaked objects after each leak report. Previously we printed only a joint list of all leaked objects. As a bonus, suppressed objects are no longer reported. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197977 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-17[lsan] Remove the LSan-specific verbosity flag.Sergey Matveev
It conflicted with the verbosity flag we had in common flags. We don't need an LSan-specific flag anyway. Also, shift some logging levels and remove some unnecessary code. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197512 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-17[lsan] Introduce print_suppressions flag.Sergey Matveev
Introduce a flag to either always or never print matched suppressions. Previously, matched suppressions were printed unconditionally if there were unsuppressed leaks. Also, verbosity=1 no longer has the semantics of "always print suppressions and summary". git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197510 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-17[lsan] Introduce __lsan_(un)register_root_region().Sergey Matveev
Add an interface for telling LSan that a region of memory is to be treated as a source of live pointers. Useful for code which stores pointers in mapped memory. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197489 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-09[lsan] Make LSan ignore memory poisoned by ASan.Sergey Matveev
Summary: No more (potenital) false negatives due to red zones or fake stack frames. Reviewers: kcc, samsonov Reviewed By: samsonov CC: llvm-commits, samsonov Differential Revision: http://llvm-reviews.chandlerc.com/D2359 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@196778 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-14[lsan] Support ASan's stack-use-after-return mode in LSan.Sergey Matveev
Treat the fake stack as live memory. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192593 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-13Define SANITIZER_INTERFACE_ATTRIBUTE on Windows and fix all the places where ↵Timur Iskhodzhanov
SANITIZER_INTERFACE_ATTRIBUTE or SANITIZER_ATTRIBUTE_WEAK are used git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@188261 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-08[lsan] Handle fork() correctly.Sergey Matveev
Update the main thread's os_id on every pthread_create, and before initiating leak checking. This ensures that we have the correct os_id even if we have forked after Init(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@185815 91177308-0d34-0410-b5e6-96231b3b80d8