Commit Graph

12066 Commits

Author SHA1 Message Date
Alex Brachet a672b7a7d7 [InstrProf] Make __llvm_profile_counter_bias_default hidden
This symbol shouldn't have default visibility.

Differential Revision: https://reviews.llvm.org/D135346
2022-10-06 06:16:22 +00:00
Vitaly Buka 68f4ceaf9b Revert "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests"
Breaks some bots, details in https://reviews.llvm.org/D91620

This reverts commit 93b1256e38.
2022-10-05 09:59:25 -07:00
Rainer Orth 93b1256e38 [compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests
When trying to debug some `compiler-rt` unittests, I initially had a hard
time because

- even in a `Debug` build one needs to set `COMPILER_RT_DEBUG` to get
  debugging info for some of the code and
- even so the unittests used a hardcoded `-O2` which often makes debugging
  impossible.

This patch addresses this by instead using `-O0` if `COMPILER_RT_DEBUG`.
Two tests in `sanitizer_type_traits_test.cpp` need to be disabled since
they have undefined references to `__sanitizer::integral_constant<bool,
true>::value`.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D91620
2022-10-05 09:53:26 +02:00
Hans Wennborg 20a269cf77 Revert "[CMake] Use libcxx-abi-* targets for in-tree sanitizer C++ ABI"
It casued some runtimes builds to fail with cmake error

  No target "libcxx-abi-static"

see code review.

> When in-tree libcxx is selected as the sanitizer C++ ABI, use
> libcxx-abi-* targets rather than libcxxabi and libunwind directly.
>
> Differential Revision: https://reviews.llvm.org/D134855

This reverts commit 414f9b7d2f.
2022-10-03 14:56:07 +02:00
Fangrui Song 6f46ff3765 [test] Make Linux/sem_init_glibc.cpp robust
and fix it for 32-bit ports defining sem_init@GLIBC_2.0 (i386, mips32, powerpc32) for glibc>=2.36.

Fix https://github.com/llvm/llvm-project/issues/58079

Reviewed By: mgorny

Differential Revision: https://reviews.llvm.org/D135023
2022-10-02 00:47:10 -07:00
Petr Hosek 414f9b7d2f [CMake] Use libcxx-abi-* targets for in-tree sanitizer C++ ABI
When in-tree libcxx is selected as the sanitizer C++ ABI, use
libcxx-abi-* targets rather than libcxxabi and libunwind directly.

Differential Revision: https://reviews.llvm.org/D134855
2022-09-30 20:32:10 +00:00
Vitaly Buka 8c5f66a3af [NFC][sanitizer] Simplify symbolizer build script
This checks are irrelevant with monorepo.
2022-09-30 12:25:59 -07:00
Vitaly Buka 5a86b53a91 [sanitizer] Fix build of 32bit symbolizer 2022-09-30 12:21:17 -07:00
Dmitry Vyukov 3056ccdbae tsan: fix deadlock/crash in signal handling
We set in_blocking_func around some blocking C functions so that we don't
delay signal infinitely (if in_blocking_func is set we deliver signals
synchronously).

However, pthread_join is blocking but also call munmap/free to free thread
resources. If we are inside the munmap/free interceptors called from
pthread_join and deliver a signal synchronously, it can lead to deadlocks
and crashes since we re-enter runtime and try to lock the same mutexes
or use the same per-thread data structures.

If we re-enter runtime via an interceptor when in_blocking_func is set,
temporary reset in_blocking_func around the interceptor and restore it back
when we return from the recursive interceptor.

Also move in_blocking_func from ThreadSignalContext to ThreadContext
so that we can CHECK that it's not set in SlotLocker ctor.

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

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D127845
2022-09-30 14:23:46 +02:00
Vitaly Buka 4d7c0f8ccf [sanitizer] Fix symbolizer build script 2022-09-29 23:32:54 -07:00
Alex Brachet 2449f42427 [scudo][Fuchsia] Increase MaxNumCachedHint
This brings the value closer to other platforms and allows
for future improvements, see D133897.
2022-09-29 20:57:10 +00:00
Vitaly Buka 346de23ec9 Revert "[sanitizer] Use LLVM_ENABLE_LIBCXX to build symbolizer"
Trigger some "libatomic" error.

This reverts commit ccbb401472.
2022-09-28 23:55:21 -07:00
Vitaly Buka ccbb401472 [sanitizer] Use LLVM_ENABLE_LIBCXX to build symbolizer 2022-09-28 19:27:25 -07:00
Vitaly Buka 5f2e2b7d80 [test][msan] -fno-sanitize-memory-param-retval in unittests 2022-09-28 18:53:09 -07:00
Rainer Orth 1cd4d63fb9 [sanitizer_common] Restore sanitizer_procmaps_solaris.cpp compilation on Solaris 11.3
When upstream `compiler-rt` was recently imported into GCC's
`libsanitizer`, Solaris 11.3 bootstrap broke because in 11.3
`<sys/procfs.h>` doesn't mix with largefile compilation.  I'd caused this
in D129837 <https://reviews.llvm.org/D129837> where I forgot that the code
still needs to support Solaris 11.3.

Fixed by restoring the `#undef _FILE_OFFSET_BITS`.

Tested on `sparc-sun-solaris2.11` and `amd64-pc-solaris2.11` (Solaris 11.4)
in LLVM and both Solaris 11.3 and 11.4 in GCC.

Differential Revision: https://reviews.llvm.org/D133556
2022-09-23 15:50:00 +02:00
Blue Gaston 9b194fe2a2 [Sanitizer] Bump macOS deployment target for sanitizer unit test binary to support C++17 requirements.
This patch fixes a test failure on Apple caused by changing standard to c++17.
sanitizer_allocator_test.cpp requires language features introducied in 10.13 for c++17.
After initial investigation, it was not clear how to add this flag to a single file:
https://reviews.llvm.org/D133878

Becuase of this, we have upped the min version of this test suite to 10.13, the min version necessary to support necessary language features.

We felt this was a better option than upping the min version of the product to support a single test.
We are raising deployment target for a single test suite, rather than the product.

Differential Revision: https://reviews.llvm.org/D134091

rdar://98737270
2022-09-20 06:43:30 -04:00
Lang Hames 0e43f3b04d [ORC][ORC-RT] Make WrapperFunctionCall::Create support void functions.
Serialized calls to void-wrapper-functions should have zero bytes of argument
data, but accessing ArgData[0] may (and will, in the case of SmallVector) fail
if the argument data buffer is empty.

This commit fixes the issue by adding a check for empty argument buffers.
2022-09-18 17:53:45 -07:00
Lang Hames 47e9e58808 [ORC][ORC-RT][MachO] Reset __data and __common sections on library close.
If we want to be able to close and then re-open a library then we need to reset
the data section states when the library is closed. This commit updates
MachOPlatform and the ORC runtime to track __data and __common sections, and
reset the state in MachOPlatformRuntimeState::dlcloseDeinitialize.

This is only a first step to full support -- there are other data sections that
we're not capturing, and we'll probably want a more efficient representation
for the sections (rather than passing their string name over IPC), but this is
a reasonable first step.

This commit also contains a fix to MapperJITLinkMemoryManager that prevents it
from calling OnDeallocated twice in the case of an error.
2022-09-16 13:40:19 -07:00
Lang Hames 9cd28d3f11 [ORC-RT] Update COFF, ELF support after ExecutorAddrDiff change in 4c43483186. 2022-09-15 22:26:36 -07:00
jacquesguan cbd7bc66c4 [ORC-RT] Remove wrong getValue of ExecutorAddrDiff. 2022-09-16 11:18:27 +08:00
Lang Hames 4c43483186 [ORC-RT] Make ExecutorAddrDiff an alias for uint64_t.
Unlike ExecutorAddr, there's limited value to having a distinct type for
ExecutorAddrDiff, and it's occasionally awkward to work with. The corresponding
LLVM type (llvm::orc::ExecutorAddrDiff) was already made a type-alias in
9e2cfb061a.
2022-09-15 19:11:51 -07:00
Leonard Grey ed2c3f46f5 [lsan][Darwin] Scan libdispatch and Foundation memory regions
libdispatch uses its own heap (_dispatch_main_heap) for some allocations, including the dispatch_continuation_t that holds a dispatch source's event handler.
Objective-C block trampolines (creating methods at runtime with a block as the implementations) use the VM_MEMORY_FOUNDATION region (see 8701d5672d/runtime/objc-block-trampolines.mm (L371)).

This change scans both regions to fix false positives. See tests for details; unfortunately I was unable to reduce the trampoline example with imp_implementationWithBlock on a new class, so I'm resorting to something close to the bug as seen in the wild.

Differential Revision: https://reviews.llvm.org/D129385
2022-09-14 16:46:40 -04:00
Lang Hames 35ea0c6d56 [ORC-RT] Update headers for rename of include/orc in a85e4aa37d.
The ORC runtime include directory was renamed from 'orc' to 'orc_rt' in
a85e4aa37d. Update includes to match.
2022-09-12 17:09:06 -07:00
Lang Hames a85e4aa37d [ORC-RT] Drop the 'clang_rt.' prefix from the ORC runtime.
The ORC runtime isn't used by clang -- the prefix was just cargo-culted with
the rest of the XRay config when the ORC runtime was introduced. We now want to
make parts of it available for clients to link directly, so this seems like a
good time to fix the name.
2022-09-12 16:48:20 -07:00
sunho 73c4033987 [ORC][ORC_RT][COFF] Support dynamic VC runtime.
Supports dynamic VC runtime. It implements atexits handling which is required to load msvcrt.lib successfully. (the object file containing atexit symbol somehow resolves to static vc runtim symbols) It also default to dynamic vc runtime which tends to be more robust.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132525
2022-09-10 15:25:49 +09:00
Florian Mayer 178554f3c8 [ASan] Show memory rather than tag addresses in tag dump
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D133391
2022-09-07 13:23:00 -07:00
Florian Mayer 4f5147a7cf [HWASan] Show memory rather than tag addresses in tag dump
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D133380
2022-09-06 16:54:34 -07:00
Florian Mayer 9006b082a5 [HWASan] rename left/right to before/after.
left/right is a weird way to refer to address ordering.

Reviewed By: eugenis, vitalybuka

Differential Revision: https://reviews.llvm.org/D132622
2022-09-06 13:52:28 -07:00
Florian Mayer be366041fa [ASan] rename left/right to before/after.
left/right is a weird way to refer to address ordering.

Reviewed By: eugenis, MaskRay

Differential Revision: https://reviews.llvm.org/D132611
2022-09-06 13:25:15 -07:00
Vitaly Buka b4257d3bf5 [tsan] Replace mem intrinsics with calls to interceptors
After https://reviews.llvm.org/rG463aa814182a23 tsan replaces llvm
intrinsics with calls to glibc functions. However this approach is
fragile, as slight changes in pipeline can return llvm intrinsics back.
In particular InstCombine can do that.

Msan/Asan already declare own version of these memory
functions for the similar purpose.

KCSAN, or anything that uses something else than compiler-rt, needs to
implement this callbacks.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D133268
2022-09-06 13:09:31 -07:00
Vitaly Buka 4a0b18c2cd [tsan][go] Fix buildgo.sh when GOAMD64 undefined 2022-09-06 13:02:11 -07:00
Vitaly Buka c51a12d598 Revert "[tsan] Replace mem intrinsics with calls to interceptors"
Breaks
http://45.33.8.238/macm1/43944/step_4.txt
https://lab.llvm.org/buildbot/#/builders/70/builds/26926

This reverts commit 77654a65a3.
2022-09-06 09:47:33 -07:00
Vitaly Buka 77654a65a3 [tsan] Replace mem intrinsics with calls to interceptors
After https://reviews.llvm.org/rG463aa814182a23 tsan replaces llvm
intrinsics with calls to glibc functions. However this approach is
fragile, as slight changes in pipeline can return llvm intrinsics back.
In particular InstCombine can do that.

Msan/Asan already declare own version of these memory
functions for the similar purpose.

KCSAN, or anything that uses something else than compiler-rt, needs to
implement this callbacks.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D133268
2022-09-06 08:25:32 -07:00
Igor Kudrin 84c4efbc6d [ubsan-minimal] Report the address of an error
This implements a FIXME in the runtime library and adds printing the
address at the end of the message as "by 0x123abc". The buffer for the
message is allocated on the stack in a handler, so the stack memory
consumption is slightly increased. No additional external dependencies
are added.

Differential revision: https://reviews.llvm.org/D131914
2022-09-05 14:18:25 +04:00
Krzysztof Parzyszek 98c2754abd [Libfuzzer] Include signal.h for SIGINT
Or else compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp fails to compile
on FreeBSD.
2022-09-04 11:31:15 -05:00
Lang Hames 1169586dcd [ORC-RT] Refactor ORC runtime CMake for future test tool(s).
We want to move functionality from the LLVM ORCTargetProcess library into the
ORC runtime, and this will mean implementing remote-executor testing tools
(like llvm-jitlink-executor and lli-child-target) in the ORC runtime.

This patch refactors the ORC runtime build system to introduce an
add_orc_tool function that can be used to add new test tools. The code is
modeled on existing functions for adding unit tests.

A placeholder orc-rt-executor tool and test are added to verify that the
config changes behave as expected.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D133084
2022-09-02 20:59:57 -07:00
Leonard Grey f458d9f6f8 [lsan][darwin] Unmask camouflaged class_rw_t pointers
Detailed motivation here: https://docs.google.com/document/d/1xUNo5ovPKJMYxitiHUQVRxGI3iUmspI51Jm4w8puMwo

check-asan (with LSAN enabled) and check-lsan are currently broken on recent macOS versions, due to pervasive false positives. Whenever the Objective-C runtime realizes a class, it allocates data for it, then stores that data with flags in the low bits. This means LSAN can not recognize it as a pointer while scanning.

This change checks every potential pointer on Apple platforms, and if the high bit is set, attempts to extract a pointer by masking out the high bit and flags. This is ugly, but it's also the best approach I could think of (see doc above); very open to other suggestions.

Differential Revision: https://reviews.llvm.org/D133126
2022-09-02 11:25:22 -04:00
Lang Hames 6ca9f42189 [ORC][ORC-RT] Consistently use pointed-to type as template arg to wrap/unwrap.
Saves wrap/unwrap implementers from having to use std::remove_pointer_t to get
at the pointed-to type.
2022-09-01 20:54:24 -07:00
Vitaly Buka ad2b356f85 [msan] Use no-origin functions when possible
Saves 1.8% of .text size on CTMark

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D133077
2022-09-01 19:18:38 -07:00
Vitaly Buka c059ede28e [msan] Add more specific messages for use-after-destroy
Reviewed By: kda, kstoimenov

Differential Revision: https://reviews.llvm.org/D132907
2022-08-30 19:52:32 -07:00
Gulfem Savrun Yeniceri 999886325e [profile] Create only prof header when no counters
When we use selective instrumentation and instrument a file
that is not in the selected files list provided via -fprofile-list,
we generate an empty raw profile. This leads to empty_raw_profile
error when we try to read that profile. This patch fixes the issue by
generating a raw profile that contains only a profile header when
there are no counters and profile data.

A small reproducer for the above issue:
echo "src:other.cc" > code.list
clang++ -O2 -fprofile-instr-generate -fcoverage-mapping
-fprofile-list=code.list code.cc -o code
./code
llvm-profdata show default.profraw

Differential Revision: https://reviews.llvm.org/D132094
2022-08-30 19:50:41 +00:00
Lang Hames 6d71c4e86b [ORC-RT] unit tests do not need access to LLVM headers.
Also delete trailing whitespace in lib/orc/CMakeLists.txt
2022-08-29 14:45:02 -07:00
Alexey Baturo fba042dabb [RISC-V][HWASAN] Save sp address at the start of tag mismatch routine
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131574
2022-08-28 21:12:37 +03:00
Alexey Baturo 38b04fd9c0 [RISC-V][HWASAN] Add runtime support for HWASAN for RISC-V
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131342
2022-08-28 20:43:31 +03:00
Alexey Baturo f8b71a307e [RISC-V][HWASAN] Add tag mismatch routines for HWASAN required for RISC-V
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131341
2022-08-28 19:42:08 +03:00
Lang Hames 16d538c5ef [ORC-RT] Remove __orc_rt::apply_tuple.
This utility was a substitute for std::apply, which is now available.
2022-08-26 17:06:56 -07:00
Lang Hames ac0c8cb3ff [ORC-RT] Add "wrap" and "unwrap" steps to __orc_rt::ExecutorAddr toPtr/fromPtr.
The wrap/unwrap operations are applied to pointers after/before conversion to/from
raw addresses. They can be used to tag, untag, sign, or strip signing from
pointers. They currently default to 'rawPtr' (identity) on all platforms, but it
is expected that the default will be set based on the host architecture, e.g.
they would default to signing/stripping for arm64e.

This is the ORC runtime counterpart to f14cb494a34:
2022-08-26 15:58:10 -07:00
Lang Hames faabefe3c8 [ORC-RT] Add a std::identity substitute.
The __orc_rt::identity utility is intended to serve as a substitute for
c++20's std::identity until we can use the latter (when LLVM moves to c++20).
2022-08-26 15:58:10 -07:00
Akira Hatanaka 2e9df86046 [compiler-rt][builtins] Add compiler flags to catch potential errors
that can lead to security vulnerabilities

Also, fix a few places that were causing -Wshadow and
-Wformat-nonliteral warnings to be emitted.

This reapplies the patch that was reverted in caaafe4ae2 because it
broke Fuchsia builders.

I reverted the changes I made to InstrProfData.inc and instead renamed
the variables in InstrProfilingWriter.c. Also fixed a bug in function
add_security_warnings that was causing it to pass -Wformat-nonliteral
when the compiler doesn't support it.
2022-08-26 08:35:19 -07:00
Alexander Potapenko 5d82819583 [compiler-rt][hwasan] Support for Intel LAM v6 API
Version 6 of Intel LAM kernel patches
(https://lore.kernel.org/all/20220815041803.17954-1-kirill.shutemov@linux.intel.com/)
introduces arch_prctl(ARCH_GET_MAX_TAG_BITS), which (unlike
ARCH_GET_UNTAG_MASK) can be used to determine if the kernel really
supports pointer tagging. arch_prctl(ARCH_GET_UNTAG_MASK) will be used to
verify that HWASan can place tags in the given bit range.

Depends on D132545

Differential Revision: https://reviews.llvm.org/D132546
2022-08-26 10:21:18 +02:00