Commit Graph

10972 Commits

Author SHA1 Message Date
Benjamin Kramer a2ada4d1ce [X86][compiler-rt] Add missing semicolon
llvm-svn: 347519
2018-11-24 20:57:03 +00:00
Craig Topper 428caa398c [X86] Make conversion of feature bits into a mask explicitly unsigned by using 1U instead of 1.
llvm-svn: 347517
2018-11-24 20:25:45 +00:00
Craig Topper 62e5924dd6 [X86][compiler-rt] Attempt to fix a warning about a shift amount being negative in a macro expansion.
llvm-svn: 347516
2018-11-24 20:14:03 +00:00
David Carlier 0a01f5d244 Unbreak FreeBSD build.
M    lib/sanitizer_common/sanitizer_platform_limits_posix.cc

llvm-svn: 347451
2018-11-22 10:31:01 +00:00
Petr Hosek e7dec7848b [XRay] Support for Fuchsia
This extends XRay to support Fuchsia.

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

llvm-svn: 347443
2018-11-22 02:00:44 +00:00
Peter Collingbourne 56f3bb4b36 tsan: Update measurements in check_analyze.sh.
These changed as a result of r347379. Unfortunately there was a
regression; filed PR39748 to track it.

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

llvm-svn: 347442
2018-11-22 00:47:37 +00:00
Peter Collingbourne c56109306b tsan: Correct the name of an executable.
llvm-svn: 347439
2018-11-22 00:00:26 +00:00
David Carlier 0c81a62d9d [Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions
- Enabling setvbuf interceptions for non NetBSD platforms.
- setbuf, setbuffer, setlinebuf as well.

Reviewers: vitalybuka, krytarowski	

Reviewed By: vitalybuka

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

llvm-svn: 347426
2018-11-21 21:17:46 +00:00
Roman Lebedev 1d0c7f563c [compiler-rt][UBSan] silence_unsigned_overflow: do *NOT* ignore *fatal* unsigned overflows
Summary:
D48660 / rL335762 added a `silence_unsigned_overflow` env flag for [[ https://github.com/google/oss-fuzz/pull/1717 | oss-fuzz needs ]],
that allows to silence the reports from unsigned overflows.
It makes sense, it is there because `-fsanitize=integer` sanitizer is not enabled on oss-fuzz,
so this allows to still use it as an interestingness signal, without getting the actual reports.

However there is a slight problem here.
All types of unsigned overflows are ignored.
Even if `-fno-sanitize-recover=unsigned` was used (which means the program will die after the report)
there will still be no report, the program will just silently die.

At the moment there are just two projects on oss-fuzz that care:
* [[ 8eeffa627f/projects/llvm_libcxx/build.sh (L18-L20) | libc++ ]]
* [[ 8eeffa627f/projects/librawspeed/build.sh | RawSpeed ]] (me)

I suppose this could be overridden there ^, but i really don't think this is intended behavior in any case..

Reviewers: kcc, Dor1s, #sanitizers, filcab, vsk, kubamracek

Reviewed By: Dor1s

Subscribers: dberris, mclow.lists, llvm-commits

Tags: #sanitizers

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

llvm-svn: 347415
2018-11-21 20:35:43 +00:00
Dmitry Vyukov d0fb5d8b00 tsan: add pthread_tryjoin_np and pthread_timedjoin_np interceptors
Add pthread_tryjoin_np() and pthread_timedjoin_np() interceptors on Linux,
so that ThreadSanitizer can handle programs using these functions.

Author: Yuri Per (yuri)
Reviewed in: https://reviews.llvm.org/D54521

llvm-svn: 347383
2018-11-21 09:31:21 +00:00
Douglas Yung 5839abb2f9 Add header <atomic> which is needed to compile with some older library versions.
llvm-svn: 347382
2018-11-21 08:54:40 +00:00
Dean Michael Berris 2b95e3c5cf [XRay] Add a test for re-initialising FDR mode (NFC)
This change adds an end-to-end test that ensures FDR mode can be
re-initialised safely in the face of multiple threads being traced.

llvm-svn: 347368
2018-11-21 00:30:26 +00:00
David Carlier d931c135f0 Revert "[Sanitizer] intercept setvbuf on other platforms where it is supported"
llvm-svn: 347358
2018-11-20 22:50:31 +00:00
David Carlier a1ea566fbc [Sanitizer] Unbreak non NetBSD builds.
llvm-svn: 347357
2018-11-20 22:35:29 +00:00
David Carlier 5ffb47b3a1 [Sanitizer] intercept setvbuf on other platforms where it is supported
Unit tests enabled only in platform tested.

Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski, vitalybuka

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

llvm-svn: 347355
2018-11-20 22:17:23 +00:00
Michal Gorny 4b0b84f4bb [cmake] Fix detecting terminfo library
Copy the fix for determining the correct terminfo library from LLVM --
use distinct variables for check_library_exists() calls.  Otherwise,
the first check (for -ltinfo) populates the variable and no other checks
are performed.  Effectively, systems with other libraries than the first
one listed are presumed not to have terminfo routines at all.

Also sync the check order to include the NetBSD fix from r347156.

This partially fixes undefined symbols when linking XRay tests.  It's
probably not the best solution to the problem there but as long
as the terminfo check stays in config-ix, I thnk it's worth fixing.

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

llvm-svn: 347338
2018-11-20 18:41:11 +00:00
Vitaly Buka afedb893a6 [tsan] Add __cxa_guard_acquire hooks to support cooperative scheduling
Reviewers: dvyukov

Subscribers: krytarowski, kubamracek, llvm-commits

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

llvm-svn: 347336
2018-11-20 18:21:42 +00:00
Dean Michael Berris 388af45f18 [XRay] Add a test for allocator exhaustion
Use a more representative test of allocating small chunks for
oddly-sized (small) objects from an allocator that has a page's worth of
memory.

llvm-svn: 347286
2018-11-20 03:56:04 +00:00
Dean Michael Berris ba02cb58cf [XRay] Move buffer extents back to the heap
Summary:
This change addresses an issue which shows up with the synchronised race
between threads writing into a buffer, and another thread reading the
buffer.

In a lot of cases, we cannot guarantee that threads will always see the
signal to finalise their buffers in time despite the grace periods and
state machine maintained through atomic variables. This change addresses
it by ensuring that the same instance being updated to indicate how much
of the buffer is "used" by the writing thread is the same instance being
read by the thread processing the buffer to be written out to disk or
handled through the iterators.

To do this, we ensure that all the "extents" instances live in their own
the backing store, in a different contiguous page from the
buffer-specific backing store. We also take precautions to ensure that
the atomic variables are cache-line-sized to prevent false-sharing from
unnecessarily causing cache contention on unrelated writes/reads.

It's feasible that we may in the future be able to move the storage of
the extents objects into the single backing store, slightly changing the
way to compute the size(s) of the buffers, but in the meantime we'll
settle for the isolation afforded by having a different backing store
for the extents instances.

Reviewers: mboerger

Subscribers: jfb, llvm-commits

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

llvm-svn: 347280
2018-11-20 01:00:26 +00:00
Petr Hosek 8e0e35a3f5 [compiler-rt] Use zx_futex_wait_deprecated for Fuchsia sanitizer runtime
This change is part of the soft-transition to the new synchronization
primitives which implement priority inheritance.

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

llvm-svn: 347279
2018-11-20 00:55:20 +00:00
Kamil Rytarowski 74abaf8cdc Add interceptor for the setvbuf(3) from NetBSD
Summary:
setvbuf(3) is a routine to setup stream buffering.

Enable the interceptor for NetBSD.

Add dedicated tests for setvbuf(3) and functions
on top of this interface: setbuf, setbuffer, setlinebuf.

Based on original work by Yang Zheng.

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: devnexen, tomsun.0.7, kubamracek, llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

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

llvm-svn: 347270
2018-11-19 22:44:26 +00:00
Kostya Serebryany 0e799d92fd [hwasan] don't check tail magic when in right_align mode (should fix the bot)
llvm-svn: 347121
2018-11-17 01:02:09 +00:00
Kostya Serebryany b5c1d69e40 [hwasan] make the heap-buffer-overflow.c test more robust and re-enable it. With malloc_align_right the relative offsets of heap chunks are less predictable to simply don't test for them.
llvm-svn: 347118
2018-11-17 00:40:34 +00:00
Kostya Serebryany c265e7673d [hwasan] implement free_checks_tail_magic=1
Summary:
With free_checks_tail_magic=1 (default) HWASAN
writes magic bytes to the tail of every heap allocation
(last bytes of the last granule, if the last granule is not fully used)
and checks these bytes on free().

This feature will detect buffer overwires within the last granule
at the time of free().

This is an alternative to malloc_align_right=[1289] that should have
fewer compatibility issues. It is also weaker since it doesn't
detect read overflows and reports bugs at free() instead of at access.

Reviewers: eugenis

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

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

llvm-svn: 347116
2018-11-17 00:25:17 +00:00
Kostya Serebryany 31b6a14a99 [hwasan] use reads instead of writes in a test
llvm-svn: 347107
2018-11-16 23:01:42 +00:00
Kamil Rytarowski 003b720873 Revert "Cast the 2nd argument of _Unwind_SetIP() to _Unwind_Ptr"
_Unwind_Ptr is unknown on some targets.

Detected on green-dragon-21 (MacPro Late 2013 | OS X 10.14(18A391) | Xcode 10.1(10B61)).

llvm-svn: 347106
2018-11-16 23:00:28 +00:00
Kamil Rytarowski 54eaafafbf Cast the 2nd argument of _Unwind_SetIP() to _Unwind_Ptr
This modification is require for NetBSD with GCC, as there is a
custom unwind.h header implementation with different types.

No functional change intended for others.

Cherry-picked chunk from D33878.

llvm-svn: 347102
2018-11-16 22:17:36 +00:00
Kamil Rytarowski 7461cc12fc Cast _Unwind_GetIP() and _Unwind_GetRegionStart() to uintptr_t
This modification is require for NetBSD with GCC, as there is a
custom unwind.h header implementation with different types.

No functional change intended for others.

Cherry-picked chunk from D33878.

llvm-svn: 347101
2018-11-16 22:15:09 +00:00
Vitaly Buka c505ceeb3c [sanitizer] Update global_symbols.txt
llvm-svn: 347099
2018-11-16 21:42:22 +00:00
Kostya Serebryany f5912d0ef2 [hwasan] disable one test line while investigating a bot failure
llvm-svn: 347091
2018-11-16 20:35:07 +00:00
Kamil Rytarowski 56ef906532 Add new interceptor for mi_vector_hash(3)
Summary:
mi_vector_hash(3) provides fast 32bit hash functions.

Add a test for this interface.

Enable the API for NetBSD.

Based on original work by Yang Zheng.

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: tomsun.0.7, kubamracek, llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

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

llvm-svn: 347088
2018-11-16 19:54:13 +00:00
Kamil Rytarowski 47fb42e6c3 Add new interceptor for getmntinfo(3) from NetBSD
Summary:
getmntinfo gets information about mounted file systems.

Add a dedicated test for new interceptor.

Based on original work by Yang Zheng.

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: tomsun.0.7, kubamracek, llvm-commits, mgorny, #sanitizers

Tags: #sanitizers

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

llvm-svn: 347083
2018-11-16 19:47:42 +00:00
Kostya Serebryany ba5c7169c5 [hwasan] optionally right-align heap allocations
Summary:
... so that we can find intra-granule buffer overflows.
The default is still to always align left.
It remains to be seen wether we can enable this mode at scale.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: jfb, dvyukov, kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 347082
2018-11-16 19:38:48 +00:00
Petr Hosek 5f5c773765 [compiler-rt] Use exact spelling when building for default target
When building for default target only, use exact target spelling
when deriving the name for the per-target runtime directory. This
is necessary for AArch32 where the CMake build by default rewrites
the architecture which leads to unexpected results.

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

llvm-svn: 347022
2018-11-16 04:14:23 +00:00
Dan Liew ee6eb9b25a Start adding the supporting code to perform out-of-process allocator
enumeration.

Summary:

This patch introduces the local portion (`LocalAddressSpaceView`) of the
`AddressSpaceView` abstraction and modifies the secondary allocator
so that the `ForEachChunk()` method (and its callees) would work in the
out-of-process case when `AddressSpaceView` is `RemoteAddressSpaceView`.

The `AddressSpaceView` abstraction simply maps pointers from a target
process to a pointer in the local process (via its `Load()` method). For
the local (in-process) case this is a no-op. For the remote
(out-of-process) case this is not a no-op. The implementation of the
out-of-process `RemoteAddressSpaceView` is not included in this patch
and will be introduced later.

This patch is considerably simpler than the `ObjectView` abstraction
used in previous patches but lacks the type safety and stricter memory
management of the `ObjectView` abstraction.

This patch does not introduce any tests because with
`LocalAddressSpaceView` it should be a non functional change and unit
tests already cover the secondary allocator.  When
`RemoteAddressSpaceView` is landed tests will be added to ensure that it
functions as expected.

rdar://problem/45284065

Reviewers: kcc, kubamracek, dvyukov, vitalybuka, cryptoad,
george.karpenkov, morehouse

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 346956
2018-11-15 14:20:28 +00:00
Petr Hosek 2d2e23e89b [CMake] Passthrough CFLAGS when checking the compiler-rt path
This is needed when cross-compiling for a different target since
CFLAGS may contain additional flags like -resource-dir which
change the location in which compiler-rt builtins are found.

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

llvm-svn: 346820
2018-11-14 00:09:26 +00:00
George Karpenkov 6fd29477c3 [lsan] [FIXUP] Fixup for http://reviews.llvm.org/D54484
After the change, the tests started failing, as skipped sections can be
equal in size to kMaxSegName.
Changing `<` to `<=` to address the off-by-one problem.

llvm-svn: 346804
2018-11-13 22:17:16 +00:00
George Karpenkov 2e8839de7c [lsan] [NFC] Change ARRAY_SIZE to internal_strnlen
Calling ARRAY_SIZE on a char* will not actually compute it's size, but just the pointer size.
A new Clang warning enabled by default warns about this.

Replaced the call with internal_strnlen.

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

llvm-svn: 346792
2018-11-13 20:19:38 +00:00
Kamil Rytarowski 4a282024db Correct atexit(3) support in MSan/NetBSD
Summary:
The NetBSD specific implementation of cxa_atexit() does not
preserve the 2nd argument if dso is equal to NULL.

Changes:

 - Split paths of handling intercepted __cxa_atexit() and atexit(3).
   This affects all supported Operating Systems.
 - Add a local stack-like structure to hold the __cxa_atexit() context.
   atexit(3) is documented in the C standard as calling callback from the
   earliest to the oldest entry. This path also fixes potential ABI
   problem of passing an argument to a function from the atexit(3)
   callback mechanism.
 - Allow usage of global vars with ctors in interceptors.
   This allows to use Vector without automatic cleaning up the structures.

This code has been modeled after TSan implementation for the same functions.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: vitalybuka

Subscribers: delcypher, devnexen, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 346579
2018-11-10 02:17:32 +00:00
Reid Kleckner 6c0bb3758e Re-land r343606 "[winasan] Unpoison the stack in NtTerminateThread"
This change was reverted because it caused some nacl tests in chromium
to fail. I attempted to reproduce those problems locally, but I was
unable to. Let's reland this and let Chromium's test infrastructure
discover any problems.

llvm-svn: 346560
2018-11-09 22:06:59 +00:00
Evgeniy Stepanov 771d6d37ca [hwasan] Add entire report to abort message on Android.
Summary:
When reporting a fatal error, collect and add the entire report text to
android_set_abort_message so that it can be found in the tombstone.

Reviewers: kcc, vitalybuka

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 346557
2018-11-09 21:54:03 +00:00
Dean Michael Berris 9e089fca7e [XRay] Add a test for function id encoding/decoding (NFC)
Increase test coverage for function enter/exit encoding/decoding.

llvm-svn: 346477
2018-11-09 07:43:30 +00:00
Dean Michael Berris ead47aab78 [XRay] Add a static assertion on size of metadata payload (NFC)
This change adds a static check to ensure that all data metadata record
payloads don't go past the available buffers in Metadata records.

llvm-svn: 346476
2018-11-09 07:16:45 +00:00
Dean Michael Berris e39a89fbfb [XRay] Fix enter function tracing for record unwriting
Summary:
Before this change, we could run into a situation where we may try to
undo tail exit records after writing metadata records before a function
enter event. This change rectifies that by resetting the tail exit
counter after writing the metadata records.

Reviewers: mboerger

Subscribers: llvm-commits

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

llvm-svn: 346475
2018-11-09 06:49:00 +00:00
Dean Michael Berris aeae545064 [XRay] Add atomic fences around non-atomic reads and writes
Summary:
We need these fences to ensure that other threads attempting to read
bytes in the buffer will see thw writes committed before the extents are
updated. Without these, the writes can be un-committed by the time the
buffer extents counter is updated -- the fences should ensure that the
records written into the log have completed by the time we observe the
buffer extents from different threads.

Reviewers: mboerger

Subscribers: jfb, llvm-commits

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

llvm-svn: 346474
2018-11-09 06:39:45 +00:00
Dean Michael Berris da375a67f8 [XRay] Improve FDR trace handling and error messaging
Summary:
This change covers a number of things spanning LLVM and compiler-rt,
which are related in a non-trivial way.

In LLVM, we have a library that handles the FDR mode even log loading,
which uses C++'s runtime polymorphism feature to better faithfully
represent the events that are written down by the FDR mode runtime. We
do this by interpreting a trace that's serliased in a common format
agreed upon by both the trace loading library and the FDR mode runtime.
This library is under active development, which consists of features
allowing us to reconstitute a higher-level event log.

This event log is used by the conversion and visualisation tools we have
for interpreting XRay traces.

One of the tools we have is a diagnostic tool in llvm-xray called
`fdr-dump` which we've been using to debug our expectations of what the
FDR runtime should be writing and what the logical FDR event log
structures are. We use this fairly extensively to reason about why some
non-trivial traces we're generating with FDR mode runtimes fail to
convert or fail to parse correctly.

One of these failures we've found in manual debugging of some of the
traces we've seen involve an inconsistency between the buffer extents (a
record indicating how many bytes to follow are part of a logical
thread's event log) and the record of the bytes written into the log --
sometimes it turns out the data could be garbage, due to buffers being
recycled, but sometimes we're seeing the buffer extent indicating a log
is "shorter" than the actual records associated with the buffer. This
case happens particularly with function entry records with a call
argument.

This change for now updates the FDR mode runtime to write the bytes for
the function call and arg record before updating the buffer extents
atomically, allowing multiple threads to see a consistent view of the
data in the buffer using the atomic counter associated with a buffer.
What we're trying to prevent here is partial updates where we see the
intermediary updates to the buffer extents (function record size then
call argument record size) becoming observable from another thread, for
instance, one doing the serialization/flushing.

To do both diagnose this issue properly, we need to be able to honour
the extents being set in the `BufferExtents` records marking the
beginning of the logical buffers when reading an FDR trace. Since LLVM
doesn't use C++'s RTTI mechanism, we instead follow the advice in the
documentation for LLVM Style RTTI
(https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html). We then rely on
this RTTI feature to ensure that our file-based record producer (our
streaming "deserializer") can honour the extents of individual buffers
as we interpret traces.

This also sets us up to be able to eventually do smart
skipping/continuation of FDR logs, seeking instead to find BufferExtents
records in cases where we find potentially recoverable errors. In the
meantime, we make this change to operate in a strict mode when reading
logical buffers with extent records.

Reviewers: mboerger

Subscribers: hiraditya, llvm-commits, jfb

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

llvm-svn: 346473
2018-11-09 06:26:48 +00:00
Evgeniy Stepanov 4680386c34 [hwasan] Remove dead code.
llvm-svn: 346452
2018-11-09 00:03:39 +00:00
Dan Liew 7383b4fba4 Introduce `sanitizer_malloc_introspect_t` for Darwin which is a sub-class of Darwin's `malloc_introspection_t` and use it when setting up the malloc zone.
Summary:
Currently `sanitizer_malloc_introspection_t` just adds a version field
which is used to version the allocator ABI. The current allocator ABI
version is returned by the new `GetMallocZoneAllocatorEnumerationVersion()` function.

The motivation behind this change is to allow external processes to
determine the allocator ABI of a sanitized process.

rdar://problem/45284065

Reviewers: kubamracek, george.karpenkov, vitalybuka

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 346420
2018-11-08 17:50:34 +00:00
Calixte Denizet 692b34790f [Profile] The test for gcov-fork seems to be ok on arm
Summary: Remove the XFAIL for arm since it seems to be ok

Reviewers: marco-c

Reviewed By: marco-c

Subscribers: javed.absar, kristof.beyls, delcypher, chrib, llvm-commits, #sanitizers, sylvestre.ledru

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

llvm-svn: 346409
2018-11-08 16:16:04 +00:00
Kamil Rytarowski e06fb482a9 Split lgammal() from INIT_LGAMMAL
Summary:
Introduce SANITIZER_INTERCEPT_LGAMMAL
dedicated for lgammal(). Disable it for NetBSD
as this routine is not implemented in this OS.

Installation of supernumerary interceptors causes
leaking of errors to dlsym(3)-like operations.

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 346352
2018-11-07 20:19:53 +00:00