Commit Graph

10255 Commits

Author SHA1 Message Date
Jianzhou Zhao 0f3fd3b281 [dfsan] Add thread registration
This is a part of https://reviews.llvm.org/D95835.

This change is to address two problems
1) When recording stacks in origin tracking, libunwind is not async signal safe. Inside signal callbacks, we need
to use fast unwind. Fast unwind needs threads
2) StackDepot used by origin tracking is not async signal safe, we set a flag per thread inside
a signal callback to prevent from using it.

The thread registration is similar to ASan and MSan.

Related MSan changes are
* 98f5ea0dba
* f653cda269
* 5a7c364343

Some changes in the diff are used in the next diffs
1) The test case pthread.c is not very interesting for now. It will be
  extended to test origin tracking later.
2) DFsanThread::InSignalHandler will be used by origin tracking later.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D95963
2021-02-05 17:38:59 +00:00
Emily Shi 039567b664 [Darwin] Switch to new logging api for sanitizers
Switch to new logging api added in [[ https://developer.apple.com/documentation/os/os_log_error | macOS 10.12 ]] that is more memory safe and enables us to label the log messages in the future. Falls back to old API if ran on older OS versions.

Commited by Dan Liew on behalf of Emily Shi.

rdar://25181524

Reviewed By: delcypher, yln

Differential Revision: https://reviews.llvm.org/D95977
2021-02-04 21:04:51 -08:00
Amy Huang 9ba623c655 [asan] Add %d variable to external_symbolizer_path option, so that user can specify paths relative to the location of the binary.
We want way to set a path to llvm-symbolizer that isn't relative
to the current working directory; this change adds a variable that
expands to the path relative to the current binary.
This approach came from comments in https://reviews.llvm.org/D93070

Differential Revision: https://reviews.llvm.org/D94563
2021-02-04 15:43:02 -08:00
Bill Torpey dd5c2b8de9 [sanitizer] Add suffix to report file name
For those using a GUI, it can be very helpful to have a
particular suffix appended to the report file name, so
it can be opened with a double-click.

(see also: https://github.com/google/sanitizers/issues/951)

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D46546
2021-02-04 13:50:11 -08:00
Vitaly Buka 9da05cf6ed [asan] Fix pthread_create interceptor
AsanThread::Destroy implementation expected to be called on
child thread.

I missed authors concern regarding this reviewing D95184.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D95731
2021-02-03 12:57:56 -08:00
Jianzhou Zhao 15f26c5f51 [dfsan] Wrap strcat
Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D95923
2021-02-03 18:50:29 +00:00
Roland McGrath 15aa78abb6 [sanitizer_common] Use zx_system_get_page_size() on Fuchsia
Fuchsia is migrating to a variable page size.

Reviewed By: phosek, charco

Differential Revision: https://reviews.llvm.org/D95919
2021-02-03 10:45:46 -08:00
Roland McGrath 09fe23a61c [gwp_asan] Use zx_system_get_page_size() on Fuchsia
Fuchsia is migrating to a variable page size.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D95920
2021-02-03 10:35:07 -08:00
Roland McGrath d81069e796 [scudo/standalone] Use zx_system_get_page_size() on Fuchsia
Fuchsia is migrating to a variable page size.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D95921
2021-02-03 10:28:05 -08:00
Jianzhou Zhao 93afc3452c [dfsan] Clean TLS after signal callbacks
Similar to https://reviews.llvm.org/D95642, this diff fixes signal.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D95896
2021-02-03 17:21:28 +00:00
Jianzhou Zhao 3f568e1fbb [dfsan] Wrap memmove
Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D95883
2021-02-03 05:15:56 +00:00
Mitch Phillips 0dcf3324cf Revert "[GWP-ASan] Add aligned allocations."
This reverts commit 9dc0676247.

Should not have been committed, was a bad rebase. Review still
continuing on D94830.
2021-02-02 14:46:25 -08:00
Mitch Phillips 30973f6fe0 [GWP-ASan] Add locking around unwinder for atfork protection.
Unwinders (like libc's backtrace()) can call their own locks (like the
libdl lock). We need to let the unwinder release the locks before
forking. Wrap a new lock around the unwinder for atfork protection.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D95889
2021-02-02 14:44:35 -08:00
Mitch Phillips 9dc0676247 [GWP-ASan] Add aligned allocations.
Adds a new allocation API to GWP-ASan that handles size+alignment
restrictions.

Differential Revision: https://reviews.llvm.org/D94830
2021-02-02 14:44:35 -08:00
Jianzhou Zhao e1a4322f81 [dfsan] Clean TLS after sigaction callbacks
DFSan uses TLS to pass metadata of arguments and return values. When an
instrumented function accesses the TLS, if a signal callback happens, and
the callback calls other instrumented functions with updating the same TLS,
the TLS is in an inconsistent state after the callback ends. This may cause
either under-tainting or over-tainting.

This fix follows MSan's workaround.
  cb22c67a21
It simply resets TLS at restore. This prevents from over-tainting. Although
under-tainting may still happen, a taint flow can be found eventually if we
run a DFSan-instrumented program multiple times. The alternative option is
saving the entire TLS. However the TLS storage takes 2k bytes, and signal calls
could be nested. So it does not seem worth.

This diff fixes sigaction. A following diff will be fixing signal.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D95642
2021-02-02 22:07:17 +00:00
Erik Pilkington 5f3c4923e4 [compiler-rt] Fix AArch64 out-of-line atomics visibility on mach-o
This fixes an apparent oversight in D91156, where the symbol was defined
without the leading underscore, then the visibility was later declared with it.
rdar://73364185

Differential revision: https://reviews.llvm.org/D95639
2021-02-01 11:29:20 -05:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
Luís Marques 68e5614b42 [Sanitizer][RISCV] Fix FastUnwindTest
Fixes the `FastUnwindTest` unit test for RISC-V.
These changes reflect the different stack organization commonly used for
that architecture.

Differential Revision: https://reviews.llvm.org/D90574
2021-02-01 00:00:15 +00:00
Luís Marques 2de4f19ecd [LSan][RISCV] Enable LSan for RISCV64
Fixes the broken RISCV64 implementation of `internal_clone` and
adds RISCV64 support for LSan.

Differential Revision: https://reviews.llvm.org/D92403
2021-01-31 21:53:25 +00:00
Harald van Dijk b01b964d37
[compiler-rt][tests] Define TARGET_FLAGS
D36116 refactored the logic of tests and removed the definition of TARGET_FLAGS, but left one use of it. Restore its definition for that one use, so that an x86_64 test is compiled with -m64.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D93634
2021-01-30 13:06:08 +00:00
Dimitry Andric e056fc6cb6 [sanitizer] Fix msan test build on FreeBSD after 7afdc89c20
This commit accidentally enabled fgetgrent_r() in the msan tests under
FreeBSD, but this function is not supported. Also remove FreeBSD from
the SANITIZER_INTERCEPT_FGETGRENT_R macro.
2021-01-28 23:54:04 +01:00
Vyacheslav Chigrin f79937140d [sanitizer] Fix crash on empty strings.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D95431
2021-01-27 13:22:43 -08:00
Evgenii Stepanov e53247ca42 Revert "[sanitizer] Fix crash on empty strings."
Wrong author name, will recommit shortly.

This reverts commit 262c50856a.
2021-01-27 13:22:43 -08:00
Evgenii Stepanov 262c50856a [sanitizer] Fix crash on empty strings.
Patch by Vyacheslav Chigrin.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D95431
2021-01-27 13:08:10 -08:00
Kostya Kortchinsky ba379fe527 [scudo][standalone] Restore GWP-ASan flag parsing
With D92696, the Scudo Standalone GWP-ASan flag parsing was changed to
the new GWP-ASan optional one. We do not necessarily want this, as this
duplicates flag parsing code in Scudo Standalone when using the
GWP-ASan integration.

This CL reverts the changes within Scudo Standalone, and increases
`MaxFlags` to 20 as an addionnal option got us to the current max.

Differential Revision: https://reviews.llvm.org/D95542
2021-01-27 12:35:34 -08:00
Jessica Clarke e47a388bd6 [builtins] Fix build after D95537 due to missing size_t
Strangely int_lib.h only includes stdint.h and not stddef.h, so we need
to include the latter to be able to use size_t here.
2021-01-27 19:44:01 +00:00
Jessica Clarke 5748a71ba3 [builtins] Fix integer/pointer confusion in gcc_personality_v0.c
This fixes the implementation for architectures like CHERI with strong
pointer provenance (pointers, and thus uintptr_t, are represented as
hardware capabilities). Specifically, adding two uintptr_t's together
(as is done for `start + length` and `funcStart + landingPad`) has
ambiguous provenance, whereas using a plain integer (such as size_t) for
the offset operand does not. Also, readULEB128 is creating a plain
integer, not a pointer.

On all currently-supported architectures this should be an NFC, as
size_t and uintptr_t end up being the same underlying plain integer
type.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D95537
2021-01-27 19:28:20 +00:00
Marco Vanotti 98c21ae7a8 [sanitizer][fuchsia] Implement ReleaseMemoryPagesToOS
The `zx_vmar_op_range` allows us to decommit memory pages without
needing a handle to the underlying vmo, as long as we have a handle to
a vmar that contains this mapping. This allows us to implement the
`ReleaseMemoryPagesToOS` function by decommitting the memory using a
handle to the root vmar.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D95384
2021-01-27 11:13:24 -08:00
Jessica Clarke add98b2462 [compiler-rt] Support FreeBSD standalone (boot) environment
FreeBSD uses -Ddouble=jagged-little-pill -Dfloat=floaty-mcfloatface to
poison uses of floating point in its standalone environment. It also
deprecates machine/limits.h in favour of sys/limits.h and does not even
provide the former on newer architectures.

This is a cleaner reimplementation of equivalent patches in FreeBSD's
vendored copy of compiler-rt.

Reviewed By: dim

Differential Revision: https://reviews.llvm.org/D95264
2021-01-27 15:29:39 +00:00
Kostya Kortchinsky e9cc5fef64 [scudo][standalone] Enable death tests on Fuchsia
zxtest doesn't have `EXPECT_DEATH` and the Scudo unit-tests were
defining it as a no-op.

This enables death tests on Fuchsia by using `ASSERT_DEATH` instead.
I used a lambda to wrap the expressions as this appears to not be
working the same way as `EXPECT_DEATH`.

Additionnally, a death test using `alarm` was failing with the change,
as it's currently not implemented in Fuchsia, so move that test within
a `!SCUDO_FUCHSIA` block.

Differential Revision: https://reviews.llvm.org/D94362
2021-01-25 09:19:10 -08:00
Dan Liew 757b93bb7b [ASan] Fix broken Windows build due to 596d534ac3.
In that change I forgot to update the call to
`AsanThread::ThreadStart()` in `asan_win.cpp`.
2021-01-23 09:09:06 -08:00
Dan Liew 596d534ac3 [ASan] Stop blocking child thread progress from parent thread in `pthread_create` interceptor.
Previously in ASan's `pthread_create` interceptor we would block in the
`pthread_create` interceptor waiting for the child thread to start.

Unfortunately this has bad performance characteristics because the OS
scheduler doesn't know the relationship between the parent and child
thread (i.e. the parent thread cannot make progress until the child
thread makes progress) and may make the wrong scheduling decision which
stalls progress.

It turns out that ASan didn't use to block in this interceptor but was
changed to do so to try to address
http://llvm.org/bugs/show_bug.cgi?id=21621/.

In that bug the problem being addressed was a LeakSanitizer false
positive. That bug concerns a heap object being passed
as `arg` to `pthread_create`. If:

* The calling thread loses a live reference to the object (e.g.
  `pthread_create` finishes and the thread no longer has a live
  reference to the object).
* Leak checking is triggered.
* The child thread has not yet started (once it starts it will have a
  live reference).

then the heap object will incorrectly appear to be leaked.

This bug is covered by the `lsan/TestCases/leak_check_before_thread_started.cpp` test case.

In b029c5101f ASan was changed to block
in `pthread_create()` until the child thread starts so that `arg` is
kept alive for the purposes of leaking check.

While this change "works" its problematic due to the performance
problems it causes. The change is also completely unnecessary if leak
checking is disabled (via detect_leaks runtime option or
CAN_SANITIZE_LEAKS compile time config).

This patch does two things:

1. Takes a different approach to solving the leak false positive by
   making LSan's leak checking mechanism treat the `arg` pointer of
   created but not started threads as reachable.  This is done by
   implementing the `ForEachRegisteredThreadContextCb` callback for
   ASan.

2. Removes the blocking behaviour in the ASan `pthread_create`
   interceptor.

rdar://problem/63537240

Differential Revision: https://reviews.llvm.org/D95184
2021-01-22 23:34:43 -08:00
Dan Liew dd922bc2a6 [LSan] Introduce a callback mechanism to allow adding data reachable from ThreadContexts to the frontier.
This mechanism is intended to provide a way to treat the `arg` pointer
of a created (but not yet started) thread as reachable. In future
patches this will be implemented in `GetAdditionalThreadContextPtrs`.

A separate implementation of `GetAdditionalThreadContextPtrs` exists
for ASan and LSan runtimes because they need to be implemented
differently in future patches.

rdar://problem/63537240

Differential Revision: https://reviews.llvm.org/D95183
2021-01-22 19:26:02 -08:00
Jianzhou Zhao f86db34def [MSan] Move origins for overlapped memory transfer
Reviewed-by: eugenis

Differential Revision: https://reviews.llvm.org/D94572
2021-01-21 02:11:26 +00:00
Mitch Phillips 6a42cbf6d2 [GWP-ASan] Add inbuilt options parser.
Adds a modified options parser (shamefully pulled from Scudo, which
shamefully pulled it from sanitizer-common) to GWP-ASan. This allows
customers (Android) to parse options strings in a common way.

Depends on D94117.

AOSP side of these patches is staged at:

 - sepolicy (sysprops should only be settable by the shell, in both root and
 unrooted conditions):
 https://android-review.googlesource.com/c/platform/system/sepolicy/+/1517238

 - zygote updates:
 https://android-review.googlesource.com/c/platform/frameworks/base/+/1515009

 - bionic changes to add `gwp_asan.<process_name>` system property, and
 GWP_ASAN_OPTIONS environment variable:
 https://android-review.googlesource.com/c/platform/bionic/+/1514989

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D92696
2021-01-15 12:57:05 -08:00
Julian Lettner 84de4faf4c GetMacosAlignedVersion() fails if sysctl is not setup
`GetMacosAlignedVersion()` fails for ASan-ified launchd because the
sanitizer initialization code runs before `sysctl` has been setup by
launchd.  In this situation, `sysctl kern.osproductversion` returns a
non-empty string that does not match our expectations of a
well-formatted version string.

Retrieving the kernel version (via `sysctl kern.osrelease`) still works,
so we can use it to add a fallback for this corner case.

Differential Revision: https://reviews.llvm.org/D94190
2021-01-15 11:42:25 -08:00
Mitch Phillips a8520f6970 [GWP-ASan] Minor refactor of optional components.
In preparation for the inbuilt options parser, this is a minor refactor
of optional components including:
 - Putting certain optional elements in the right header files,
 according to their function and their dependencies.
 - Cleaning up some old and mostly-dead code.
 - Moving some functions into anonymous namespaces to prevent symbol
 export.

Reviewed By: cryptoad, eugenis

Differential Revision: https://reviews.llvm.org/D94117
2021-01-14 11:14:11 -08:00
Nico Weber 704831fe1f Revert "Hwasan InitPrctl check for error using internal_iserror"
This reverts commit 1854594b80.
See https://reviews.llvm.org/D94425#2495621
2021-01-13 08:30:11 -05:00
Matthew Malcomson 1854594b80 Hwasan InitPrctl check for error using internal_iserror
When adding this function in https://reviews.llvm.org/D68794 I did not
notice that internal_prctl has the API of the syscall to prctl rather
than the API of the glibc (posix) wrapper.

This means that the error return value is not necessarily -1 and that
errno is not set by the call.

For InitPrctl this means that the checks do not catch running on a
kernel *without* the required ABI (not caught since I only tested this
function correctly enables the ABI when it exists).
This commit updates the two calls which check for an error condition to
use `internal_iserror`.  That function sets a provided integer to an
equivalent errno value and returns a boolean to indicate success or not.

Tested by running on a kernel that has this ABI and on one that does
not.  Verified that running on the kernel without this ABI the current
code prints the provided error message and does not attempt to run the
program.  Verified that running on the kernel with this ABI the current
code does not print an error message and turns on the ABI.
All tests done on an AArch64 Linux machine.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D94425
2021-01-13 11:35:09 +00:00
Jianzhou Zhao 0b99385e15 [MSan] Partially revert some changes from D94552
Because of line 55, actually aligned_beg always equals to beg.
2021-01-13 07:03:17 +00:00
Jianzhou Zhao 82655c1514 [MSan] Tweak CopyOrigin
There could be some mis-alignments when copying origins not aligned.

I believe inaligned memcpy is rare so the cases do not matter too much
in practice.

1) About the change at line 50

Let dst be (void*)5,
then d=5, beg=4
so we need to write 3 (4+4-5) bytes from 5 to 7.

2) About the change around line 77.

Let dst be (void*)5,
because of lines 50-55, the bytes from 5-7 were already writen.
So the aligned copy is from 8.

Reviewed-by: eugenis
Differential Revision: https://reviews.llvm.org/D94552
2021-01-13 01:22:05 +00:00
Julian Lettner 8f5ec45937 [Sanitizer][Darwin] Fix test for macOS 11+ point releases
This test wrongly asserted that the minor version is always 0 when
running on macOS 11 and above.
2021-01-12 15:23:43 -08:00
Martin Storsjö ffac9001d9 [compiler-rt] [sanitizer] Silence -Wframe-larger-than= for a few windows functions with large stack buffers
Also update a documentation url while touching code nearby, as
requested in review.

Differential Revision: https://reviews.llvm.org/D91853
2021-01-08 22:54:03 +02:00
Alex Richardson 00530dee5d [compiler-rt] Implement __atomic_is_lock_free
This function is called by the __atomic_is_lock_free() builtin if the value
cannot be resolved to true at compile time. Lack of this function is
causing the non-lockfree atomics tests in libc++ to not be run (see D91911)

This function is also added in D85044, but that review also adds support
for using lock-free atomics in more cases, whereas this is a minimal change
that just adds __atomic_is_lock_free() for the implementation of atomic.c.

Reviewed By: ldionne

Differential Revision: https://reviews.llvm.org/D92302
2021-01-08 12:48:22 +00:00
Ryan Prichard 658a1be76b [builtins] Add COMPILER_RT_BUILTINS_HIDE_SYMBOLS
On Android, when the builtins are linked into a binary, they are
typically linked using -Wl,--exclude-libs so that the symbols aren't
reexported. For the NDK, compiler-rt's default behavior (build the
builtins archive with -fvisibility=hidden) is better so that builtins
are hidden even without -Wl,--exclude-libs.

Android needs the builtins with non-hidden symbols only for a special
case: for backwards compatibility with old binaries, the libc.so and
libm.so DSOs in the platform need to export some builtins for arm32 and
32-bit x86. See D56977.

Control the behavior with a new flag,
`COMPILER_RT_BUILTINS_HIDE_SYMBOLS`, that behaves similarly to the
`*_HERMETIC_STATIC_LIBRARY` in libunwind/libcxx/libcxxabi, so that
Android can build a special builtins variant for libc.so/libm.so.

Unlike the hermetic flags for other projects, this new flag is enabled
by default.

Reviewed By: compnerd, MaskRay

Differential Revision: https://reviews.llvm.org/D93431
2021-01-07 17:53:44 -08:00
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
Oliver Stannard 4839378ca0 Revert "[sanitizer] Define SANITIZER_GLIBC to refine SANITIZER_LINUX feature detection and support musl"
This reverts commit b7718b6175, because it
is causing build failures on all 32-bit ARM bots which build
compiler-rt.
2021-01-06 10:31:59 +00:00
Peter Collingbourne 6dc3c117a3 scudo: Update a comment to match the Linux kernel behavior. NFCI. 2021-01-05 19:51:47 -08:00
Julian Lettner 8b0bd54d0e [sanitizer][Darwin] Suppress -Wno-non-virtual-dtor warning
Suppress the warning:
```
'fake_shared_weak_count' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]
```

The warning has been recently enabled [1], but the associated cleanup
missed this instance in Darwin code [2].

[1] 9c31e12609
[2] d48f2d7c02

Differential Revision: https://reviews.llvm.org/D94139
2021-01-05 17:09:18 -08:00
Fangrui Song b7718b6175 Reland D93848 "[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 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

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D93848
2021-01-05 16:18:43 -08:00