13561 Commits

Author SHA1 Message Date
Mircea Trofin
cfe9deb135 Reapply "[ctx_profile] Integration test (#92456)"
This reverts commit 881f20e958.

Passing -ldl -lpthread explicitly
2024-05-17 21:55:39 -07:00
Aiden Grossman
881f20e958 Revert "[ctx_profile] Integration test (#92456)"
This reverts commit 487d5af648.

This was causing failures on some buildbots.
https://lab.llvm.org/buildbot/#/builders/247/builds/18559
2024-05-17 23:59:28 +00:00
Mircea Trofin
487d5af648 [ctx_profile] Integration test (#92456)
Compile with clang a program that's instrumented for contextual profiling and verify a profile can be collected.
2024-05-17 11:08:14 -07:00
ChiaHungDuan
772b1b0cb2 [scudo] Move the chunk update into functions (#83493)
The code paths for mte enabled and disabled were interleaving and which
increases the difficulty of reading each path in both source level and
assembly level. In this change, we move the parts that they have
different logic into functions and minor refactors on the code
structure.
2024-05-15 17:13:08 -07:00
Enna1
73324cbc9c [ASan] Remove COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION. (#91832)
Since the set of COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION is removed in
commit 8421fa5d53,
cleanup the use of COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION.
2024-05-15 15:04:34 +08:00
Stephan Bergmann
4688df68f9 Avoid partial munmap (#92109)
...which caused issues like

> ==42==ERROR: AddressSanitizer failed to deallocate 0x32 (50) bytes at
address 0x117e0000 (error code: 28)
> ==42==Cannot dump memory map on emscriptenAddressSanitizer: CHECK
failed: sanitizer_common.cpp:81 "((0 && "unable to unmmap")) != (0)"
(0x0, 0x0) (tid=288045824)
> #0 0x14f73b0c in __asan::CheckUnwind()+0x14f73b0c
(this.program+0x14f73b0c)
> #1 0x14f8a3c2 in __sanitizer::CheckFailed(char const*, int, char
const*, unsigned long long, unsigned long long)+0x14f8a3c2
(this.program+0x14f8a3c2)
> #2 0x14f7d6e1 in __sanitizer::ReportMunmapFailureAndDie(void*,
unsigned long, int, bool)+0x14f7d6e1 (this.program+0x14f7d6e1)
> #3 0x14f81fbd in __sanitizer::UnmapOrDie(void*, unsigned
long)+0x14f81fbd (this.program+0x14f81fbd)
> #4 0x14f875df in __sanitizer::SuppressionContext::ParseFromFile(char
const*)+0x14f875df (this.program+0x14f875df)
> #5 0x14f74eab in __asan::InitializeSuppressions()+0x14f74eab
(this.program+0x14f74eab)
> #6 0x14f73a1a in __asan::AsanInitInternal()+0x14f73a1a
(this.program+0x14f73a1a)

when trying to use an ASan suppressions file under Emscripten: Even
though it would be considered OK by SUSv4, the Emscripten runtime states
"We don't support partial munmapping" (see

<f4115eb2c3>
"Implement MAP_ANONYMOUS on top of malloc in STANDALONE_WASM mode
(#16289)").

Co-authored-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-05-15 08:58:14 +02:00
Keith Smiley
332f5e7113 [compiler-rt][ORC] Remove unused cmake variables (NFC) (#87742) 2024-05-14 12:24:12 -07:00
Thurston Dang
d9ce33a0ee [libfuzzer] Prevent MSan false positive when printing log with -jobs (#91679)
libfuzzer's -jobs option will, depending on the number of CPUs, spin up
a
WorkerThread and end up printing the log file using CopyFileToErr.
This leads to an MSan false positive. This patch disables the MSan
interceptor checks,
similarly to other instances in https://reviews.llvm.org/D48891

Side-note: this false positive issue first appeared when printf()
was replaced by puts() (90b4d1bcb2).
The interceptor check was always present; however, MSan does not
check_printf by default.
2024-05-10 15:36:55 -07:00
Mircea Trofin
77a59c3210 [ctx_profile] Fix signed-ness in CtxInstrProfilingTest.cpp
Follow-up from `265953c`
2024-05-10 11:27:44 -07:00
Mircea Trofin
265953cc26 [ctx_profile] Arena should zero-initialize its allocation area. 2024-05-10 10:43:22 -07:00
Mircea Trofin
0fd017ce43 [nfc][ctx_profile] Move CtxInstrContextNode.h in include
Follow-up from PR #91669.
2024-05-09 17:30:46 -07:00
Mircea Trofin
e4763ca83b [ctx_profile] Pull ContextNode in a .inc file (#91669)
This pulls out `ContextNode` as we need to use it pretty much as-is to implement a writer. The writer will be implemented on the LLVM side because it takes a dependency on BitStreamWriter.

Since we can't reuse a header between compiler-rt and llvm, we use a header file which is copied on both sides, and test that the 2 copies are identical.

The changes adds the necessary other stuff for compiler-rt/ctx_profile testing.
2024-05-09 16:58:40 -07:00
Mircea Trofin
8755d24cb3 [compiler-rt][ctx_profile] Fix signed-ness warnings in test
Follow-up from PR ##89838. Some build bots warn-as-error
about signed/unsigned comparison in CtxInstrProfilingTest.

Example: https://lab.llvm.org/buildbot/#/builders/37/builds/34610
2024-05-07 23:27:54 -07:00
Mircea Trofin
ccf765cfd5 [compiler-rt][ctx_profile] Add the instrumented contextual profiling APIs (#89838)
APIs for contextual profiling. `ContextNode` is the call context-specific counter buffer. `ContextRoot` is associated to those functions that constitute roots into interesting call graphs, and is the object on which we hang off `Arena`s for allocating `ContextNode`s, as well as the `ContextNode` corresponding to such functions. Graphs of `ContextNode`s are accessible by one thread at a time.

(Tracking Issue: #89287, more details in the RFC referenced there)
2024-05-07 15:01:15 -07:00
luolent
a98a6e95be Add clarifying parenthesis around non-trivial conditions in ternary expressions. (#90391)
Fixes [#85868](https://github.com/llvm/llvm-project/issues/85868)

Parenthesis are added as requested on ternary operators with non trivial conditions.

I used this [precedence table](https://en.cppreference.com/w/cpp/language/operator_precedence) for reference, to make sure we get the expected behavior on each change.
2024-05-04 18:38:45 +01:00
Igor Kudrin
2224dce7e4 [DFSan] Replace cat with cmake -E cat (#90557)
`CMake` supports [this
command](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-E-arg-cat)
as of version 3.18. [D151344](https://reviews.llvm.org/D151344) bumped
the minimum version to 3.20, so, it is now possible to remove the
dependency on the external utility. This helps to cross-compile from
Windows to Linux without installing additional tools, such as MSYS2.
2024-04-30 13:57:58 -07:00
ChiaHungDuan
11f4f458d9 [scudo] Support setting default value of ReleaseToOsIntervalMs in config (#90256) 2024-04-29 08:41:46 -07:00
ChiaHungDuan
6904e0e885 [scudo] Reflect the allowed values for M_DECAY_TIME on Android (#89114) 2024-04-26 09:55:42 -07:00
Nikita Popov
47682e4b4a Revert "[ORC] Implement basic reoptimization. (#67050)"
This reverts commit 0d288e5b0c.

Breaks the build.
2024-04-26 14:47:48 +09:00
Sunho Kim
0d288e5b0c [ORC] Implement basic reoptimization. (#67050) 2024-04-25 22:43:06 -07:00
ChiaHungDuan
c7f4b3e1bd [scudo] Fix the misused Exhausted in region allocation (#89852)
`Region->Exhausted` indicates that we don't have more pages to create
new blocks in the region. It has different meaning from region
allocation failure.

Also fix a minor lint in popBlocks()
2024-04-25 19:40:40 -07:00
Fabio D'Urso
b7e9dae6f6 [scudo] Improve readability of MemMapFuchsia's error handling (#90102)
By expressing the conditions covered by MAP_ALLOWNOMEM in a more
direct way.
2024-04-25 23:23:42 +02:00
Dimitry Andric
0f329e0246 [sanitizer_symbolizer] Cast arguments for format strings in markup (#89815)
When compiling the common sanitizer libraries, there are many warnings
about format specifiers, similar to:

    compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp:31:32: warning: format specifies type 'void *' but the argument has type 'uptr' (aka 'unsigned long') [-Wformat]
       31 |   buffer->AppendF(kFormatData, DI->start);
          |                   ~~~~~~~~~~~  ^~~~~~~~~
    compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h:33:46: note: format string is defined here
       33 | constexpr const char *kFormatData = "{{{data:%p}}}";
          |                                              ^~
          |                                              %lu
    compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cpp:46:43: warning: format specifies type 'void *' but the argument has type 'uptr' (aka 'unsigned long') [-Wformat]
       46 |   buffer->AppendF(kFormatFrame, frame_no, address);
          |                   ~~~~~~~~~~~~            ^~~~~~~
    compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup_constants.h:36:48: note: format string is defined here
       36 | constexpr const char *kFormatFrame = "{{{bt:%u:%p}}}";
          |                                                ^~
          |                                                %lu
    ...

This is because `uptr` is dependent on the platform, and can be either
`unsigned long long`, `unsigned long`, or `unsigned int`.

To fix the warnings, cast the arguments to the expected type of the
format strings.
2024-04-25 17:00:26 +02:00
Frederic Cambus
791161516f [compiler-rt] Update libFuzzer build script to use C++17. (#89604)
libFuzzer uses std::clamp which was introduced in C++17.
2024-04-24 21:18:24 +02:00
Fabio D'Urso
9cbf96ad5b Allow ZX_ERR_NO_RESOURCES with MAP_ALLOWNOMEM on Fuchsia (#89767)
This can occur if the virtual address space is (almost) entirely
mapped or heavily fragmented.
2024-04-24 15:06:25 +02:00
Mircea Trofin
579efe011b Temporarily remove clang_rt.ctx_profile target
Trying to address the build failure on the `clang-ve-ninja`bot, which
appears hard to repro locally. The target isn't needed currently (there
are unit tests exercising the new functionality). Removing it for now
to green-ify the build bot.
2024-04-23 00:46:52 +02:00
Mircea Trofin
a3e7a125e1 Reapply "[compiler-rt][ctx_instr] Add ctx_profile component" (#89625)
This reverts commit 8b2ba6a144.

The uild errors (see below) were likely due to the same issue PR #88074 fixed. Addressed by following that PR.

https://lab.llvm.org/buildbot/#/builders/165/builds/52789
https://lab.llvm.org/buildbot/#/builders/91/builds/25273
2024-04-22 22:33:09 +02:00
David CARLIER
8482dbdcd2 compiler-rt: fix few builtins build warnings. (#88991) 2024-04-22 21:25:56 +01:00
Mircea Trofin
8b2ba6a144 Revert "[compiler-rt][ctx_instr] Add ctx_profile component" (#89625)
Reverts llvm/llvm-project#89304

Some build bot failures - will fix and reland.

Example: https://lab.llvm.org/buildbot/#/builders/165/builds/52789
2024-04-22 09:35:49 -07:00
Mircea Trofin
6ad22c879a [compiler-rt][ctx_instr] Add ctx_profile component (#89304)
Add the component structure for contextual instrumented PGO and the bump allocator + test.

(Tracking Issue: #89287, RFC referenced there)
2024-04-22 09:24:22 -07:00
Fabio D'Urso
adc11b34b1 Sync FuchsiaConfig with downstream's custom_scudo_config.h (#89244)
Downstream disabled EnableContiguousRegions on RISCV-64 to avoid
running out of virtual memory, but our tests still use the internal
FuchsiaConfig class, which therefore needs to be changed too.
2024-04-19 21:27:53 +02:00
David Spickett
c674dbc2a8 Revert "[FMV] Remove useless features according the latest ACLE spec." (#89184)
Reverts llvm/llvm-project#88965

This caused a test suite failure:
https://lab.llvm.org/buildbot/#/builders/185/builds/6583
NOEXE: test-suite::aarch64-acle-fmv-features.test

```
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/test/test-suite/SingleSource/UnitTests/AArch64/acle-fmv-features.c:98:1: error: redefinition of 'check_sha1'
   98 | CHECK(sha1, {
      | ^
/home/tcwg-buildbot/worker/clang-aarch64-lld-2stage/test/test-suite/SingleSource/UnitTests/AArch64/acle-fmv-features.c:36:17: note: expanded from macro 'CHECK'
   36 |     static void check_##X(void) { \
      |                 ^
<scratch space>:150:1: note: expanded from here
  150 | check_sha1
      | ^
```

I presume that the useless features need to be removed from the fmv test
as well.
2024-04-18 09:25:47 +01:00
Alexandros Lamprineas
19c6a7feca [FMV] Remove useless features according the latest ACLE spec. (#88965)
As explained in https://github.com/ARM-software/acle/pull/315 we
are deprecating features which aren't adding any value. These are:

sha1, pmull, dit, dgh, ebf16, sve-bf16, sve-ebf16, sve-i8mm,
sve2-pmull128, memtag2, memtag3, ssbs2, bti, ls64_v, ls64_accdata
2024-04-17 17:16:58 +01:00
Alexander Richardson
abd5e45a96 [compiler-rt] Use __atomic builtins whenever possible
The code in this file dates back to 2012 when Clang's support for atomic
builtins was still quite limited. The bugs referenced in the comment
at the top of the file have long been fixed and using the compiler
builtins directly should now generate slightly better code.
Additionally, this allows using the atomic builtin header for platforms
where the __sync_builtins are lacking (e.g. Arm Morello).

This change does not introduce any code generation changes for
__tsan_read*/__tsan_write* or __tsan_func_{entry,exit} on x86, which
indicates the previously noted compiler issues have been fixed.

We also have to touch the non-clang codepaths here since the only way we
can make this work easily is by making the memory_order enum match the
compiler-provided macros, so we have to update the debug checks that
assumed the enum was always a bitflag.

The one downside of this change is that 32-bit MIPS now definitely
requires libatomic (but that may already have been needed for RMW ops).

Reviewed By: dvyukov

Pull Request: https://github.com/llvm/llvm-project/pull/84439
2024-04-17 08:42:41 -07:00
Fangrui Song
9022d9c102 [xray] Apply default visibility to __xray_CustomEvent/__xray_TypedEvent
`__xray_customevent` and `__xray_typedevent` are built-in functions in
Clang. With -fxray-instrument, they are lowered to `__xray_CustomEvent`
(with 2 arguments) or `__xray_TypedEvent` (with 3 arguments).

xray patching is supported for shared objects, but they may contain
`__xray_customevent` and `__xray_typedevent` references that need to be
satisfied by default visibility definitions exported by the executable.

lld since df54f627fa, like GNU ld, catches
the scenario at link time.
2024-04-12 10:49:39 -07:00
Cyrill Leutwiler
bd32aaa8c9 [RISCV] Support rv{32, 64}e in the compiler builtins (#88252)
Register spills (save/restore) in RISC-V embedded work differently
because there are less registers and different stack alignment.

[GCC equivalent
](https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/riscv/save-restore.S#L298C16-L336)

Follow up from #76777.

---------

Signed-off-by: xermicus <cyrill@parity.io>
2024-04-11 13:11:51 +08:00
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
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
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
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