Commit Graph

11497 Commits

Author SHA1 Message Date
Julian Lettner 764c2165e8 [TSan][libdispatch] Enable linking and running of tests on Linux
When COMPILER_RT_INTERCEPT_LIBDISPATCH is ON the TSan runtime library
now has a dependency on the blocks runtime and libdispatch. Make sure we
set all the required linking options.

Also add cmake options for specifying additional library paths to
instruct the linker where to search for libdispatch and the blocks
runtime. This allows us to build TSan runtime with libdispatch support
without installing those libraries into default linker library paths.

`CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY` is necessary to avoid
aborting the build due to failing the link step in CMake's
check_c_compiler test.

Reviewed By: dvyukov, kubamracek

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

llvm-svn: 356281
2019-03-15 17:52:27 +00:00
Jonas Hahnfeld 77eccf24d5 [msan] Fix BMI2 detection in msan tests, take 2.
It's not enough if only one bit is present, we need to check that
both are set. This finally fixes the test failures for me.

llvm-svn: 356242
2019-03-15 10:15:13 +00:00
Julian Lettner 4d4f64cddd [NFC][TSan] Move libdispatch tests into their own subfolder
Remove 'gcd' file prefix. GCD stands for Grand Central Dispatch, which
is another name for libdispatch.
https://apple.github.io/swift-corelibs-libdispatch/

Remove `REQUIRE: dispatch` from tests.

Also rename lit feature 'dispatch' -> 'libdispatch' to be more explicit
what this is about.

Reviewed By: kubamracek

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

llvm-svn: 356202
2019-03-14 20:59:41 +00:00
Julian Lettner e0e02444bc [TSan][libdispatch] Remove dependency on system headers
Including <dispatch/dispatch.h> and <Blocks.h> transitively pulls in
other system headers. Let's try to avoid that.

Blocks.h: compiler-rt already includes a blocks runtime. Just use the
header file that comes with it.

dispatch.h: Declare the bare minimum required for our implementation,
i.e., everything needed to define the interceptors, but not the
interceptors themselves. See tsan_dispatch_defs.h. I spotted a few other
places in compile-rt, where we declare libdispatch types. Maybe this
file can be moved to sanitizer_common if we deem it useful enough.

tsan_libdispatch.cc now compiles on Linux/Clang (requires support for
-fblocks). Linking still requires some manual configuration.

Reviewed By: kubamracek

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

llvm-svn: 356201
2019-03-14 20:59:37 +00:00
Mitch Phillips 621de86907 [HWASan] Use less Printf() calls in register dump.
Summary:
Explicitly print 4 registers/line in each iteration during register
dump. Reduces logcat spam as we get a single logcat message per call to
Printf(), even if the output isn't newline-terminated. This brings the
output format in logcat closer to that of the normal textual dump.

Reviewers: eugenis, pcc

Reviewed By: pcc

Subscribers: kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 356166
2019-03-14 17:05:53 +00:00
Vitaly Buka 9df0754b8d AddressSanitizer: 64-bit SPARC/Linux port
Summary:
This patch contains the bits required to make the AddressSanitizer work on SPARC64/Linux (SPARC-T4 and later).

Patch by Eric Botcazou.

Reviewers: #sanitizers, vitalybuka, krytarowski

Reviewed By: #sanitizers, vitalybuka

Subscribers: brad, vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

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

llvm-svn: 355980
2019-03-12 21:02:24 +00:00
Vitaly Buka 5ae9f865b2 AddressSanitizer: fix for SPARC with GCC
Summary:
This patch contains a fixlet for the AddressSanitizer on the SPARC with GCC, which would otherwise generate a problematic call to the intercepted memcpy routine.  It was tested with GCC on SPARC/Solaris and SPARC/Linux.

Patch by Eric Botcazou.

Reviewers: #sanitizers, vitalybuka

Reviewed By: #sanitizers, vitalybuka

Subscribers: vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

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

llvm-svn: 355979
2019-03-12 21:02:15 +00:00
Vitaly Buka d3ed66dfb3 SanitizerCommon: 64-bit SPARC/Linux port
Summary:
This patch contains the bits required to make the common 32-bit allocator work on SPARC64/Linux.

Patch by Eric Botcazou.

Reviewers: #sanitizers, vitalybuka

Reviewed By: #sanitizers, vitalybuka

Subscribers: krytarowski, vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

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

llvm-svn: 355978
2019-03-12 21:02:04 +00:00
Vitaly Buka 2a3de8f437 SanitizerCommon: fixes for unwinding & backtrace on SPARC
Summary:
This patch contains various fixes for the unwinding and backtrace machinery on the SPARC, which doesn't work correctly in various cases.  It was tested with GCC on SPARC/Solaris and SPARC/Linux.

Patch by Eric Botcazou.

Reviewers: #sanitizers, vitalybuka

Reviewed By: #sanitizers, vitalybuka

Subscribers: jrtc27, delcypher, vitalybuka, ro, jyknight, kubamracek, fedor.sergeev, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

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

llvm-svn: 355965
2019-03-12 20:31:53 +00:00
Kostya Kortchinsky 1f066a717c [scudo][standalone] Implement checksumming functions
Summary:
This CL implements the checksumming functions. This departs from the
current Scudo code in one aspect: the software version is no longer
CRC32 but a BSD checksum. This is because the software CRC32 was too
impactful in terms of performances, the BSD checksum has no array
lookup which is better (and saves 1KB of data).

As with the current version, we only flip the CRC compiler flag for
a single compilation unit by default, to allow for a library compiled
with HW CRC32 to work on a system without HW CRC32.

There is some platform & hardware specific code in those files, but
since departs from a mere platform split, it felt right to me to have
it that way.

Reviewers: morehouse, eugenis, vitalybuka, hctim, mcgrathr

Reviewed By: morehouse

Subscribers: mgorny, delcypher, jfb, jdoerfert, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 355923
2019-03-12 14:46:31 +00:00
Evgeniy Stepanov 17ee3b4b74 [msan] Fix BMI2 detection in msan tests.
llvm-svn: 355885
2019-03-12 00:19:09 +00:00
Evgeniy Stepanov aedec3f684 Remove ASan asm instrumentation.
Summary: It is incomplete and has no users AFAIK.

Reviewers: pcc, vitalybuka

Subscribers: srhines, kubamracek, mgorny, krytarowski, eraman, hiraditya, jdoerfert, #sanitizers, llvm-commits, thakis

Tags: #sanitizers, #llvm

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

llvm-svn: 355870
2019-03-11 21:50:10 +00:00
Nico Weber 885b790f89 Remove esan.
It hasn't seen active development in years, and it hasn't reached a
state where it was useful.

Remove the code until someone is interested in working on it again.

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

llvm-svn: 355862
2019-03-11 20:23:40 +00:00
Mitch Phillips 85bbf57bf9 [HWASan] Remove address significance from tag_mismatch.
Actually fix the issue referenced in rL355840.

llvm-svn: 355844
2019-03-11 17:34:17 +00:00
Mitch Phillips 5ccb339107 [HWASan] Fixed minor AArch64/GCC build error.
Fixed buildbot clang-cmake-aarch64-lld by ensuring clang-only features
are guarded by clang-only #defines.

llvm-svn: 355840
2019-03-11 17:06:39 +00:00
Mitch Phillips 790edbc16e [HWASan] Save + print registers when tag mismatch occurs in AArch64.
Summary:
This change change the instrumentation to allow users to view the registers at the point at which tag mismatch occured. Most of the heavy lifting is done in the runtime library, where we save the registers to the stack and emit unwind information. This allows us to reduce the overhead, as very little additional work needs to be done in each __hwasan_check instance.

In this implementation, the fast path of __hwasan_check is unmodified. There are an additional 4 instructions (16B) emitted in the slow path in every __hwasan_check instance. This may increase binary size somewhat, but as most of the work is done in the runtime library, it's manageable.

The failure trace now contains a list of registers at the point of which the failure occured, in a format similar to that of Android's tombstones. It currently has the following format:

Registers where the failure occurred (pc 0x0055555561b4):
    x0  0000000000000014  x1  0000007ffffff6c0  x2  1100007ffffff6d0  x3  12000056ffffe025
    x4  0000007fff800000  x5  0000000000000014  x6  0000007fff800000  x7  0000000000000001
    x8  12000056ffffe020  x9  0200007700000000  x10 0200007700000000  x11 0000000000000000
    x12 0000007fffffdde0  x13 0000000000000000  x14 02b65b01f7a97490  x15 0000000000000000
    x16 0000007fb77376b8  x17 0000000000000012  x18 0000007fb7ed6000  x19 0000005555556078
    x20 0000007ffffff768  x21 0000007ffffff778  x22 0000000000000001  x23 0000000000000000
    x24 0000000000000000  x25 0000000000000000  x26 0000000000000000  x27 0000000000000000
    x28 0000000000000000  x29 0000007ffffff6f0  x30 00000055555561b4

... and prints after the dump of memory tags around the buggy address.

Every register is saved exactly as it was at the point where the tag mismatch occurs, with the exception of x16/x17. These registers are used in the tag mismatch calculation as scratch registers during __hwasan_check, and cannot be saved without affecting the fast path. As these registers are designated as scratch registers for linking, there should be no important information in them that could aid in debugging.

Reviewers: pcc, eugenis

Reviewed By: pcc, eugenis

Subscribers: srhines, kubamracek, mgorny, javed.absar, krytarowski, kristof.beyls, hiraditya, jdoerfert, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

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

llvm-svn: 355738
2019-03-08 21:22:35 +00:00
Hubert Tong 57b38a8593 [msan] Properly guard tests added by r355348; NFC
r355348 uses builtins without proper guards, breaking the test on
various platforms.

llvm-svn: 355718
2019-03-08 19:57:27 +00:00
Julian Lettner 9e18875ba3 [TSan] Initialize libdispatch interceptors if necessary
On Linux (and other non-Darwin platforms) we need to initialize
interceptors. Since tsan_libdispatch.cc is compiled optionally, add a
weak default implementation of `InitializeLibdispatchInterceptors`.

Reviewed By: dvyukov

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

llvm-svn: 355717
2019-03-08 19:52:45 +00:00
Manman Ren e73ae9a142 Reland compiler-rt support for order file instrumentation.
r355343 was landed and was reverted in r355363 due to build breakage.
This patch adds Linux/Windows support on top of r355343.

In this patch, Darwin should be working with testing case. Linux should be working,
I will enable the testing case in a follwup diff. Windows/Other should be building.
Correct implementation for Other platforms will be added.

Thanks David for reviewing the original diff, helping me with issues on Linux, and
giving suggestions for adding support for Other platforms.

llvm-svn: 355701
2019-03-08 15:30:56 +00:00
Clement Courbet a3c43cfd63 [sanitizer] Update global_symbols.txt
Add `bcmp` after r355672.

llvm-svn: 355692
2019-03-08 12:41:42 +00:00
Kostya Kortchinsky 16d9a3a4b6 [scudo][standalone] Adding a stats class
Summary:
This adds simple local & global stats classes to be used by the Primary
and Secondary, and associated test. Note that we don't need the strict
atomicity of the addition & subtraction (as is in sanitizer_common) so
we just use load & store.

Reviewers: morehouse, vitalybuka, eugenis, flowerhack, dmmoore415

Reviewed By: morehouse, vitalybuka

Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 355643
2019-03-07 21:44:35 +00:00
Julian Lettner ed77926f99 [TSan] Temporarily disable test which fails on build bot
llvm-svn: 355642
2019-03-07 21:42:48 +00:00
Julian Lettner 9d782f998d [TSan] Temporarily disable test which fails on build bot
llvm-svn: 355633
2019-03-07 20:30:18 +00:00
Vlad Tsyrklevich 2e1479e2f2 Delete x86_64 ShadowCallStack support
Summary:
ShadowCallStack on x86_64 suffered from the same racy security issues as
Return Flow Guard and had performance overhead as high as 13% depending
on the benchmark. x86_64 ShadowCallStack was always an experimental
feature and never shipped a runtime required to support it, as such
there are no expected downstream users.

Reviewers: pcc

Reviewed By: pcc

Subscribers: mgorny, javed.absar, hiraditya, jdoerfert, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

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

llvm-svn: 355624
2019-03-07 18:56:36 +00:00
Julian Lettner a30357d1e0 [NFC][TSan] Remove unnecessary #include
llvm-svn: 355620
2019-03-07 18:22:22 +00:00
Julian Lettner 011a90b96a [TSan][Linux] Fix libdispatch interception macros compilation errors
Most libdispatch functions come in two variants: callbacks can be
specified via blocks or function pointers. Some of our interceptors for
the block variant actually forward to the function variant. However, on
Linux, `DECLARE_REAL(name)` has to appear before `REAL(name)`.

This patch reorders _f variant interceptors before _b variants
where possible and forward declares the _f variant in the remaining
cases (cyclic dependency between _f and _b interceptors).

Also rename macro to DISPATCH_INTERCEPT_ASYNC_F for better consistency.

Reviewed By: dvyukov

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

llvm-svn: 355619
2019-03-07 18:15:29 +00:00
Julian Lettner 9ee68ffffd [NFC][TSan] Add libdispatch tests for non-Darwin platforms
Add new sets of tests (copy instead of move existing tests) because
there could be subtle differences between C/Obj-C and with/without
Foundation etc.

Reviewed By: dvyukov

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

llvm-svn: 355618
2019-03-07 18:15:26 +00:00
Julian Lettner 98a00defe1 [Sanitizer] Add 'dispatch' feature to be used in compiler-rt tests
Reviewed By: dvyukov

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

llvm-svn: 355617
2019-03-07 18:15:23 +00:00
Julian Lettner eacde7d2b0 [NFC][TSan][libdispatch] Rename tsan_block_context_t -> block_context_t
'tsan_' part of the struct name is redundant since we are already inside
the __tsan namespace.

llvm-svn: 355539
2019-03-06 19:27:10 +00:00
Julian Lettner 96ef52ccf0 [tsan] Support interception of libdispatch on Linux
This is a new attempt for bringing TSan libdispatch support to Linux.
The main issue with the last patch (https://reviews.llvm.org/D53171) was
that we want to avoid building a separate library.

The updated plan is as follows:
1) Hide libdispatch support behind a flag: true on Darwin, false
   elsewhere. If flag is specified, assume that libdispatch header and
   -flbocks is available for building. This way we can directly include
   the libdispatch header and rely on blocks runtime for our
   implementation.
2) Optionally/weakly intercept libdispatch API functions.

This patch accomplishes 1). It compiles (without the flag enabled) on
Linux. Follow-up patches will provide 2) and enabling of tests on Linux.

Reviewed By: dvyukov

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

llvm-svn: 355538
2019-03-06 19:25:09 +00:00
Martin Liska a25a2c7c9a Always compare C++ typeinfo (based on libstdc++ implementation).
Differential Revision: https://reviews.llvm.org/D58028

llvm-svn: 355488
2019-03-06 08:36:50 +00:00
Kostya Kortchinsky 7421f7bd66 [scudo][standalone] Add bytemap classes
Summary:
The bytemap classes will be used by the primary32 allocator to associate
classes with memory regions. It's similar to the sanitizer_common one
except for the fact that the base (level1) maps are mapped instead of
being static to reduce the memory footprint of an uninitialized allocator.

Reviewers: vitalybuka, eugenis, morehouse, flowerhack, dmmoore415, mcgrathr

Reviewed By: vitalybuka, morehouse

Subscribers: mgorny, delcypher, jfb, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 355416
2019-03-05 17:36:11 +00:00
Martin Storsjo 826624f00a [sanitizers] Don't use Windows Trace Logging with Clang in MSVC mode either
The TraceLoggingProvider.h header does work with clang-cl in general
these days with Win SDK 10.0.17763.0, but when compiled in 32 bit x86
mode, with the -Z7 flag, compilation fails with the following error:

fatal error: error in backend: assembler label '' can not be undefined

With older Win SDKs, there are other build failures (regardless of
architecture or the -Z7 flag).

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

llvm-svn: 355397
2019-03-05 12:50:06 +00:00
Vitaly Buka 816e7b43dc [NFC] Simplify BufferedStackTrace::UnwindImpl
llvm-svn: 355381
2019-03-05 05:52:34 +00:00
Vitaly Buka 1ac22bfef0 [NFC] Move isUnwinding check into ScopedUnwinding
llvm-svn: 355380
2019-03-05 05:40:05 +00:00
Vitaly Buka 7cbb408850 [NFC] Move ScopedUnwinding from .h to .cc
llvm-svn: 355377
2019-03-05 04:36:56 +00:00
Vitaly Buka 4d9d2251ab [NFC] Reorder ifs in BufferedStackTrace::UnwindImpl
llvm-svn: 355376
2019-03-05 04:36:49 +00:00
Vitaly Buka 3d7e9c843b [NFC] Return on SANITIZER_MIPS && !IsValidFrame
llvm-svn: 355372
2019-03-05 02:51:04 +00:00
Vitaly Buka b214bd4b71 [NFC] Put bp into Unwind(.. false) for consistency
It's not used there anyway

llvm-svn: 355371
2019-03-05 02:50:57 +00:00
Vitaly Buka 3eb19449f9 [NFC] Move asan_inited and size reset on top of ::UnwindImpl
llvm-svn: 355370
2019-03-05 02:50:49 +00:00
Vitaly Buka 0d973a5311 Revert "[NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation"
I've missed that UnwindSlow was removed from ScopedUnwinding.

This reverts commit 4ce918e394.

llvm-svn: 355369
2019-03-05 02:35:49 +00:00
Manman Ren ff4bb36d7c Revert compiler-rt diffs for order file instrumentation to get bot green!
This caused issues on Linux/Windows and other platforms.

r355343 355350 355350

llvm-svn: 355363
2019-03-05 01:21:40 +00:00
Manman Ren 31b31e5111 Attemp to fix windows profile-rt build breakage.
Followup to D57530.

llvm-svn: 355357
2019-03-05 00:52:00 +00:00
Julian Lettner 4ce918e394 [NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation
Cleanup ASan's  __sanitizer::BufferedStackTrace::UnwindImpl (formerly
GetStackTrace) implementation. Start with ASan because it is the most
complex implementation.

GetStackTrace implementations seem to have started out as exact copies
of the original implementation in ASan, but have diverged in subtle
ways. My goal is to parameterize this algorithm (via templating or
callbacks) so we can share the implementation and get rid of the
inversed dependency (sanitizer_common depends on concrete
implementations in asan, ubsan, etc.). This should also help us to avoid
those pesky linker errors caused by undefined, duplicate, and weak
symbols on Windows.

Reviewed By: vitalybuka

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

llvm-svn: 355355
2019-03-05 00:41:15 +00:00
Manman Ren 03d5348132 Attemp to fix build brokage due to D57530.
By adding implementations for __llvm_profile_begin_orderfile for non-Darwin platforms.

llvm-svn: 355350
2019-03-04 23:41:57 +00:00
Evgeniy Stepanov 53d7c5cd44 [msan] Instrument x86 BMI intrinsics.
Summary:
They simply shuffle bits. MSan needs to do the same with shadow bits,
after making sure that the shuffle mask is fully initialized.

Reviewers: pcc, vitalybuka

Subscribers: hiraditya, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 355348
2019-03-04 22:58:20 +00:00
Evgeniy Stepanov 8cee2e8539 [sanitizer] Intercept bzero.
Summary:
Intercept bzero and enable existing __bzero interceptor in Linux.
bzero is deprecated but still used occasionally.

Reviewers: vitalybuka

Subscribers: srhines, kubamracek, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 355347
2019-03-04 22:58:11 +00:00
Manman Ren 4737abc71c Order File Instrumentation: dump the data in compiler-rt
The profile data will be dumped in a file default_xxx.profraw.order.

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

llvm-svn: 355343
2019-03-04 22:28:38 +00:00
Shoaib Meenai 5be71faf4b [build] Rename clang-headers to clang-resource-headers
Summary:
The current install-clang-headers target installs clang's resource
directory headers. This is different from the install-llvm-headers
target, which installs LLVM's API headers. We want to introduce the
corresponding target to clang, and the natural name for that new target
would be install-clang-headers. Rename the existing target to
install-clang-resource-headers to free up the install-clang-headers name
for the new target, following the discussion on cfe-dev [1].

I didn't find any bots on zorg referencing install-clang-headers. I'll
send out another PSA to cfe-dev to accompany this rename.

[1] http://lists.llvm.org/pipermail/cfe-dev/2019-February/061365.html

Reviewers: beanz, phosek, tstellar, rnk, dim, serge-sans-paille

Subscribers: mgorny, javed.absar, jdoerfert, #sanitizers, openmp-commits, lldb-commits, cfe-commits, llvm-commits

Tags: #clang, #sanitizers, #lldb, #openmp, #llvm

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

llvm-svn: 355340
2019-03-04 21:19:53 +00:00
Evgeniy Stepanov 02a913367a Revert "[sanitizer] Fix return type of __bzero and __aeabi_mem* interceptors."
Breaks TSan on Mac, which does
  return REAL(func)(...
in COMMON_INTERCEPTOR_ENTER, which is not OK when REAL(func) has return
type of void.

llvm-svn: 355256
2019-03-02 01:33:52 +00:00