Commit Graph

14534 Commits

Author SHA1 Message Date
Fangrui Song c520863abb [crt][test] Make ctor_dtor.c robust if DT_INIT/DT_FINI is disabled
New ports in glibc typically don't define ELF_INITFINI, so
DT_INIT/DT_FINI support is disabled.
(rhel ppc64le likely patches their glibc this way as well.)
musl can disable DT_INIT/DT_FINI via -DNO_LEGACY_INITFINI.

So we cannot guarantee ctor()/dtor() will be printed.
2021-08-12 09:31:31 -07:00
Dmitry Vyukov 62139c5b25 tsan: remove implicit memcpy in MutexSet::Desc::operator=()
The default compiler-generated MutexSet::Desc::operator=()
now contains memcpy() call since Desc become bigger.
This fails in debug mode since we call interceptor from within the runtime.
Define own operator=() using internal_memcpy().
This also makes copy ctor necessary, otherwise:
tsan_mutexset.h:33:11: warning: definition of implicit copy constructor for
'Desc' is deprecated because it has a user-declared copy assignment operator
And if we add copy ctor, we also need the default ctor
since it's called by MutexSet ctor.

Depends on D107911.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107959
2021-08-12 15:10:05 +02:00
Dmitry Vyukov d9afba9000 tsan: extend MutexSet to memorize mutex address/stack_id
We currently memorize u64 id + epoch for each mutex.
The new tsan runtime will memorize address + stack_id instead.
But switching to address + stack_id requires new trace,
which in turn requires new MutexSet and some other changes.
Extend MutexSet to support both new and old info to break
the dependency cycles. The plan is to remove the old
info/methods after switching to the new runtime.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D107910
2021-08-12 13:18:43 +02:00
David Spickett d4b193ca64 [compiler-rt][fuzzer] Mark flags test unsupported on AArch64 Linux
Previously I xfailed this but it's only failing in stage 2 so
we get xpasses for stage 1. Disable it completely.
2021-08-12 08:25:47 +00:00
Dmitry Vyukov 645f5890ec tsan: fix build breakage due to AppMemBeg
AppMemBeg was renamed to LoAppMemBeg in 3830c93478
("tsan: rename kAppMemBeg to kLoAppMemBeg").
Rename remaining uses of the old name in tsan_platform_mac.cpp.

Differential Revision: https://reviews.llvm.org/D107948
2021-08-12 08:18:09 +02:00
Fangrui Song d54c62cc32 [profile][test] Add -no-pie to make value profile merge work on Linux with default PIE
Alpine enables PIE by default.
2021-08-11 22:41:52 -07:00
Daniel Kolesa b7611ad0b1 [CMake] Enable clang_rt.crt{begin,end} on ppc32/ppc64 2021-08-11 18:25:41 -07:00
Mitch Phillips 32adf108c8 [scudo] Add GWP-ASan state/metadata pointer proxies.
Provide accessor proxies for the gwp-asan regions that are useful in
symbolizing dumps offline. Should be useful for Fuchsia to be able to
locate these internal pointers to stash the data in a minidump.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D107909
2021-08-11 09:21:48 -07:00
David Spickett 683147ff11 [compiler-rt][fuzzer] Xfail flags test on AArch64 Linux
This fails with:
/tmp/FlagsTest-5761bc.o: In function `sancov.module_ctor_8bit_counters':
FlagsTest.cpp:(.text.sancov.module_ctor_8bit_counters[sancov.module_ctor_8bit_counters]+0x14): undefined reference to `__start___sancov_cntrs'
FlagsTest.cpp:(.text.sancov.module_ctor_8bit_counters[sancov.module_ctor_8bit_counters]+0x18): undefined reference to `__stop___sancov_cntrs'
<...>

Since https://reviews.llvm.org/D107374. However the changes
there don't seem to be the real fault so xfail while I look into it.
2021-08-11 13:53:18 +00:00
Dmitry Vyukov 9af6156c52 tsan: fix active mapping selection
Fix bug introduced by commit 5d106f16b9.
SANITIZER_IOSSIM is always defined,
it's the value 0/1 that's meaningful.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D107888
2021-08-11 13:03:16 +02:00
Florian Mayer ab41f37ef6 [hwasan] Fix test with TCO eliminating free frame.
This broke https://lab.llvm.org/buildbot/#/builders/37/builds/6016/steps/10/logs/stdio

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D107864
2021-08-11 09:51:14 +01:00
Dmitry Vyukov 8af4725576 tsan: fix Printf format string
Reported on D107745

Reported-by: Wolfgang Pieb (wolfgangp)

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107881
2021-08-11 10:22:02 +02:00
Dmitry Vyukov 8233c343ad tsan: add notion of compressed addresses
New tsan runtime will need to compress addresses/PCs to fewer bits.
Add CompressAddr/RestoreAddr functions that compress/restore
addresses to 44 bits.

Depends on D107744.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107745
2021-08-10 20:09:16 +02:00
Dmitry Vyukov 1d9be7b4fa tsan: rename mapping field selectors
Rename mapping field selectors according to the code style.
Reuse the actual field names, there is no need to invent
second set of names.

Depends on D107743.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107744
2021-08-10 20:08:07 +02:00
Dmitry Vyukov 5d106f16b9 tsan: remove indirection when selecting the active mapping
Currently there are 2 levels when selecting the active mapping:
the branchy ifdef tree + another ifdef tree in SelectMapping.
Moreover, there is an additional indirection for some platforms
via HAS_48_BIT_ADDRESS_SPACE define. This makes already complex
logic even more complex and almost impossible to read.
Remove one level of indirection and define the active mapping
in SelectMapping.

Depends on D107742.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107743
2021-08-10 20:07:31 +02:00
Dmitry Vyukov 959076c596 tsan: remove dependencies on HAS_48_BIT_ADDRESS_SPACE and Mapping
Remove direct uses of Mapping in preperation for removing Mapping type
(which we already don't have for all platforms).
Remove dependence on HAS_48_BIT_ADDRESS_SPACE in preparation for removing it.
As far as I see for Apple/Mac platforms !HAS_48_BIT_ADDRESS_SPACE
simply means SANITIZER_IOS.

Depends on D107741.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107742
2021-08-10 20:07:23 +02:00
Dmitry Vyukov 0ebfe7c312 tsan: unit-test all mappings
Move the mapping checking logic from startup to unit tests
and test all mapping instead of just the active one.
This makes it much more feasible to make any global changes
to the mappings since we have 17 of them.

Depends on D107740.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D107741
2021-08-10 20:07:15 +02:00
Dmitry Vyukov 62c340760c tsan: unify all shadow mappings
Currently we have ifdef's for Go/C++ and Windows/non-Windows
in MemToShadow, MemToMeta, ShadowToMem. This does not allow
to test all mappings on a single platform.
Make all these functions support a superset of mappings for
all platforms by defining missing mapping consts to 0.
E.g. we always do ^A+B, but if A and B are defined to 0,
then these operations become no-op.

Depends on D107739.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107740
2021-08-10 20:07:04 +02:00
Dmitry Vyukov fd50600733 tsan: define all fields for all mappings
Define all fields to 0 for all mappings.
This allows to write portable code and tests.
For all existing cases 0 values work out of the box
because we check if an address belongs to the range
and nothing belongs to [0, 0] range.

Depends on D107738.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107739
2021-08-10 20:05:14 +02:00
Dmitry Vyukov 3830c93478 tsan: rename kAppMemBeg to kLoAppMemBeg
Unify Go mapping naming with C++ naming to allow
writing portable code/tests that can work for both C++ and Go.
No functional changes.

Depends on D107737.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107738
2021-08-10 20:05:00 +02:00
Dmitry Vyukov fda121a9cc tsan: remove TSAN_MID_APP_RANGE macro
First, the define conflicts with definition/testing of all mappings,
since it's not a global property anymore. Second, macros/ifdefs are bad.
Define kMidAppMemBeg/End to 0 to denote that there is no "mid" range instead.

Depends on D107736.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107737
2021-08-10 20:04:44 +02:00
Dmitry Vyukov a44a873e11 sanitizer_common: add FALLTHROUGH macro
Add FALLTHROUGH portably defined to [[clang::fallthrough]].
We have -Wimplicit-fallthrough already enabled, and currently
it's not possible to fix the warning.

Depends on D107735.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107736
2021-08-10 20:04:37 +02:00
Dmitry Vyukov 3cb4ed72e7 tsan: deduplicate mapping selection
Currently we have mapping selection duplicated 9 times.
Deduplicate it. No functional changes.

Depends on D107734.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107735
2021-08-10 20:04:11 +02:00
Dmitry Vyukov 470f063720 tsan: make all memory mappings testable
Currently we define/compile the mapping for a platform
only on that platform. This makes it impossible to unit-test
them on a single platform, and even to build test.
We have 17 of them and the Go mappings will be tested
only after a manual episodic update of the Go runtime.

Define all mappings always with unique names.
This will allow to unit-test them.
No functional changes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107734
2021-08-10 20:04:02 +02:00
Dmitry Vyukov 2f6ac22b08 sanitizers: turn thread-safety errors into warnings
There were 2 issues reported on https://reviews.llvm.org/D105716:
1. FreeBSD phtread.h is annotated with thread-safety attributes
and this causes errors in gtest headers.
2. If sanitizers are compiled with an older versions of clang
(which supports the annotations, but has some false positives
in analysis not present in later versions of clang), compilation
fails with errors.

Switch the errors to warnings by default.
Some CI bots enable COMPILER_RT_ENABLE_WERROR, which should
turn these warnings back into errors.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D107826
2021-08-10 20:03:30 +02:00
Dmitry Vyukov 1fa4c188b5 sanitizer_common: optimize Mutex for high contention
After switching tsan from the old mutex to the new sanitizer_common mutex,
we've observed a significant degradation of performance on a test.
The test effectively stresses a lock-free stack with 4 threads
with a mix of atomic_compare_exchange and atomic_load operations.
The former takes write lock, while the latter takes read lock.
It turned out the new mutex performs worse because readers don't
use active spinning, which results in significant amount of thread
blocking/unblocking. The old tsan mutex used active spinning
for both writers and readers.

Add active spinning for readers.
Don't hand off the mutex to readers, and instread make them
compete for the mutex after wake up again.
This makes readers and writers almost symmetric.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107824
2021-08-10 20:03:07 +02:00
Dmitry Vyukov faef0d042f Problem with realpath interceptor
tsan in some cases (e.g. after fork from multithreaded program, which arguably is problematic) increments ignore_interceptors and in that case runs just the intercepted functions and not their wrappers.
For realpath the interceptor handles the resolved_path == nullptr case though and so when ignore_interceptors is non-zero, realpath (".", nullptr) will fail instead of succeeding.
This patch uses instead the COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN macro to use realpath@@GLIBC_2.3 whenever possible (if not, then it is likely a glibc architecture
with more recent oldest symbol version than 2.3, for which any realpath in glibc will DTRT, or unsupported glibc older than 2.3), which never supported NULL as second argument.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D107819
2021-08-10 16:29:42 +02:00
Florian Mayer be59a332eb [hwasan] Fix test on x86.
Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D107816
2021-08-10 13:06:12 +01:00
Lang Hames a3290ea156 [ORC-RT] Fix typo in path in f63b1bf7f4.
rdar://81056700
2021-08-10 21:04:44 +10:00
Lang Hames f63b1bf7f4 [ORC-RT] Include TLV support in x86-64 Haswell slice.
Darwin/MachO TLV support was only getting built into the x86_64 slice, not the
x86_64h slice. This caused errors when using the ORC runtime on Haswell
machines.

rdar://81056700
2021-08-10 21:01:40 +10:00
Florian Mayer 6794593fdb [hwasan] State correct PC in first error message.
We would put the return address there, rather than the fault address.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D107578
2021-08-10 09:29:29 +01:00
Vitaly Buka 0831f8bf79 [NFC] Fix typo in comment 2021-08-10 01:11:42 -07:00
Vitaly Buka f33d51d592 [sanitizer] Intercept sem_open/sem_unlink
Without interceptor implementation may call strlen on internal
buffers causing false msan errors.

Differential Revision: https://reviews.llvm.org/D107615
2021-08-10 01:11:16 -07:00
Paul Robinson a5915f983c Revert "[compiler-rt] Speculative fix for cross_over_uniform_dist.test"
This reverts commit dc11e69dd4.
The speculative fix did not help.
2021-08-09 12:14:57 -07:00
Florian Mayer 9b74924b6c Revert "[sanitizer] Intercept sem_open/sem_unlink"
This reverts commit 69a909b9fe.
2021-08-09 19:50:31 +01:00
Vitaly Buka 69a909b9fe [sanitizer] Intercept sem_open/sem_unlink
Without interceptor implementation may call strlen on internal
buffers causing false msan errors.

Differential Revision: https://reviews.llvm.org/D107615
2021-08-09 10:57:23 -07:00
Paul Robinson dc11e69dd4 [compiler-rt] Speculative fix for cross_over_uniform_dist.test
This change makes the REQUIRES clause unambiguously use triple-relative
feature names, in case that helps fix the bot failure seen at
https://lab.llvm.org/buildbot/#/builders/37/builds/5998
2021-08-09 10:20:05 -07:00
Paul Robinson a2acac68eb Have compiler-rt/test/fuzzer report info to help diagnose a test issue 2021-08-09 05:11:27 -07:00
Martin Storsjö 94c001d646 [profile] Build with -fms-extensions in MinGW mode
54902e00d1 added a use of
/alternatename via a #pragma comment(linker); in MinGW mode, this
requires building with -fms-extensions. (This flag is added to
SANITIZER_COMMON_CFLAGS in the toplevel CMakeLists.txt.)

This avoids a warning when building in MinGW mode (about an unknown
pragma being ignored), and presumably also makes the code work as
intended.

Differential Revision: https://reviews.llvm.org/D107620
2021-08-09 11:39:11 +03:00
Martin Storsjö 743f78ef7f [InstrProfiling] Fix warnings when building for Windows
The Headers.CountersDelta field is an uint64_t, not a pointer,
so just cast to uint32_t to truncate it.

Differential Revision: https://reviews.llvm.org/D107619
2021-08-09 11:39:11 +03:00
Roland McGrath 5a2a179695 [profile][Fuchsia] Add missing system header #include
The _zx_vmar_root_self function is not a system call but
a libc function declared in a separate header.

Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D107616
2021-08-06 17:59:35 -07:00
Zequan Wu 2129c4a861 Fix Windows bots failure caused by 8c4208d5c1 2021-08-06 15:03:00 -07:00
Zequan Wu 8c4208d5c1 [Profile][NFC] Clean up initializeProfileForContinuousMode
Merge two versions of `initializeProfileForContinuousMode` function into one.

Differential Revision: https://reviews.llvm.org/D107591
2021-08-06 14:00:36 -07:00
Petr Hosek f59f659879 [CMake] Check the builtins library value first
When the builtins library isn't found, find_compiler_rt_library
returns NOTFOUND so we'll end up linking against -lNOTFOUND. We need
to check the return value before adding it to the list.

Differential Revision: https://reviews.llvm.org/D107627
2021-08-06 10:59:24 -07:00
Paul Robinson e4cc071e92 Disable a dataflow fuzz test after "Have REQUIRES support the target triple"
See: https://lab.llvm.org/buildbot/#/builders/75/builds/8095/steps/8/logs/stdio

which shows:
unsupported option '-fsanitize=dataflow' for target 'i386-unknown-linux-gnu'

The other dataflow tests in the same directory were already disabled,
so I think it's fine to disable this one as well.
2021-08-06 09:14:39 -07:00
Rainer Orth 779714f89b [profile] Only use NT_GNU_BUILD_ID if supported
The Solaris buildbots have been broken for some time by the unconditional
use of `NT_GNU_BUILD_ID`, e.g. Solaris/sparcv9
<https://lab.llvm.org/staging/#/builders/50/builds/4910> and Solaris/amd64
<https://lab.llvm.org/staging/#/builders/101/builds/3751>.  Being a GNU
extension, it is not defined in `<sys/elf.h>`.  However, providing a
fallback definition doesn't help because the code also relies on
`__ehdr_start`, another unportable GNU extension that most likely never
will be implemented in Solaris `ld`.  Besides, there's reallly no point in
supporting build ids since they aren't used on Solaris at all.

This patch fixes this by making the relevant code conditional on the
definition of `NT_GNU_BUILD_ID`.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D107556
2021-08-06 14:04:11 +02:00
Martin Storsjö ab737d5367 [fuzzer] Fix building on case sensitive mingw platforms
Include windows.h with an all lowercase filename; Windows SDK headers
aren't self consistent so they can't be used in an entirely
case sensitive setting, and mingw headers use all lowercase names
for such headers.

This fixes building after 881faf4190.
2021-08-06 08:53:13 +03:00
Vitaly Buka 7138f1cd13 [NFC][sanitizer] clang-format sem related block 2021-08-05 19:51:19 -07:00
Vitaly Buka c2a3fb303f [msan] Don't track origns in signal handlers
Origin::CreateHeapOrigin is not async-signal-safe and can deadlock.

Differential Revision: https://reviews.llvm.org/D107431
2021-08-05 13:53:20 -07:00
Matt Morehouse 7ca2b9aac7 [libFuzzer] Add missing include on Darwin. 2021-08-05 12:27:13 -07:00