Commit Graph

60 Commits

Author SHA1 Message Date
Vitaly Buka 1b73bde182 [lsan] Add __lsan_default_options
For consistency with asan, msan, tsan and ubsan.

llvm-svn: 314048
2017-09-22 23:49:49 +00:00
Francis Ricci f36d34a4d4 Revert "Prevent DCE on __lsan_is_turned_off and re-enable test case"
This doesn't fix the failing test. Leave in the comment and the
attribute, since the used attribute is still required.

This partially reverts commit r312824

llvm-svn: 312827
2017-09-08 21:09:43 +00:00
Francis Ricci 4a327e1c5c Prevent DCE on __lsan_is_turned_off and re-enable test case
Summary:
-dead_strip in ld64 strips weak interface symbols, which I believe
is most likely the cause of this test failure. Re-enable after marking the interface
function as used.

Reviewers: alekseyshl, kubamracek, kcc

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D37635

llvm-svn: 312824
2017-09-08 19:43:53 +00:00
Michal Gorny 0e52de05db Reland r311842 - [cmake] Remove i686 target that is duplicate to i386
Remove the explicit i686 target that is completely duplicate to
the i386 target, with the latter being used more commonly.

1. The runtime built for i686 will be identical to the one built for
i386.

2. Supporting both -i386 and -i686 suffixes causes unnecessary confusion
on the clang end which has to expect either of them.

3. The checks are based on wrong assumption that __i686__ is defined for
all newer x86 CPUs. In fact, it is only declared when -march=i686 is
explicitly used. It is not available when a more specific (or newer)
-march is used.

Curious enough, if CFLAGS contain -march=i686, the runtime will be built
both for i386 and i686. For any other value, only i386 variant will be
built.

Differential Revision: https://reviews.llvm.org/D26764

llvm-svn: 311924
2017-08-28 20:30:12 +00:00
Michal Gorny 7298595a2c Revert r311842 - [cmake] Remove i686 target that is duplicate to i386
The required change in clang is being reverted because of the Android
build bot failure.

llvm-svn: 311859
2017-08-27 20:37:06 +00:00
Michal Gorny 34ca7168ae [cmake] Remove i686 target that is duplicate to i386
Remove the explicit i686 target that is completely duplicate to
the i386 target, with the latter being used more commonly.

1. The runtime built for i686 will be identical to the one built for
i386.

2. Supporting both -i386 and -i686 suffixes causes unnecessary confusion
on the clang end which has to expect either of them.

3. The checks are based on wrong assumption that __i686__ is defined for
all newer x86 CPUs. In fact, it is only declared when -march=i686 is
explicitly used. It is not available when a more specific (or newer)
-march is used.

Curious enough, if CFLAGS contain -march=i686, the runtime will be built
both for i386 and i686. For any other value, only i386 variant will be
built.

Differential Revision: https://reviews.llvm.org/D26764

llvm-svn: 311842
2017-08-27 07:44:41 +00:00
Alex Shlyapnikov d08c32b2f4 [Sanitizers] LSan allocator set errno on failure.
Set proper errno code on alloction failures and change valloc and
memalign implementations to satisfy their man-specified requirements.

llvm-svn: 308063
2017-07-14 22:23:46 +00:00
Alex Shlyapnikov d3213c792e [LSan] Make LSan allocator allocator_may_return_null compliant
Summary:
An attempt to reland D34786 (which caused bot failres on Mac), now with
properly intercepted operators new() and delete().

LSan allocator used to always return nullptr on too big allocation requests
(the definition of "too big" depends on platform and bitness), now it
follows policy configured by allocator_may_return_null flag

Reviewers: eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D34845

llvm-svn: 306845
2017-06-30 17:21:34 +00:00
Michael Zolotukhin 1576571112 Revert "[LSan] Make LSan allocator allocator_may_return_null compliant"
This reverts commit r306624.

The committed test failed on various bots (e.g. on green dragon).

llvm-svn: 306644
2017-06-29 04:39:17 +00:00
Alex Shlyapnikov 17277f13f0 [LSan] Make LSan allocator allocator_may_return_null compliant
Summary:
LSan allocator used to always return nullptr on too big allocation requests
(the definition of "too big" depends on platform and bitness), now it
follows policy configured by allocator_may_return_null flag.

Reviewers: eugenis

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D34786

llvm-svn: 306624
2017-06-29 01:02:40 +00:00
Francis Ricci 42175cb0d7 Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Re-commit of r305695 with use_stacks=0 to get around a racy lingering pointer.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D34247

llvm-svn: 305732
2017-06-19 19:21:31 +00:00
Francis Ricci 214b354f2e Revert "Add lsan interceptors for libdispatch functions on darwin"
This reverts r305695

llvm-svn: 305712
2017-06-19 17:08:55 +00:00
Francis Ricci 4f1e047a6d Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D34247

llvm-svn: 305695
2017-06-19 14:09:10 +00:00
Renato Golin 5ade1f1c86 [LSAN-ARM] Marking new test unsupported on ARMHF due to bot failures
The test was meant for Darwin anyway, so I'm not even sure it's supposed
to run on Linux. If it was, then we need time to investigate, but since
the test is new, there's no point in reverting the whole patch because
of it.

llvm-svn: 304010
2017-05-26 17:31:33 +00:00
Francis Ricci 86e070f7e9 Implement tls scanning for darwin LSan
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
2017-05-25 17:41:13 +00:00
Francis Ricci 3b57da0c73 Revert "Implement tls scanning for darwin LSan"
This reverts r303262, due to TSan buildbot breakages.

llvm-svn: 303266
2017-05-17 15:25:41 +00:00
Francis Ricci eab89eb850 Implement tls scanning for darwin LSan
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
2017-05-17 14:35:17 +00:00
Francis Ricci fb3d1ea063 Disable two failing darwin lsan tests
These tests don't fail consistently in all cases, but they
fail most of the time on the buildbots. Mark as UNSUPPORTED for now to
avoid buildbots failing due to XPASS.

llvm-svn: 302920
2017-05-12 16:52:19 +00:00
Francis Ricci b680e9742a Disable two failing darwin lsan tests
These are causing buildbot failures, disable for now.

llvm-svn: 302912
2017-05-12 16:01:15 +00:00
Francis Ricci 6b494d9edc make detect_leaks=1 the default for the lsan test suite
Summary:
This already appears to be the case in all .cc test files,
it was probably left out of the .c test files accidentally. Make it a global
default, instead of manually adding it to each individual test.

This is needed to force leak detection for Darwin tests, where leak detection
is disabled by default.

Reviewers: m.ostapenko, kubamracek, alekseyshl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D32297

llvm-svn: 300890
2017-04-20 21:00:02 +00:00
Francis Ricci cae98fc8f0 Allow for setting of global platform-specific lsan options in the test suite
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D32131

llvm-svn: 300592
2017-04-18 20:56:56 +00:00
Francis Ricci 5bfddfefe1 Move Linux-specific lsan tests into a new directory
Summary:
These tests aren't supported on other platforms, move them
to their own directory.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D32034

llvm-svn: 300247
2017-04-13 20:13:53 +00:00
Maxim Ostapenko de3b9a2ecc Reapply "Enable LSan for arm Linux"
This patch reapplies r299923 with typo fixed in BLX macros.

llvm-svn: 299948
2017-04-11 14:58:26 +00:00
Nico Weber 7124b5f6f9 Revert r299923, it doesn't build in bootstrap builds.
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
            ^~~~

llvm-svn: 299943
2017-04-11 14:28:49 +00:00
Maxim Ostapenko 950d2809d5 [lsan] Enable LSan for arm Linux
This patch enables LSan for arm Linux.

Differential Revision: https://reviews.llvm.org/D29586

llvm-svn: 299923
2017-04-11 08:13:38 +00:00
Francis Ricci 0add37927c Disable use_tls_dynamic on 32-bit linux
Summary:
This test fails with a false negative due to an unrelated change.
Since we expect a number of false negatives on 32-bit lsan,
disable this test on linux-i386 and linux-i686.

Reviewers: kubamracek, m.ostapenko, kcc

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D31300

llvm-svn: 298847
2017-03-27 14:06:49 +00:00
Michal Gorny 123515561f [test] Enable the strace_test only if strace is installed
Differential Revision: https://reviews.llvm.org/D29628

llvm-svn: 294425
2017-02-08 08:43:44 +00:00
Maxim Ostapenko 7d8f1deafc [lsan] Fix typo in stale_stack_leak.cc testcase
llvm-svn: 293644
2017-01-31 16:32:58 +00:00
Maxim Ostapenko dbaacc7566 [lsan] Disable stale_stack_leak.cc testcase on x86
llvm-svn: 293621
2017-01-31 12:59:04 +00:00
Maxim Ostapenko 651cfe3cfa [lsan] Renable LSan for x86 Linux
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

llvm-svn: 293610
2017-01-31 07:15:37 +00:00
Evgeniy Stepanov 0f550c8176 Revert "[lsan] Enable LSan for x86 Linux."
Breaks tests on i686/Linux due to missing clang driver support:
  error: unsupported option '-fsanitize=leak' for target 'i386-unknown-linux-gnu'

llvm-svn: 292844
2017-01-23 22:52:31 +00:00
Maxim Ostapenko 2523faf677 [lsan] Enable LSan for x86 Linux.
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

llvm-svn: 292775
2017-01-23 08:45:17 +00:00
Strahinja Petrovic f10d114d43 [lsan] [aarch64] Fix printing of pointers in make check tests - update
This patch replaces fprintf with print_address function in LSAN
tests. This is necessary because of different printing of pointers
in fprintf and sanitizer's print function. 
Differential Revision: https://reviews.llvm.org/D26084.

llvm-svn: 286816
2016-11-14 11:40:56 +00:00
Strahinja Petrovic 19610a33c1 [lsan] [aarch64] Fix printing of pointers in make check tests
This patch replaces fprintf with print_address function
in LSAN tests. This is necessary because of different 
printing of pointers in fprintf and sanitizer's print 
function. Differential Revision: https://reviews.llvm.org/D25270.

llvm-svn: 284722
2016-10-20 12:25:57 +00:00
Kostya Serebryany 8633900e03 Make lsan complain loudly when running under ptrace
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
2016-10-13 22:34:13 +00:00
Kostya Serebryany 3a46def40c [lsan] one more test fix to please the Debian Sid bot (this time, confirmed on the proper machine). Apparently, newer glibc uses slightly more stack
llvm-svn: 279768
2016-08-25 19:08:10 +00:00
Kostya Serebryany db0fcdb03b [lsan] give a test a bit more stack -- it started failing after r279664 on the debian bot, hopefully this is a fix.
llvm-svn: 279674
2016-08-24 22:10:35 +00:00
Mohit K. Bhakkad 2a4985c929 [LSan] Enable use_registers test for MIPS
Reviewers: samsonov

Subscribers: jaydeep, sagar, llvm-commits

Differential Revision: http://reviews.llvm.org/D17797

llvm-svn: 262581
2016-03-03 05:05:20 +00:00
Alexey Samsonov 669e87c1f1 [LSan] Test case fix: mode debug output, synchronization instead of sleep().
llvm-svn: 260564
2016-02-11 19:03:09 +00:00
Alexey Samsonov 027729c566 [LSan] Fix a crash when LSan hits a guard page while scanning thread stack 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
2016-02-11 18:07:17 +00:00
Alexey Samsonov 95cd990588 [LSan] Ignore all allocations made inside pthread_create.
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
2016-01-16 00:57:25 +00:00
Alexey Samsonov 1f242d6a77 [LSan] Add "use_ld_allocations" flag to disable old way of DTLS handling.
This flag allows to disable old way of determining dynamic TLS by
filtering out allocations from dynamic linker. This will be eventually
superseded by __tls_get_addr interceptor (see r257785), after we:
1) Test it in several supported environments
2) Deal with existing problems (currently we can't find a pointer to
  DTV which is calloc()-ed in pthread_create).

llvm-svn: 257789
2016-01-14 19:16:05 +00:00
Alexey Samsonov 89d7ff5de6 [LSan] Fix tests with some libstdc++ implementations.
Summary:
Newer libstdc++ has global pool, which is filled with objects
allocated during libstdc++ initialization, and never released.
Using use_globals=0 in the lit tests results in these objects
being treated as leaks.

Fix this by porting several tests to plain C, and introducing
a simple sanity test case for __lsan::ScopedDisabler.

Reviewers: kcc, ygribov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D14798

llvm-svn: 253576
2015-11-19 17:18:02 +00:00
Alexey Samsonov e6c614d48a [Sanitizer] Teach ReadFileToBuffer to distinguish empty file from inaccessible file.
Summary:
This fixes https://code.google.com/p/address-sanitizer/issues/detail?id=399
(sanitizers crash with empty suppression files).

Reviewers: kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D11284

llvm-svn: 242594
2015-07-17 23:50:08 +00:00
Sergey Matveev cbdd0dc88a [lsan] Add an interface function for on-demand leak checking.
Summary:
Add an interface function which can be used to periodically trigger
leak detection in a long-running process.

NB: The meaning of the kIgnored tag has been changed to allow easy clean-up
between subsequent leak checks. Previously, this tag was applied to explicitly
ignored (i.e. with __lsan_disable() or __lsan_ignore_object()) chunks *and* any
chunks only reachable from those. With this change, it's only applied to
explicitly ignored chunks.

Reviewers: samsonov

Reviewed By: samsonov

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9159

llvm-svn: 235728
2015-04-24 16:53:15 +00:00
Evgeniy Stepanov f294d5b829 [sanitizer] Flag parser rewrite.
The new parser is a lot stricter about syntax, reports unrecognized
flags, and will make it easier to implemented some of the planned features.

llvm-svn: 226169
2015-01-15 15:13:43 +00:00
Evgeniy Stepanov 1a1a7d0f30 [lsan] Fix a typo in a test.
llvm-svn: 226168
2015-01-15 15:00:49 +00:00
Sergey Matveev 5010b262aa [lsan] Add debug output to leak_check_before_thread_started.cc.
Trying to investigate why this test is flaky.

llvm-svn: 224580
2014-12-19 15:33:13 +00:00
Filipe Cabecinhas 9fd326d4d6 Fix suppressions file usage
Summary:
Always quote suppressions files given to *_OPTIONS.
This will make it not break when given full Windows paths (otherwise,
parsing would stop after the drive's letter + ':').

Also fix one or two cases where the suppression files' extensions were
not *.supp.

Reviewers: samsonov, kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6680

llvm-svn: 224529
2014-12-18 18:25:18 +00:00
Sergey Matveev 5a03a9919f [LSan] Rewrite the test from r223419 to not use C++11.
This was causing build failures on llvm-clang-lld-x86_64-centos-6.5 for some
reason. Anyway, the new way is better because we no longer rely on std::thread
implementation details.

llvm-svn: 223480
2014-12-05 17:21:43 +00:00