Commit Graph

14282 Commits

Author SHA1 Message Date
Ilya Leoshkevich 9bf2e7eeeb [TSan] Add SystemZ SANITIZER_GO support
Define the address ranges (similar to the C/C++ ones, but with the heap
range merged into the app range) and enable the sanity check.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich e34078f121 [TSan] Enable SystemZ support
Enable building the runtime and enable -fsanitize=thread in clang.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich 937242cecc [TSan] Adjust tests for SystemZ
XFAIL map32bit, define the maximum possible allocation size in
mmap_large.cpp.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich bd77f742d6 [TSan] Intercept __tls_get_addr_internal and __tls_get_offset on SystemZ
Reuse the assembly glue code from sanitizer_common_interceptors.inc and
the handling logic from the __tls_get_addr interceptor.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich b17673816d [TSan] Disable __TSAN_HAS_INT128 on SystemZ
SystemZ does not have 128-bit atomics.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich 402fc790eb [TSan] Add SystemZ longjmp support
Implement the interceptor and stack pointer demangling.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Ilya Leoshkevich 96a29df0b1 [TSan] Define C/C++ address ranges for SystemZ
The kernel supports a full 64-bit VMA, but we can use only 48 bits due
to the limitation imposed by SyncVar::GetId(). So define the address
ranges similar to the other architectures, except that the address
space "tail" needs to be made inaccessible in CheckAndProtect(). Since
it's for only one architecture, don't make an abstraction for this.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:47 +02:00
Ilya Leoshkevich fab044045b [TSan] Define PTHREAD_ABI_BASE for SystemZ
SystemZ's glibc symbols use version 2.3.2.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:47 +02:00
Ilya Leoshkevich d5c34ee5b6 [TSan] Build ignore_lib{0,1,5} tests with -fno-builtin
These tests depend on TSan seeing the intercepted memcpy(), so they
break when the compiler chooses the builtin version.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:47 +02:00
Ilya Leoshkevich cadbb92416 [TSan] Align thread_registry_placeholder
s390x requires ThreadRegistry.mtx_.opaque_storage_ to be 4-byte
aligned. Since other architectures may have similar requirements, use
the maximum thread_registry_placeholder alignment from other
sanitizers, which is 64 (LSan).

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:47 +02:00
Ilya Leoshkevich 54128b73f8 [sanitizer] Force TLS allocation on s390
When running with an old glibc, CollectStaticTlsBlocks() calls
__tls_get_addr() in order to force TLS allocation. This function is not
available on s390 and the code simply does nothing in this case,
so all the resulting static TLS blocks end up being incorrect.

Fix by calling __tls_get_offset() on s390.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:47 +02:00
Ilya Leoshkevich acf0a64286 [sanitizer] Fix __sanitizer_kernel_sigset_t endianness issue
setuid(0) hangs on SystemZ under TSan because TSan's BackgroundThread
ignores SIGSETXID. This in turn happens because internal_sigdelset()
messes up the mask bits on big-endian system due to how
__sanitizer_kernel_sigset_t is defined.

Commit d9a1a53b8d ("[ESan] [MIPS] Fix workingset-signal-posix.cpp on
MIPS") fixed this for MIPS by adjusting the __sanitizer_kernel_sigset_t
definition. Generalize this by defining __SANITIZER_KERNEL_NSIG based
on kernel's _NSIG and using uptr[] for __sanitizer_kernel_sigset_t.sig
on all platforms.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:46 +02:00
Vitaly Buka 14362bf1b2 [scudo] Don't enabled MTE for small alignment
Differential Revision: https://reviews.llvm.org/D105954
2021-07-14 12:04:16 -07:00
Dmitry Vyukov dfd9808b6c sanitizer_common: add simpler ThreadRegistry ctor
Currently ThreadRegistry is overcomplicated because of tsan,
it needs tid quarantine and reuse counters. Other sanitizers
don't need that. It also seems that no other sanitizer now
needs max number of threads. Asan used to need 2^24 limit,
but it does not seem to be needed now. Other sanitizers blindly
copy-pasted that without reasons. Lsan also uses quarantine,
but I don't see why that may be potentially needed.

Add a ThreadRegistry ctor that does not require any sizes
and use it in all sanitizers except for tsan.
In preparation for new tsan runtime, which won't need
any of these parameters as well.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D105713
2021-07-13 22:52:25 -07:00
Vitaly Buka 16f8207de3 [sanitizer] Fix type error in python 3 2021-07-13 21:29:14 -07:00
Vitaly Buka 94210b12d1 [sanitizer] Upgrade android scripts to python 3 2021-07-13 20:45:49 -07:00
Vitaly Buka ba127a4570 [sanitizer] Convert script to python 3 2021-07-13 20:39:25 -07:00
Vitaly Buka 35ce66330a [NFC][sanitizer] Simplify MapPackedCounterArrayBuffer 2021-07-13 18:16:28 -07:00
Vitaly Buka ed430023e8 Revert "[NFC][sanitizer] Simplify MapPackedCounterArrayBuffer"
Does not compile.

This reverts commit 8725b382b0.
2021-07-13 17:43:33 -07:00
Vitaly Buka 8725b382b0 [NFC][sanitizer] Simplify MapPackedCounterArrayBuffer 2021-07-13 17:26:07 -07:00
Vitaly Buka 7140382b17 [NFC][sanitizer] Move MemoryMapper template parameter 2021-07-13 16:52:22 -07:00
Dmitry Vyukov 832ba20710 sanitizer_common: optimize memory drain
Currently we allocate MemoryMapper per size class.
MemoryMapper mmap's and munmap's internal buffer.
This results in 50 mmap/munmap calls under the global
allocator mutex. Reuse MemoryMapper and the buffer
for all size classes. This radically reduces number of
mmap/munmap calls. Smaller size classes tend to have
more objects allocated, so it's highly likely that
the buffer allocated for the first size class will
be enough for all subsequent size classes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105778
2021-07-13 16:28:48 -07:00
Vitaly Buka 99aebb62fb [NFC][sanitizer] Don't store region_base_ in MemoryMapper
Part of D105778
2021-07-13 15:59:36 -07:00
Vitaly Buka afa3fedcda [NFC][sanitizer] Exctract DrainHalfMax
Part of D105778
2021-07-13 15:33:22 -07:00
Vitaly Buka 5df9995439 [NFC][sanitizer] Rename some MemoryMapper members
Part of D105778
2021-07-13 15:33:22 -07:00
Vitaly Buka f990da59c5 [sanitizer] Few more NFC changes from D105778 2021-07-13 13:38:13 -07:00
Vitaly Buka 9f1f666b30 [NFC][sanitizer] Move MemoryMapper out of SizeClassAllocator64
Part of D105778
2021-07-13 13:17:36 -07:00
Vitaly Buka d558bfaf8e [NFC][sanitizer] clang-format part of D105778 2021-07-13 13:02:23 -07:00
Vitaly Buka ba8dcaef0d Revert "sanitizer_common: optimize memory drain"
Breaks https://lab.llvm.org/buildbot/#/builders/anitizer-windows

This reverts commit d89d3dfae1.
2021-07-13 12:58:57 -07:00
Vitaly Buka ce25eb0b71 [NFC][sanitizer] Remove trailing whitespace 2021-07-13 11:02:42 -07:00
Vitaly Buka 2bc07083a2 [sanitizer] Fix VSNPrintf %V on Windows 2021-07-13 10:56:17 -07:00
Julian Lettner 1893b630fe Avoid triggering assert when program calls OSAtomicCompareAndSwapLong
A previous change brought the new, relaxed implementation of "on failure
memory ordering" for synchronization primitives in LLVM over to TSan
land [1].  It included the following assert:
```
// 31.7.2.18: "The failure argument shall not be memory_order_release
// nor memory_order_acq_rel". LLVM (2021-05) fallbacks to Monotonic
// (mo_relaxed) when those are used.
CHECK(IsLoadOrder(fmo));

static bool IsLoadOrder(morder mo) {
  return mo == mo_relaxed || mo == mo_consume
      || mo == mo_acquire || mo == mo_seq_cst;
}
```

A previous workaround for a false positive when using an old Darwin
synchronization API assumed this failure mode to be unused and passed a
dummy value [2].  We update this value to `mo_relaxed` which is also the
value used by the actual implementation to avoid triggering the assert.

[1] https://reviews.llvm.org/D99434
[2] https://reviews.llvm.org/D21733

rdar://78122243

Differential Revision: https://reviews.llvm.org/D105844
2021-07-13 09:33:50 -07:00
John Ericson 1e03c37b97 Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0e but had to be reverted in
8cf7ddbdd4.

This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.

One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.

Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).

---

Original message:

Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.

This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.

---

There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.

That last part should be the only behavior changes; everything else
should be a pure refactoring.

---

I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.

[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html

[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options

In 38b2dec37e the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.

---

D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.

Reviewed By: phosek, #libc_abi, #libunwind

Differential Revision: https://reviews.llvm.org/D105765
2021-07-13 15:21:41 +00:00
Rainer Orth 45430983ef [sanitizer_common] Define internal_usleep on Solaris
The Solaris/amd64 buildbot
<https://lab.llvm.org/staging/#/builders/101/builds/2845> has recently been
broken several times, at least one of those remains unfixed:

  [63/446] Generating Sanitizer-x86_64-Test
  [...]
  Undefined			first referenced
   symbol  			    in file
  _ZN11__sanitizer15internal_usleepEy /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/stage1/projects/compiler-rt/lib/sanitizer_common/tests/libRTSanitizerCommon.test.x86_64.a(sanitizer_common.cpp.o)
  ld: fatal: symbol referencing errors

Thist patch fixes it by defining the missing `internal_usleep`.

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

Differential Revision: https://reviews.llvm.org/D105878
2021-07-13 11:15:03 +02:00
Dmitry Vyukov d89d3dfae1 sanitizer_common: optimize memory drain
Currently we allocate MemoryMapper per size class.
MemoryMapper mmap's and munmap's internal buffer.
This results in 50 mmap/munmap calls under the global
allocator mutex. Reuse MemoryMapper and the buffer
for all size classes. This radically reduces number of
mmap/munmap calls. Smaller size classes tend to have
more objects allocated, so it's highly likely that
the buffer allocated for the first size class will
be enough for all subsequent size classes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105778
2021-07-13 10:02:23 +02:00
Vitaly Buka c41e67f3f1 [NFC][scudo] Clang format a file 2021-07-12 22:26:54 -07:00
Vitaly Buka b8424b42a5 Revert "[hwasan] More realistic setjmp test."
Breaks https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-qemu

This reverts commit 5511bfdb67.
2021-07-12 22:16:25 -07:00
Leonard Chan 189c552518 [compiler-rt][hwasan] Refactor kAliasRegionStart usage
This moves logic for setting kAliasRegionStart into hwasan_allocator.cpp
so other platforms that do not support aliasing mode will not need to define
kAliasRegionStart.

Differential Revision: https://reviews.llvm.org/D105725
2021-07-12 16:33:05 -07:00
Marco Elver 98033fdc50 sanitizer_common: Fix build for tests
It turns out that COMPILER_RT_TEST_COMPILER_CFLAGS is actually a string
that is being appended to and not a list.

Therefore, append the thread-safety flags to the string. Because CMake
separates list elements by ';' when turning into a string, also
substitute ';' with ' '.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D105829
2021-07-12 15:49:40 -07:00
Vitaly Buka b4a6fa12d1 Revert "sanitizer_common: add simpler ThreadRegistry ctor"
Breaks https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-android

This reverts commit 6062c672bc.
This reverts commit 8e489b4b96.
2021-07-12 12:04:12 -07:00
Nikita Popov 97661b8634 Revert "sanitizer_common: optimize memory drain"
This reverts commit 0726695214.

This causes the following build failure with gcc 10.3.0:

/home/nikic/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h:114:31: error: declaration of ‘typedef class __sanitizer::MemoryMapper<__sanitizer::SizeClassAllocator64<Params> > __sanitizer::SizeClassAllocator64<Params>::MemoryMapper’ changes meaning of ‘MemoryMapper’ [-fpermissive]
  114 |   typedef MemoryMapper<ThisT> MemoryMapper;
2021-07-12 20:28:28 +02:00
Dmitry Vyukov 0726695214 sanitizer_common: optimize memory drain
Currently we allocate MemoryMapper per size class.
MemoryMapper mmap's and munmap's internal buffer.
This results in 50 mmap/munmap calls under the global
allocator mutex. Reuse MemoryMapper and the buffer
for all size classes. This radically reduces number of
mmap/munmap calls. Smaller size classes tend to have
more objects allocated, so it's highly likely that
the buffer allocated for the first size class will
be enough for all subsequent size classes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105778
2021-07-12 19:21:15 +02:00
Leonard Chan b270c3fbde [NFC][compiler-rt][hwasan] Move shadow bound variables to hwasan.cpp
This way, other platforms can define these values.

Differential Revision: https://reviews.llvm.org/D105744
2021-07-12 10:16:28 -07:00
Benjamin Kramer 6f6131815e sanitizer_common: Suppress another thread safety warning
Another follow-up to 0da172b176

compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'CandidateTSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:95:21: note: mutex acquired here
      CandidateTSD->lock();
                    ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:101:8: note: mutex acquired here
  TSD->lock();
       ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSDs[Index].Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:80:23: note: mutex acquired here
      if (TSDs[Index].tryLock()) {
                      ^
2021-07-12 17:57:42 +02:00
Benjamin Kramer 561b9446d6 sanitizer_common: Fix the build for platforms that use shared TSDs
Looks like an oversight in 0da172b176

compiler-rt/lib/scudo/scudo_tsd_shared.inc:53:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.inc:49:12: note: mutex acquired here
  if (TSD->tryLock())
           ^
2021-07-12 17:49:48 +02:00
Dmitry Vyukov 6ca7247866 sanitizer_common: support printing __m128i type
__m128i is vector SSE type used in tsan.
It's handy to be able to print it for debugging.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102167
2021-07-12 16:12:46 +02:00
Dmitry Vyukov b3bd885017 sanitizer_common: allow COMMON_INTERCEPTOR_ENTER to use labels
The memcpy interceptor is the only one that uses COMMON_INTERCEPTOR_ENTER
more than once in a single function. This does not allow COMMON_INTERCEPTOR_ENTER
to use labels, because they are global for the whole function (not block scoped).
Don't include COMMON_INTERCEPTOR_ENTER code twice.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105774
2021-07-12 15:54:37 +02:00
Dmitry Vyukov 10158b52dc sanitizer_common: fix 32-bit build
https://reviews.llvm.org/D105716 enabled thread safety annotations,
and that broke 32-bit build:
https://green.lab.llvm.org/green/job/lldb-cmake/33604/consoleFull#-77815080549ba4694-19c4-4d7e-bec5-911270d8a58c

1. Enable thread-safety analysis in unit tests
(this catches the breakage even in 64-bit mode).
2. Add NO_THREAD_SAFETY_ANALYSIS to sanitizer_allocator_primary32.h
to unbreak the build.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105808
2021-07-12 14:03:13 +02:00
Dmitry Vyukov 8bbf2f7a44 sanitizer_common: make sem_trywait as non-blocking
sem_trywait never blocks.
Use REAL instead of COMMON_INTERCEPTOR_BLOCK_REAL.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105775
2021-07-12 13:10:04 +02:00
Dmitry Vyukov fde34d9f89 sanitizer_common: remove debugging logic from the internal allocator
The internal allocator adds 8-byte header for debugging purposes.
The problem with it is that it's not possible to allocate nicely-sized
objects without a significant overhead. For example, if we allocate
512-byte objects, that will be rounded up to 768 or something.
This logic migrated from tsan where it was added during initial development,
I don't remember that it ever caught anything (we don't do bugs!).
Remove it so that it's possible to allocate nicely-sized objects
without overheads.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105777
2021-07-12 13:02:38 +02:00