Commit Graph

18148 Commits

Author SHA1 Message Date
PiJoules
4a04fca9e2 [compiler-rt][asan] Fix for flaky asan check (#88177)
This fixes https://github.com/llvm/llvm-project/issues/87324.

We haven't been able to come up with a minimal reproducer but we can
reliabely avoid this failure with the following fix. Prior to the
GetGlobalLowLevelAllocator change, the old LowLevelAllocator aquired a
lock associated with it preventing that specific allocator from being
accessed at the same time by many threads. With the
GetGlobalLowLevelAllocator change, I had accidentally replaced it but
not taken into account the lock, so we can have a data race if the
allocator is used at any point while a thread is being created. The
global allocator can be used for flag parsing or registering asan
globals.
2024-04-09 15:39:05 -07:00
ChiaHungDuan
bab0507ff2 [scudo] Add EnableContiguousRegions mode (#85149)
This releases the requirement that we need to preserve the memory for
all regions at the beginning. It needs a huge amount of contiguous pages
and which may be a challenge in certain cases. Therefore, adding a new
flag, EnableContiguousRegions, to indicate whether we want to allocate
all the regions next to each other.

Note that once the EnableContiguousRegions is disabled,
EnableRandomOffset becomes irrelevant because the base of each region is
already random.
2024-04-09 09:30:11 -07:00
Alexander Richardson
5601e35f62 [memprof] Use COMPILER_RT_TEST_COMPILER
Unlike the other compiler-rt unit tests MemProf was not using the
`generate_compiler_rt_tests()` helper that ensures the test is compiled
using the test compiler (generally the Clang binary built earlier).
This was exposed by https://github.com/llvm/llvm-project/pull/83088
because it started adding Clang-specific flags to
COMPILER_RT_UNITTEST_CFLAGS if the compiler ID matched "Clang".

This change should fix the buildbots that compile compiler-rt using
a GCC compiler with LLVM_ENABLE_PROJECTS=compiler-rt.

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/88074
2024-04-09 09:23:38 -07:00
Chris Apple
f28c8339c1 Fix issue where MACOSX_VERSION_MIN_FLAG was not set on subsequent runs of CMake in compiler-rt (#87580)
As discussed here:

https://github.com/llvm/llvm-project/pull/74394#issuecomment-2035264683

An unintentional change of behavior was introduced in #74394 

This code introduced in #74394 :

The first time through
* SANITIZER_MIN_OSX_VERSION is not set
* parse -mmacosx-version-min and set MACOSX_VERSION_MIN_FLAG
* Set and cache SANITIZER_MIN_OSX_VERSION

Subsequent times through:
* SANITIZER_MIN_OSX_VERSION is cached 
* (BUG!!) you don't parse -mmacosx-version-min, and don't set
MACOSX_VERSION_MIN_FLAG


MACOSX_VERSION_MIN_FLAG is used later in the file on this line:

63c925ca80/compiler-rt/cmake/config-ix.cmake (L517)


Hoisting this assignment outside the if block returns us to the previous
behavior before this commit, while maintaining the flexibility
introduced with the cache variable
2024-04-08 16:34:30 -07:00
Vitaly Buka
59aba90ab6 [test][UBSAN] Simplify regex in the test 2024-04-08 15:24:40 -07:00
Vitaly Buka
96bba13bd6 [test][UBSAN] Fix Solaris after #87761 2024-04-08 15:21:31 -07:00
Vitaly Buka
ff9b63f8d0 [test][UBSAN] Fix windows after #87761 2024-04-08 15:14:39 -07:00
Christopher Ferris
3b43ae9a68 [scudo] Remove end of line checks. (#88022)
The regex to verify that there is nothing else at the end of the line
doesn't work in all cases, so remove it.
2024-04-08 13:08:35 -07:00
Axel Lundberg
708c8cd743 Fix "[clang][UBSan] Add implicit conversion check for bitfields" (#87761)
Fix since #75481 got reverted.

- Explicitly set BitfieldBits to 0 to avoid uninitialized field member
for the integer checks:
```diff
-       llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first)};
+      llvm::ConstantInt::get(Builder.getInt8Ty(), Check.first),
+      llvm::ConstantInt::get(Builder.getInt32Ty(), 0)};
```
- `Value **Previous` was erroneously `Value *Previous` in
`CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment`, fixed now.
- Update following:
```diff
-     if (Kind == CK_IntegralCast) {
+     if (Kind == CK_IntegralCast || Kind == CK_LValueToRValue) {
```
CK_LValueToRValue when going from, e.g., char to char, and
CK_IntegralCast otherwise.
- Make sure that `Value *Previous = nullptr;` is initialized (see
1189e87951)
- Add another extensive testcase
`ubsan/TestCases/ImplicitConversion/bitfield-conversion.c`

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2024-04-08 12:30:27 -07:00
Saiyedul Islam
2084a07087 Revert "[compiler-rt] Allow running tests without installing first"
This reverts commit c91254db1d.

It was throwing error:
 g++: error: unrecognized command line option ‘-resource-dir=
2024-04-08 03:35:23 -04:00
Alex Richardson
10b1864dff [compiler-rt] Do not add -rpath to linker args on Windows
This is not supported. Should hopefully fix Windows CI after
commit c91254db1d.
2024-04-07 10:22:06 -07:00
Alexander Richardson
c91254db1d [compiler-rt] Allow running tests without installing first
Currently, the testsuite uses the default runtimes path to find the
runtimes libraries which may or may not match the just-built runtimes.
This change uses the `-resource-dir` flag for clang whenever
`COMPILER_RT_TEST_STANDALONE_BUILD_LIBS` is set to ensure that we are
actually testing the currently built libraries rather than the ones
bundled with `${COMPILER_RT_TEST_COMPILER}`.

The existing logic works fine when clang and compiler-rt share the same
build directory ``-DLLVM_ENABLE_PROJECTS=clang;compiler-rt`, but when
building compiler-rt separately we need to tell the compiler used for
the tests where it can find the just-built libraries.

This reduces the fixes check-all failures to one in my configuration:
```
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja
-DCMAKE_C_COMPILER=$HOME/output/upstream-llvm/bin/clang
-DCMAKE_CXX_COMPILER=$HOME/output/upstream-llvm/bin/clang++
-DCOMPILER_RT_INCLUDE_TESTS=ON
-DLLVM_EXTERNAL_LIT=$HOME/build/upstream-llvm-project-build/bin/llvm-lit
-DLLVM_CMAKE_DIR=$HOME/output/upstream-llvm
-DCOMPILER_RT_DEBUG=OFF
-S $HOME/src/upstream-llvm-project/compiler-rt
-B $HOME/src/upstream-llvm-project/compiler-rt/cmake-build-all-sanitizers
```

Reviewed By: vitalybuka, delcypher, MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/83088
2024-04-07 09:50:06 -07:00
Usama Hameed
65e5391657 Pass the linker version to libfuzzer tests on darwin (#87719)
The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects
the linker version at configure time. The driver uses this information
to build the correct set of arguments for the linker. This patch detects
the linker version again during compiler-rt configuration and passes it
to the libfuzzer tests. This allows a clang built on a machine with a
new linker to run compiler-rt tests on a machine with an old linker.

rdar://125932376
2024-04-05 14:48:16 -07:00
Christopher Ferris
0a39f1a7e5 [scudo] Add errno description to mmap failure. (#87713)
Added unit tests for all of the linux report error functions.
2024-04-05 14:25:39 -07:00
Florian Mayer
dfaa144d0c [NFC] [HWASan] clarify FIXME comment (#87689) 2024-04-04 12:55:05 -07:00
Florian Mayer
beded9b9ce [HWASan] Allow stack_history_size of 4096 (#86362)
There is no reason to limit the minimum to two pages.
2024-04-04 12:28:10 -07:00
Vitaly Buka
029e1d7515 Revert "Revert "Revert "[clang][UBSan] Add implicit conversion check for bitfields""" (#87562)
Reverts llvm/llvm-project#87529

Reverts #87518

https://lab.llvm.org/buildbot/#/builders/37/builds/33262 is still broken
2024-04-03 15:19:03 -07:00
Vitaly Buka
8a5a1b7704 Revert "Revert "[clang][UBSan] Add implicit conversion check for bitfields"" (#87529)
Reverts llvm/llvm-project#87518

Revert is not needed as the regression was fixed with
1189e87951.

I assumed the crash and warning are different issues, but according to
https://lab.llvm.org/buildbot/#/builders/240/builds/26629
fixing warning resolves the crash.
2024-04-03 10:58:39 -07:00
Vitaly Buka
5822ca5a01 Revert "[clang][UBSan] Add implicit conversion check for bitfields" (#87518)
Reverts llvm/llvm-project#75481

Breaks multiple bots, see #75481
2024-04-03 10:27:09 -07:00
Axel Lundberg
450f1952ac [clang][UBSan] Add implicit conversion check for bitfields (#75481)
This patch implements the implicit truncation and implicit sign change
checks for bitfields using UBSan. E.g.,
`-fsanitize=implicit-bitfield-truncation` and
`-fsanitize=implicit-bitfield-sign-change`.
2024-04-03 08:55:03 -04:00
Vitaly Buka
372c275800 [dfsan][test] Disable the test with internal_symbolizer
After #87191 we had to add
8b135a7d1f, which
makes symbolizer to calls a global constructor
with `realloc`.
2024-04-01 17:38:20 -07:00
Christopher Ferris
ed6edf262d [scudo] Change isPowerOfTwo macro to return false for zero. (#87120)
Clean-up all of the calls and remove the redundant == 0 checks.

There is only one small visible change. For non-Android, the memalign
function will now fail if alignment is zero. Before this would have
passed.
2024-04-01 13:35:29 -07:00
ChiaHungDuan
92d0d6f6cb [scudo] Do a M_PURGE call before changing release interval on Android (#87110) 2024-04-01 10:09:40 -07:00
Mingming Liu
5bbc640f64 [nfc] Disable the a cpp compiler-rt test on ppc bigendian systems due to build errors (#87262)
`Linux/instrprof-vtable-value-prof.cpp` needs to be built for the test
to run. However, cpp compile & link failed with undefined-ABI error [1].
See original failure in
https://lab.llvm.org/buildbot/#/builders/18/builds/16429

[1] 
```
FAIL: Profile-powerpc64 :: Linux/instrprof-vtable-value-prof.cpp (2406 of 2414)
******************** TEST 'Profile-powerpc64 :: Linux/instrprof-vtable-value-prof.cpp' FAILED ********************
Exit Code: 1
Command Output (stderr):
--
RUN: at line 3: /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_debug/./bin/clang  --driver-mode=g++  -m64  -ldl  -fprofile-generate -fuse-ld=lld -O2 -g -fprofile-generate=. -mllvm -enable-vtable-value-profiling /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/compiler-rt/test/profile/Linux/instrprof-vtable-value-prof.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc64/Linux/Output/instrprof-vtable-value-prof.cpp.tmp-test
+ /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_debug/./bin/clang --driver-mode=g++ -m64 -ldl -fprofile-generate -fuse-ld=lld -O2 -g -fprofile-generate=. -mllvm -enable-vtable-value-profiling /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/llvm-project/compiler-rt/test/profile/Linux/instrprof-vtable-value-prof.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64be-sanitizer/sanitizer-ppc64be/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc64/Linux/Output/instrprof-vtable-value-prof.cpp.tmp-test
ld.lld: error: /lib/../lib64/Scrt1.o: ABI version 1 is not supported
clang: error: linker command failed with exit code 1 (use -v to see invocation)

```
2024-04-01 09:55:24 -07:00
Mingming Liu
1351d17826 [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (#66825)
(The profile format change is split into a standalone change into https://github.com/llvm/llvm-project/pull/81691)

* For InstrFDO value profiling, implement instrumentation and lowering for virtual table address.
* This is controlled by `-enable-vtable-value-profiling` and off by default.
* When the option is on, raw profiles will carry serialized `VTableProfData` structs and compressed vtables as payloads.
 
* Implement profile reader and writer support 
  * Raw profile reader is used by `llvm-profdata` but not compiler. Raw profile reader will construct InstrProfSymtab with symbol names, and map profiled runtime address to vtable symbols.
  * Indexed profile reader is used by `llvm-profdata` and compiler. When initialized, the reader stores a pointer to the beginning of in-memory compressed vtable names and the length of string. When used in `llvm-profdata`, reader decompress the string to show symbols of a profiled site. When used in compiler, string decompression doesn't
happen since IR is used to construct InstrProfSymtab.
  * Indexed profile writer collects the list of vtable names, and stores that to index profiles.
  * Text profile reader and writer support are added but mostly follow the implementation for indirect-call value type.
* `llvm-profdata show -show-vtables <args> <profile>` is implemented.

rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600#pick-instrumentation-points-and-instrument-runtime-types-7
2024-04-01 08:52:35 -07:00
Vitaly Buka
8b135a7d1f [sanitizer][symbolizer] Add new dependency 2024-04-01 00:37:35 -07:00
Thurston Dang
dc0cb17241 [msan] Nit: use init_origins parameter instead of __msan_get_track_origins() in InitShadowWithReExec (#86994)
This fixes a nit I had accidentally introduced in
https://github.com/llvm/llvm-project/pull/85142

I don't think the value of __msan_get_track_origins() will change
between the start and end of InitShadowWithReExec, but it's cleaner to
use the parameter.
2024-03-31 18:49:31 -07:00
Jon Chesterfield
ca68a14eb8 Revert "Revert "Revert "[compiler-rt] Allow building builtins.a without a libc (#86737)"""
This reverts commit d2b63ed0ca. CI again.
Leading theory is bad interaction between cmake and buildbot, some guesses at PR86737
2024-03-31 23:17:05 +01:00
Jon Chesterfield
d2b63ed0ca Revert "Revert "[compiler-rt] Allow building builtins.a without a libc (#86737)""
This reverts commit a2982a29fd.
Buildbot failure that motivated the revert looks unrelated.
2024-03-31 19:49:02 +01:00
Christopher Ferris
c0a3c5c81f [scudo] Change tests that use setrlimit to cause mmap to fail. (#87004)
It appears that qemu does not actually cause mmap to fail when calling
setrlimit to limit the address space size. In the two tests that use
setrlimit, detect if mmap still works and skip the tests in that case.

Since all Android targets should support setrlimit, compile out the mmap
check code for them.
2024-03-29 14:19:10 -07:00
Christopher Ferris
0dbd804a69 [scudo] Only init RingBuffer when needed. (#85994)
Only attempt to initialize the ring buffer when tracking is enabled.

Updated unit tests, and added a few new unit tests to verify the
RingBuffer is not initialized by default.

Verified that the two maps associated with the RingBuffer are not
created in processes by default.
2024-03-29 09:44:17 -07:00
Christopher Ferris
7a87902684 [scudo] Fix stack depot validation. (#87024)
In the StackDepot::isValid function, there is work to validate the
TabMask variable. Unfortunately, if TabMask is set to the maximum
allowed value, TabSize = TabMask + 1 becomes zero and validation passes.

Disallow that case to prevent invalid reads into the Tab structure.
2024-03-28 17:35:46 -07:00
ChiaHungDuan
6b149f70ab [scudo] Dump ReleaseToOsIntervalMs (#86887)
This can be adjusted during runtime and it may impact the memory
footprint if it's set to a big value or is disabled.
2024-03-28 15:28:01 -07:00
Charlie Barto
423832421b [asan][windows] Weak function interception support in instruction size decoder. (#86570)
This makes it so we'll be able to decode the instructions used in the
weak function stubs from
https://github.com/llvm/llvm-project/pull/81677. This code doesn't
technically require those changes.

Co-authored-by: Amy Wishnousky <amyw@microsoft.com>
2024-03-28 09:52:25 -07:00
Leandro Lupori
a2982a29fd Revert "[compiler-rt] Allow building builtins.a without a libc (#86737)"
This reverts commit 8669225863.

Reverting due to buildbot failures.
2024-03-28 09:56:14 -03:00
Nazım Can Altınova
cc98ffb6dc [tsan][test] Remove some unneded debug comments in a tsan test (#86896)
I introduced this test in #86537, let's remove some unneeded debugging
comments.
This PR was initially also moving the test to linux directory but looks
like it's already done by 17ab9e6446 .
2024-03-27 18:09:20 -07:00
Vitaly Buka
17ab9e6446 [TSAN] Move test into Linux/
Linux specific test was introduced by #86537
2024-03-27 17:51:50 -07:00
Amy Kwan
685d7855ac Fix the -Wmissing-designated-field-initializers on the clang-ppc64le-rhel bot 2024-03-27 14:42:01 -05:00
ChiaHungDuan
f1ac559534 Revert "[scudo] Use getMonotonicTimeFast for tryLock." (#86590)
This reverts commit 36ca9a2902.

We were using the `time` as the seed while choosing a new TSD. To make
the access of TSDs evenly distributed, we require a higher precision in
`time`. Otherwise, many threads may result in having the same random
access pattern on TSDs because they share the same `time` in certain
period. On Linux, CLOCK_MONOTONIC_COARSE usually adopts 4 ms precision.
This is way higher than the average accessing time of TSD (which is
usually less than 1 us). As a result, when multiple threads try to
select a new TSD in a 4 ms interval, they share the same `time` seed and
end up choosing and congesting on the same TSD.
2024-03-27 11:30:08 -07:00
Simon Pilgrim
fca48312a8 Fix signed/unsigned comparison warning. NFC. 2024-03-27 16:36:07 +00:00
Enna1
4720e3831b [NFC][Sanitizer] Refine the restriction on SizeClassAllocator64::kRegionSize (#86270)
This patch replaces the `SANITIZER_WORDSIZE / 2` with
`sizeof(CompactPtrT) * 8`, replaces hardcoded `4` with
`kCompactPtrScale` in assertion.
2024-03-27 09:06:45 +08:00
Jon Chesterfield
8669225863 [compiler-rt] Allow building builtins.a without a libc (#86737)
compiler-rt may depend on libc (memset etc). Likewise a libc built by
clang may depend on compiler-rt builtins.

This circular dependency doesn't matter much once they're both compiled.
The easy compilation order to build both from source is:

1. install libc headers somewhere
2. build compiler-rt builtins against those headers
3. build libc against compiler-rt builtins

This patch relaxes the cmake sanity check to pass without requiring a
libc library. That allows the above sequence to work. Otherwise one
needs to build a static libc, then use that to pass the compiler-rt
cmake check, then build a normal libc.
2024-03-26 22:33:03 +00:00
Christopher Ferris
1949f7d6c9 [scudo] Clean up string handling (#86364)
Do not abort if a vector cannot increase its own capacity. In that case,
push_back calls silently fail.

Modify the ScopedString implementation so that it no longer requires two
passes to do the format. Move the helper functions to be private member
functions so that they can use push_back directly. This allows the
capacity to be increased under the hood and/or silently discards data if
the capacity is exceeded and cannot be increased.

Add new tests for the Vector and ScopedString for capacity increase
failures.

Doing this so that if a map call fails, and we are attempting to write
an error string, we can still get some of the message dumped. This also
avoids crashing in Scudo code, and makes the caller handle any failures.
2024-03-26 14:47:48 -07:00
Fangrui Song
d5224b73cc [tsan] Refine fstat{,64} interceptors (#86625)
In glibc versions before 2.33. `libc_nonshared.a` defines
`__fxstat/__fxstat64` but there is no `fstat/fstat64`. glibc 2.33 added
`fstat/fstat64` and obsoleted `__fxstat/__fxstat64`. Ports added after
2.33 do not provide `__fxstat/__fxstat64`, so our `fstat/fstat64`
interceptors using `__fxstat/__fxstat64` interceptors would lead to
runtime failures on such ports (LoongArch and certain RISC-V ports).

Similar to https://reviews.llvm.org/D118423, refine the conditions that
we define fstat{,64} interceptors. `fstat` is supported by musl/*BSD
while `fstat64` is glibc only.
2024-03-26 14:09:39 -07:00
Nazım Can Altınova
fe97a6148e [tsan] Add callbacks for futex syscalls and mark them as blocking on tsan (#86537)
Fixes #83844.

This PR adds callbacks to mark futex syscalls as blocking. Unfortunately
we didn't have a mechanism before to mark syscalls as a blocking call,
so I had to implement it, but it mostly reuses the `BlockingCall`
implementation
[here](96819daa3d/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp (L362-L380)).

The issue includes some information but this issue was discovered
because Rust uses futexes directly. So most likely we need to update
Rust as well to use these callbacks.

Also see the latest comments in #85188 for some context.
I also sent another PR #84162 to mark `pthread_*_lock` calls as
blocking.
2024-03-26 12:33:51 +01:00
Nazım Can Altınova
f01377d8eb [tsan] Mark pthread_*_lock functions as blocking (#84162)
Fixes #83561.

When a thread is blocked on a mutex and we send an async signal to that
mutex, it never arrives because tsan thinks that `pthread_mutex_lock` is
not a blocking function. This patch marks `pthread_*_lock` functions as
blocking so we can successfully deliver async signals like `SIGPROF`
when the thread is blocked on them.

See the issue also for more details. I also added a test, which is a
simplified version of the compiler explorer example I posted in the
issue.

Please let me know if you have any other ideas or things to improve!
Happy to work on them.

Also I filed #83844 which is more tricky because we don't have a libc
wrapper for `SYS_futex`. I'm not sure how to intercept this yet. Please
let me know if you have ideas on that as well. Thanks!
2024-03-26 12:32:52 +01:00
NAKAMURA Takumi
8f86c6bf95 compiler-rt: Fix variadic macro warnings [-Wc++20-extensions]
They began complaining since #84520.
2024-03-26 08:45:12 +09:00
Vitaly Buka
4acd84e7cc Revert "[compiler-rt] Also consider SIGPROF as a synchronous signal" (#86416)
Reverting #85188 with follow up patches.

This reverts commit 362d26366d.
This reverts commit c9bdeabdf4.
This reverts commit 6bc6e1ace9.
This reverts commit 01fa550ff6.
This reverts commit ddcbab37ac.
2024-03-24 01:22:48 -07:00
Charlie Barto
dc43aa439e [asan][windows] When compiling with clang-cl or MSVC pass /Zl (that's a little L) (#85874)
/Zl is the equivalent of -nodefaultlibs. The idea here is to make sure
that the asan runtime doesn't have any defaultlibs directives, which
makes it easier to mix an asan runtime built with the dynamic CRT with
an application built with the static CRT (or vise-versa).

This is part of the overall effort to remove the static asan runtime on
windows entirely: https://github.com/llvm/llvm-project/pull/81677

Co-authored-by: Amy Wishnousky <amyw@microsoft.com>
2024-03-22 17:38:34 -07:00
Usama Hameed
3bc71c2abf Get the linker version and pass the it to compiler-rt tests on Darwin. (#86220)
The HOST_LINK_VERSION is a hardcoded string in Darwin clang that detects
the linker version at configure time. The driver uses this information
to build the correct set of arguments for the linker. This patch detects
the linker version again during compiler-rt configuration and passes it
to the tests. This allows a clang built on a machine with a new linker
to run compiler-rt tests on a machine with an old linker.

rdar://125198603
2024-03-22 15:29:36 -07:00