llvm-project/compiler-rt/lib/tsan/rtl
Fangrui Song 7afdc89c20 [sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature detection and support musl
Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are replaced
with the more appropriate `#if SANITIZER_GLIBC` (the headers are glibc
extensions, not specific to Linux (i.e. if we ever support GNU/kFreeBSD
or Hurd, the guards may automatically work)).

Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are refined
with `#if SANITIZER_GLIBC` (the definitions are available on Linux glibc,
but may not be available on other libc (e.g. musl) implementations).

This patch makes `ninja asan cfi lsan msan stats tsan ubsan xray` build on a musl based Linux distribution (apk install musl-libintl)
Notes about disabled interceptors for musl:

* `SANITIZER_INTERCEPT_GLOB`: musl does not implement `GLOB_ALTDIRFUNC` (GNU extension)
* Some ioctl structs and functions operating on them.
* `SANITIZER_INTERCEPT___PRINTF_CHK`: `_FORTIFY_SOURCE` functions are GNU extension
* `SANITIZER_INTERCEPT___STRNDUP`: `dlsym(RTLD_NEXT, "__strndup")` errors so a diagnostic is formed. The diagnostic uses `write` which hasn't been intercepted => SIGSEGV
* `SANITIZER_INTERCEPT_*64`: the `_LARGEFILE64_SOURCE` functions are glibc specific. musl does something like `#define pread64 pread`
* Disabled `msg_iovlen msg_controllen cmsg_len` checks: musl is conforming while many implementations (Linux/FreeBSD/NetBSD/Solaris) are non-conforming. Since we pick the glibc definition, exclude the checks for musl (incompatible sizes but compatible offsets)

Pass through LIBCXX_HAS_MUSL_LIBC to make check-msan/check-tsan able to build libc++ (https://bugs.llvm.org/show_bug.cgi?id=48618).

Many sanitizer features are available now.

```
% ninja check-asan
(known issues:
* ASAN_OPTIONS=fast_unwind_on_malloc=0 odr-violations hangs
)
...
Testing Time: 53.69s
  Unsupported      : 185
  Passed           : 512
  Expectedly Failed:   1
  Failed           :  12

% ninja check-ubsan check-ubsan-minimal check-memprof # all passed

% ninja check-cfi
( all cross-dso/)
...
Testing Time: 8.68s
  Unsupported      : 264
  Passed           :  80
  Expectedly Failed:   8
  Failed           :  32

% ninja check-lsan
(With GetTls (D93972), 10 failures)
Testing Time: 4.09s
  Unsupported:  7
  Passed     : 65
  Failed     : 22

% ninja check-msan
(Many are due to functions not marked unsupported.)
Testing Time: 23.09s
  Unsupported      :   6
  Passed           : 764
  Expectedly Failed:   2
  Failed           :  58

% ninja check-tsan
Testing Time: 23.21s
  Unsupported      :  86
  Passed           : 295
  Expectedly Failed:   1
  Failed           :  25
```

Used `ASAN_OPTIONS=verbosity=2` to verify there is no unneeded interceptor.

Partly based on Jari Ronkainen's https://reviews.llvm.org/D63785#1921014

Note: we need to place `_FILE_OFFSET_BITS` above `#include "sanitizer_platform.h"` to avoid `#define __USE_FILE_OFFSET64 1` in 32-bit ARM `features.h`

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D93848
2021-01-06 10:55:40 -08:00
..
tsan.syms.extra [compiler-rt][tsan] Make fiber support in thread sanitizer dynamic linkable 2020-03-11 14:14:33 +01:00
tsan_clock.cpp tsan: fix false positives in AcquireGlobal 2020-05-27 16:27:47 +02:00
tsan_clock.h tsan: fix false positives in AcquireGlobal 2020-05-27 16:27:47 +02:00
tsan_debugging.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_defs.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_dense_alloc.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_dispatch_defs.h [TSan][libdispatch] Ensure TSan dylib works on old systems 2020-08-18 18:34:14 -07:00
tsan_external.cpp [tsan] On arm64e, strip out ptrauth bits from incoming PCs 2020-08-25 11:59:36 -07:00
tsan_fd.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_fd.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_flags.cpp [sanitizers] Remove unneeded MaybeCall*DefaultOptions() and nullptr checks 2020-09-08 10:12:05 -07:00
tsan_flags.h Improve error message when '=' is missing in {ASAN,...}_OPTIONS. 2019-06-15 01:37:14 +00:00
tsan_flags.inc [TSan] Revert removal of ignore_interceptors_accesses flag 2020-06-08 12:35:43 -07:00
tsan_ignoreset.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_ignoreset.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_interceptors.h [compiler-rt] Replace INLINE with inline 2020-09-17 16:24:20 +02:00
tsan_interceptors_libdispatch.cpp [TSan][libdispatch] Fix compilation error on Linux 2020-09-02 11:20:47 -07:00
tsan_interceptors_mac.cpp [sanitizer][Darwin] Suppress -Wno-non-virtual-dtor warning 2021-01-05 17:09:18 -08:00
tsan_interceptors_mach_vm.cpp [TSan][Darwin] Handle NULL argument in interceptor 2020-08-24 11:36:02 -07:00
tsan_interceptors_posix.cpp [sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature detection and support musl 2021-01-06 10:55:40 -08:00
tsan_interface.cpp [compiler-rt][tsan] Remove unnecesary typedefs 2020-08-28 18:43:54 -07:00
tsan_interface.h [TSAN] Add read/write range interface functions with PC 2019-09-24 11:19:02 +00:00
tsan_interface_ann.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_interface_ann.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_interface_atomic.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_interface_inl.h [tsan] On arm64e, strip out ptrauth bits from incoming PCs 2020-08-25 11:59:36 -07:00
tsan_interface_java.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_interface_java.h Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_malloc_mac.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_md5.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_mman.cpp [sanitizer_common] Create max_allocation_size_mb flag. 2019-10-30 11:26:05 -07:00
tsan_mman.h Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_mutex.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_mutex.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_mutexset.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_mutexset.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_new_delete.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_platform.h [NFC][tsan] Simplify call_pthread_cancel_with_cleanup 2020-11-16 04:21:27 -08:00
tsan_platform_linux.cpp [NFC][tsan] Simplify call_pthread_cancel_with_cleanup 2020-11-16 04:21:27 -08:00
tsan_platform_mac.cpp [NFC][tsan] Simplify call_pthread_cancel_with_cleanup 2020-11-16 04:21:27 -08:00
tsan_platform_posix.cpp [NFC] Remove unused function. 2020-08-13 21:20:15 -04:00
tsan_platform_windows.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_ppc_regs.h
tsan_preinit.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_report.cpp [sanitizer] Convert PrintModuleMap to DumpProcessMap 2020-10-21 12:46:49 -07:00
tsan_report.h sanitizers: Introduce ThreadType enum 2019-02-07 11:01:22 +00:00
tsan_rtl.cpp [sanitizer] Convert PrintModuleMap to DumpProcessMap 2020-10-21 12:46:49 -07:00
tsan_rtl.h [sanitizer] Make destructors protected 2020-11-02 18:00:43 -08:00
tsan_rtl_aarch64.S [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.6 2019-07-16 20:41:04 +00:00
tsan_rtl_amd64.S Revert "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.4" 2019-07-05 21:03:46 +00:00
tsan_rtl_mips64.S
tsan_rtl_mutex.cpp [sanitizer] Cleanup -Wnon-virtual-dtor warnings 2020-11-02 20:30:50 -08:00
tsan_rtl_ppc64.S
tsan_rtl_proc.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_rtl_report.cpp [sanitizer][NFC] Fix few cpplint warnings 2020-10-13 20:39:37 -07:00
tsan_rtl_thread.cpp tsan: fix leak of ThreadSignalContext memory mapping when destroying fibers 2020-04-11 10:30:31 +02:00
tsan_stack_trace.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_stack_trace.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_stat.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_stat.h tsan: Adding releaseAcquire() to ThreadClock 2020-03-24 11:27:46 +01:00
tsan_suppressions.cpp Remove NOLINTs from compiler-rt 2019-09-11 23:19:48 +00:00
tsan_suppressions.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_symbolize.cpp compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp 2019-08-01 14:22:42 +00:00
tsan_symbolize.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_sync.cpp [tsan] Respect no_huge_pages_for_shadow. 2020-08-13 15:55:23 -04:00
tsan_sync.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_trace.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
tsan_update_shadow_word_inl.h tsan: Optimize performance of Thread sanitizer memory access functions 2019-02-07 12:43:09 +00:00