Commit Graph

11258 Commits

Author SHA1 Message Date
Martin Liska 629b40dafa Fix -Wformat warnings reported by GCC.
Differential Revision: https://reviews.llvm.org/D113099
2021-11-04 08:51:43 +01:00
Lang Hames 870fc844d1 [ORC-RT] Add SPS serialization for span<const char> / SPSSequence<char>. 2021-11-03 13:43:49 -07:00
Tamir Duberstein f639882be8 [sanitizer] Allow getsockname with NULL addrlen
This is already permitted in getpeername, and returns EFAULT
on Linux (does not crash the program).

Fixes https://github.com/google/sanitizers/issues/1451.

Differential Revision: https://reviews.llvm.org/D113055
2021-11-03 10:23:01 -07:00
Tamir Duberstein 33d9b7b4b2 [sanitizer] Mark before deref in PosixSpawnImpl
Read each pointer in the argv and envp arrays before dereferencing
it; this correctly marks an error when these pointers point into
memory that has been freed.

Differential Revision: https://reviews.llvm.org/D113046
2021-11-03 10:18:06 -07:00
Rich Lowe de6f7252da [sanitizer_common] Fix readlink error handling in sanitizer_procmaps_solaris.cpp
As pointed out in Bug 52371, the Solaris version of
`MemoryMappingLayout::Next` completely failed to handle `readlink` errors
or properly NUL-terminate the result.

This patch fixes this.  Originally provided in the PR with slight
formatting changes.

Tested on `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D112998
2021-11-02 22:06:17 +01:00
Matt Morehouse 498a4c2fd7 [HWASan] Print short tags in tag mismatch description.
I recently spent some extra time debugging a false positive because I
didn't realize the "real" tag was in the short granule.  Adding the
short tag here makes it more obvious that we could be dealing with a
short granule.

Reviewed By: hctim, eugenis

Differential Revision: https://reviews.llvm.org/D112949
2021-11-02 08:00:33 -07:00
Matt Morehouse 8c60e0b632 [HWASan] Print short tags in __hwasan_print_shadow.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D112959
2021-11-02 07:59:25 -07:00
David Carlier 56513e3e42 [sanitizers] remove extra comma for sha2 interceptors 2021-11-02 10:35:44 +00:00
Vitaly Buka 08e0b9235b Revert "[NFC][sanitizer] Disable a test with large stderr output"
This reverts commit 6eb38e5171.

The test was not the reason of sanitizer-x86_64-linux-android failures.
2021-11-02 01:25:46 -07:00
Vitaly Buka 9213202abd [sanitizer] Fix PosixSpawnImpl which fails exitcode test 2021-11-01 21:03:02 -07:00
David Carlier b4fb42300e [sanitizer] msan build fix on non linux platforms 2021-11-01 07:18:43 +00:00
Vitaly Buka 948b91a08e [NFC][sanitizer] Atomix relaxed in TwoLevelMap
This is NOOP in x86_64.
On arch64 it avoids Data Memory Barrier with visible improvements on micro benchmarks.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D112391
2021-10-31 12:18:03 -07:00
Vitaly Buka e1240745ef [sanitizer] Add posix_spawn interceptor
To make pid initialized for Msan.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D112784
2021-10-31 12:10:54 -07:00
Lang Hames 81a6eabf71 [ORC-RT] Add missing file that was left out of ff846fcb64. 2021-10-31 10:53:17 -07:00
Lang Hames ff846fcb64 [ORC][ORC-RT] Switch MachO EH/TLV registration from EPC-calls to alloc actions.
MachOPlatform used to make an EPC-call (registerObjectSections) to register the
eh-frame and thread-data sections for each linked object with the ORC runtime.

Now that JITLinkMemoryManager supports allocation actions we can use these
instead of an EPC call. This saves us one EPC-call per object linked, and
manages registration/deregistration in the executor, rather than the controller
process. In the future we may use this to allow JIT'd code in the executor to
outlive the controller object while still being able to be cleanly destroyed.

Since the code for allocation actions must be available when the actions are
run, and since the eh-frame registration code lives in the ORC runtime itself,
this change required that MachO eh-frame support be split out of
macho_platform.cpp and into its own macho_ehframe_registration.cpp file that has
no other dependencies. During bootstrap we start by forcing emission of
macho_ehframe_registration.cpp so that eh-frame registration is guaranteed to be
available for the rest of the bootstrap process. Then we load the rest of the
MachO-platform runtime support, erroring out if there is any attempt to use
TLVs. Once the bootstrap process is complete all subsequent code can use all
features.
2021-10-31 10:27:40 -07:00
Dmitry Vyukov d31b2dc235 tsan: add debugging code for ptrace test failures
Debugging of crashes on powerpc after commit:
c80604f7a3 ("tsan: remove real func check from interceptors")
Somehow replacing if with DCHECK leads to strange failures in:
SanitizerCommon-tsan-powerpc64le-Linux :: Linux/ptrace.cpp
https://lab.llvm.org/buildbot/#/builders/105
https://lab.llvm.org/buildbot/#/builders/121
https://lab.llvm.org/buildbot/#/builders/57

The hypothesis is that something writes out-of-bounds
into pt_regs on stack and that corrupts internal tsan state.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112703
2021-10-29 17:37:02 +02:00
Dmitry Vyukov 014c6b0736 sanitizer_common: fix ParseUnixMemoryProfile test linking on Mac
The ParseUnixMemoryProfile function is defined only for a subset
of platforms. Define the test for the same set of platforms.

Also disable the test for 32-bit platforms b/c the pointer
values used in the test are 64-bit and don't fit into 32-bit uptr.

Reported-by: Jan Svoboda (jansvoboda11)

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112815
2021-10-29 16:26:24 +02:00
Rainer Orth 2f353c040f [sanitizer_common] Fix Posix/mmap_write_exec.cpp on 32-bit Solaris
The new `Posix/mmap_write_exec.cpp` test FAILs on 32-bit Solaris/x86.  This
happens because only `mmap` is intercepted, but not `mmap64` which is used
for largefile support.

Fixed by also intercepting `mmap64`.

Tested on `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D112810
2021-10-29 14:29:41 +02:00
Dmitry Vyukov af0a8b8317 sanitizer_common: bump default file max size to 256MB
I am hitting some cases where /proc/self/maps does not fit into 64MB.
256MB is lots of memory, but it's not radically more than the current 64MB.
Ideally we should read/parse these huge files incrementally,
but that's lots of work for a debugging/introspection interface.
So for now just bump the limit.

Depends on D112793.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112794
2021-10-29 14:03:26 +02:00
Dmitry Vyukov e8861fa6c3 sanitizer_common: fix crashes in parsing of memory profiles
ParseUnixMemoryProfile assumes well-formed input with \n at the end, etc.
It can over-read the input and crash on basically every line
in the case of malformed input.
ReadFileToBuffer has cap the max file size (64MB) and returns
truncated contents if the file is larger. Thus even if kernel behaves,
ParseUnixMemoryProfile crashes on too large /proc/self/smaps.
Fix input over-reading in ParseUnixMemoryProfile.

Depends on D112792.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112793
2021-10-29 14:03:12 +02:00
Dmitry Vyukov 4acad5df33 sanitizer_common: add memory profile parsing test
Depends on D112790.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112792
2021-10-29 14:02:50 +02:00
Dmitry Vyukov ae833dbb81 sanitizer_common: remove unnecessary GetMemoryProfile arg
stats_size argument is unnecessary in GetMemoryProfile and in the callback.
It just clutters code. The callback knowns how many stats to expect.

Depends on D112789.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112790
2021-10-29 13:44:34 +02:00
Dmitry Vyukov d4602f759a sanitizer_common: make parsing of smaps testable (NFC)
Move parsing of /proc/self/smaps into a separate function
so that it can be tested.

Depends on D112788.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112789
2021-10-29 13:44:28 +02:00
Lang Hames dc8e5e1dc0 [ORC-RT] Add a WrapperFunctionCall utility.
WrapperFunctionCall represents a call to a wrapper function as a pair of a
target function (as an ExecutorAddr), and an argument buffer range (as an
ExecutorAddrRange). WrapperFunctionCall instances can be serialized via
SPS to send to remote machines (only the argument buffer address range is
copied, not any buffer content).

This utility will simplify the implementation of JITLinkMemoryManager
allocation actions in the ORC runtime.
2021-10-28 17:07:28 -07:00
Vitaly Buka 6eb38e5171 [NFC][sanitizer] Disable a test with large stderr output 2021-10-28 15:15:20 -07:00
David CARLIER bb168f3207 [compiler-rt] update detect_write_exec option for apple devices.
Reviewed By: yln, vitalybuka

Differential Revision: https://reviews.llvm.org/D111390
2021-10-28 17:08:23 +01:00
Dmitry Vyukov d736002e90 tsan: move memory access functions to a separate file
tsan_rtl.cpp is huge and does lots of things.
Move everything related to memory access and tracing
to a separate tsan_rtl_access.cpp file.
No functional changes, only code movement.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D112625
2021-10-28 13:31:10 +02:00
Florian Mayer dd943ebc6d [hwasan] print exact mismatch offset for short granules.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D104463
2021-10-28 03:31:11 +01:00
Kai Luo 6ea2431d3f [clang][compiler-rt][atomics] Add `__c11_atomic_fetch_nand` builtin and support `__atomic_fetch_nand` libcall
Add `__c11_atomic_fetch_nand` builtin to language extensions and support `__atomic_fetch_nand` libcall in compiler-rt.

Reviewed By: theraven

Differential Revision: https://reviews.llvm.org/D112400
2021-10-28 02:18:43 +00:00
Petr Hosek 22acda48ff [CMake] Cache the compiler-rt library search results
There's a lot of duplicated calls to find various compiler-rt libraries
from build of runtime libraries like libunwind, libc++, libc++abi and
compiler-rt. The compiler-rt helper module already implemented caching
for results avoid repeated Clang invocations.

This change moves the compiler-rt implementation into a shared location
and reuses it from other runtimes to reduce duplication and speed up
the build.

Differential Revision: https://reviews.llvm.org/D88458
2021-10-27 17:53:03 -07:00
Ben Langmuir beb3d48262 [ORC-RT] Fix objc selector corruption
We were writing a pointer to a selector string into the contents of a
string instead of overwriting the pointer to the string, leading to
corruption. This was causing non-deterministic failures of the
'trivial-objc-methods' test case.

Differential Revision: https://reviews.llvm.org/D112671
2021-10-27 16:02:52 -07:00
Ben Langmuir 3d13ee2891 [ORC][ORC-RT] Enable the MachO platform for arm64
Enables the arm64 MachO platform, adds basic tests, and implements the
missing TLV relocations and runtime wrapper function. The TLV
relocations are just handled as GOT accesses.

rdar://84671534

Differential Revision: https://reviews.llvm.org/D112656
2021-10-27 13:36:03 -07:00
Dmitry Vyukov f50cee2f4b tsan: switch sync test from EXPECT to CHECK
Gtest's EXPECT calls whole lot of libc functions
(mem*, malloc) even when EXPECT does not fail.
This does not play well with tsan runtime unit tests
b/c e.g. we call some EXPECTs with runtime mutexes locked.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112601
2021-10-27 15:11:31 +02:00
Dmitry Vyukov abdefea6a2 tsan: tidy up SCOPED_INTERCEPTOR_RAW
Don't leak caller_pc var from the macro
(it's not supposed to be used by interceptors).
Use UNUSED instead of (void) cast.

Depends on D112540.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112541
2021-10-27 08:47:46 +02:00
Dmitry Vyukov c80604f7a3 tsan: remove real func check from interceptors
If the real function is not intercepted,
we are going to crash one way or another.
The question is just in the failure mode:
error message vs NULL deref. But the message
costs us a check in every interceptor and
they are not observed to be failing in real life
for a long time, also other sanitizers don't
have this check as well (also crash on
NULL deref if that happens).
Remove the check from non-debug mode.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112540
2021-10-27 08:47:27 +02:00
Dmitry Vyukov 65e795c9ca Revert "tsan: turn off COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED"
This reverts commit 5ec832269e.

It broke a number of bots, e.g.:
https://lab.llvm.org/buildbot/#/builders/52/builds/11811

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112563
2021-10-26 19:53:07 +02:00
Matt Morehouse 082d2ad015 [libFuzzer] Improve corpus replacement unit test.
Verify that SecondII is not replaced.
2021-10-26 08:09:11 -07:00
Dmitry Vyukov 5ec832269e tsan: turn off COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED
All tsan interceptors check for initialization and/or initialize things
as necessary lazily, so we can pretend everything is initialized in the
COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED check to avoid double-checking
for initialization (this is only necessary for sanitizers that don't
handle initialization on common grounds).

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112446
2021-10-26 16:13:03 +02:00
Dmitry Vyukov d53abf834c sanitizer_common: fix deadlock detector output
Print PC of the previous lock, not the current one.
The current one will be printed during unwind.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112533
2021-10-26 16:11:52 +02:00
Julian Lettner b3980b5b68 [Sanitizer] Strip PAC from PC in StackTrace::GetNextInstructionPc()
In TSan, we use the a function reference (`__tsan_stack_initialization`)
in a call to `StackTrace::GetNextInstructionPc(uptr pc)`.  We sign
function pointers, so we need to strip the signature from this function
pointer.

Caused by: https://reviews.llvm.org/D111147

Radar-Id: rdar://problem/83940546
2021-10-25 14:48:09 -07:00
Dmitry Vyukov 1b348902ea tsan: add DynamicMutexSet helper
MutexSet is too large to be allocated on stack.
But we need local MutexSet objects in few places
and use various hacks to allocate them.
Add DynamicMutexSet helper that simplifies allocation
of such objects.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112449
2021-10-25 19:45:06 +02:00
Dmitry Vyukov d7b34d0b0d msan: disble CHECK test on powerpc64
It seems that CHECK terminates the process with 0 status on powerpc64:
https://reviews.llvm.org/D112440#3084251
Disable the test for now.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112455
2021-10-25 19:38:27 +02:00
Dmitry Vyukov b0a926adac sanitizer_common: trap on CHECK failure
Trapping on CHECK failure makes it more convinient to use with gdb
(no need to set a breakpoint each time). Without a debugger attached
trap should terminate the program as well.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112440
2021-10-25 14:51:41 +02:00
Dmitry Vyukov 75a08b1ba4 tsan: don't use symbol binding 10
Building Go programs with the current runtime fails with:

loadelf: race_linux_amd64: malformed elf file:
_ZZN6__tsan15RestoreAddrImpl5ApplyINS_11MappingGo48EEEmmE6ranges: invalid symbol binding 10

Go linker does not understand ELF in all its generality.
Don't use static const data in inline methods.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D112434
2021-10-25 14:05:15 +02:00
Vitaly Buka fb1c515d3b Revert "[NFC][sanitizer] constexpr a few functions"
This reverts a part of commit 8cd51a69e5
and 5bf24f0581 to fix Windows.
2021-10-24 19:26:55 -07:00
Vitaly Buka 8cd51a69e5 [NFC][sanitizer] Use power of two in TwoLevelMap
Using divisions by non power of two makes
a difference on x86_64 and aarch64 benchmarks.
2021-10-24 18:37:23 -07:00
Vitaly Buka 384ec7dc8c [NFC][sanitizer] DCHECKs in hot code 2021-10-24 18:37:23 -07:00
Vitaly Buka 5bf24f0581 [NFC][sanitizer] constexpr a few functions 2021-10-24 18:37:23 -07:00
Vitaly Buka 850217686e [sanitizer] Remove tag from StackDepotNode
And share storage with size.

Depends on D111615.

Differential Revision: https://reviews.llvm.org/D111616
2021-10-24 13:38:22 -07:00
Vitaly Buka e5859afa9f [sanitizer] Remove use_count from StackDepotNode
This is msan/dfsan data which does not need waste cache
of other sanitizers.

Depends on D111614.

Differential Revision: https://reviews.llvm.org/D111615
2021-10-24 13:38:21 -07:00