18222 Commits

Author SHA1 Message Date
David CARLIER
062d78ef58
[compiler-rt][fuzzer] windows build unbreak proposal. (#83538)
shuffling the order of its includes.
2024-03-01 09:13:11 +00:00
David CARLIER
43bcedd1f0
[compiler-rt] fix __sanitizer_siginfo type on freebsd. (#77379)
mostly interested in the first half of the type, adding also compile
time check.
2024-03-01 07:26:47 +00:00
David CARLIER
2cdf611c02
[compiler-rt][Fuzzer] SetThreadName windows implementation new try. (#76761)
SetThreadDescription symbol needs to be dynamically loaded before usage.
Then using a wide string buffer, since we re using a null terminated
string, we can use MultiByteToWideChar -1 as 4th argument to finally set
the thread name.

Previously `SetThreadDescription` was called directly causing crash.
It was reverted in dd3aa26fc8e9de37a39611f7a6a602bcb4153784
2024-02-29 17:47:05 -08:00
David CARLIER
7ceb74f5b7
[compiler-rt] fix BSD procmaps stack frame size limit warning. (#82887) 2024-03-01 01:25:54 +00:00
Florian Mayer
b9b8333ed5
[HWASan] add test for hwasan_handle_longjmp ignore logic (#83359) 2024-02-29 15:06:58 -08:00
Andrei Homescu
bf0f874e48
[scudo] Avoid splitting aligned allocations on Trusty (#69281)
Don't use multiple tagged pages at the beginning of an allocation, since
it prevents using such allocations for memrefs, and mappings aren't
reused anyway since Trusty uses MapAllocatorNoCache.
Upstreamed from https://r.android.com/2537251.

Co-authored-by: Marco Nelissen <marcone@google.com>
2024-02-29 15:05:47 -08:00
ChiaHungDuan
f83f7128b3
[scudo][NFC] Explicit type casting to avoid compiler warning (#83355) 2024-02-28 16:15:31 -08:00
ChiaHungDuan
1a7776abe6
Reland "[scudo] Store more blocks in each TransferBatch" (#83078) (#83081)
This reverts commit 056d62be38c5db3d8332ac300c4ff29214126697.

Fixed the number of bytes copied in moveNToArray()
2024-02-28 12:09:49 -08:00
Fangrui Song
062cfada64
[builtins] Disable COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY by default (#83201)
Most of GCC's Linux targets have a link spec
`%{!static|static-pie:--eh-frame-hdr}` that doesn't pass --eh-frame-hdr
for `-static` links. `-static` links are supposed to utilize
`__register_frame_info` (called by `crtbeginT.o`, not by crtbegin.o or
crtbeginS.o) as a replacement.

compiler-rt crtbegin (not used with GCC) has some ehframe code, which is
not utilized because Clang driver unconditionally passes --eh-frame-hdr
for Linux targets, even for -static. In addition, LLVM libunwind
implements `__register_frame_info` as an empty stub.

Furthermore, in a non-static link, the `__register_frame_info`
references can cause an undesired weak dynamic symbol.

For now, just disable the config by default.
2024-02-27 16:32:53 -08:00
Mingming Liu
78647116d8
[nfc][compiler-rt]Remove round-up in __llvm_profile_get_num_data (#83194)
- Update instrprof-basic.c as a regression test.
2024-02-27 14:34:07 -08:00
Alexander Richardson
5e31e82698
[compiler-rt] Use locally configured llvm-lit for standalone builds (#83178)
When building a standalone build with
`-DLLVM_CMAKE_DIR=$HOME/output/llvm-install
-DCOMPILER_RT_INCLUDE_TESTS=ON`, the current code will attempt to use
`LLVM_DEFAULT_EXTERNAL_LIT` which is set to
`$HOME/output/llvm-install/bin/llvm-lit` inside `LLVMConfig.cmake` even
though it is not actually installed. If we are adding the llvm-lit
subdirectory, we can use `get_llvm_lit_path()` immediately afterwards to
set LLVM_EXTERNAL_LIT so that subsequent calls within
`add_lit_testsuite()` use llvm-lit from the current build directory
instead of the nonexistant one.
2024-02-27 21:00:07 +00:00
Alex Richardson
19181f24e5 [compiler-rt] Add missing include to sanitizer_stackdepot_test.cpp
Without this change I am seeing build failures due to missing
std::next_permutation since my standard library does implicitly pull
in <algorithm> anymore.
2024-02-27 11:10:10 -08:00
Mingming Liu
16e74fd489
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](d0757f46b3).
Previous commits are restored from the remote branch with timestamps.

1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](f95b2f1acf))
   
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](a825d2a4ec (diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121))

**Original Description**

* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
  - Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
  
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
  
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600

---------

Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
Enna1
371e6d0f24
[NFC][hwasan] Do not include sanitizer_placement_new.h in header files (#82993)
Do not include sanitizer_placement_new.h into header files, only into
source files.
2024-02-26 15:45:06 -08:00
ChiaHungDuan
056d62be38
Revert "[scudo] Store more blocks in each TransferBatch" (#83078)
Reverts llvm/llvm-project#70390

There's a bug caught by
`ScudoCombinedTestReallocateInPlaceStress_DefaultConfig.ReallocateInPlaceStress`
with gwp asan. It's an easy fix but given that this is a major change, I
would like to revert it first
2024-02-26 15:21:32 -08:00
Fabio D'Urso
cda413087c
[scudo] Do not unmap the memory containing the this object in unmapRingBuffer (#83034) 2024-02-27 00:00:20 +01:00
gulfemsavrun
23f895f656
[InstrProf] Single byte counters in coverage (#75425)
This patch inserts 1-byte counters instead of an 8-byte counters into
llvm profiles for source-based code coverage. The origial idea was
proposed as block-cov for PGO, and this patch repurposes that idea for
coverage: https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4

The current 8-byte counters mechanism add counters to minimal regions,
and infer the counters in the remaining regions via adding or
subtracting counters. For example, it infers the counter in the if.else
region by subtracting the counters between if.entry and if.then regions
in an if statement. Whenever there is a control-flow merge, it adds the
counters from all the incoming regions. However, we are not going to be
able to infer counters by subtracting two execution counts when using
single-byte counters. Therefore, this patch conservatively inserts
additional counters for the cases where we need to add or subtract
counters.

RFC:
https://discourse.llvm.org/t/rfc-single-byte-counters-for-source-based-code-coverage/75685
2024-02-26 14:44:55 -08:00
ChiaHungDuan
1865c7ea85
[scudo] Store more blocks in each TransferBatch (#70390)
Instead of always storing the same number of blocks as cached, we prefer
increasing the utilization by saving more blocks in a single
TransferBatch. This may slightly impact the performance, but it will
save a lot of memory used by BatchClassId (especially for larger
blocks).
2024-02-26 11:04:08 -08:00
David CARLIER
529b5705db
Revert "[compiler-rt] simplifying ::ReExec for freebsd. (#79711)" (#82933)
This reverts commit 691b12a2dcc12fa43517d23f2a9b6039616eebc8.
2024-02-25 21:10:01 +00:00
Mingming Liu
a8c3b3e20d
[nfc][compiler-rt]Replace Type::getInt8PtrTy with PointerType::getUnqual as a clean-up (#82434)
This is a follow up of
7b9d73c2f9
and
5ef9ba7412
* The definition of `Type::getInt8PtrTy` is deleted. This doesn't cause
a compile error because the `Initializer` part of the macro doesn't run.
2024-02-24 22:30:31 -08:00
Florian Mayer
6dd6d487d0
[NFC] Make RingBuffer an atomic pointer (#82547)
This will allow us to atomically swap out RingBuffer and StackDepot.

Patched into AOSP and ran debuggerd_tests.
2024-02-23 11:28:20 -08:00
Thurston Dang
0673fb6e77
[hwasan] Add missing printf parameter in __hwasan_handle_longjmp (#82559)
The diagnostic message had four format specifiers but only three
parameters. This patch adds what I assume to be the missing
parameter.
2024-02-23 09:53:55 -08:00
Freddy Ye
1fe6be8794
[X86] Support APXF to enable __builtin_cpu_supports. (#80636)
For referring, APX's spec:
https://cdrdv2.intel.com/v1/dl/getContent/784266
APX's index in libgcc:
https://github.com/gcc-mirror/gcc/blob/master/gcc/common/config/i386/i386-cpuinfo.h#L267
2024-02-23 15:18:42 +08:00
Pavel Iliin
568babab7e
[AArch64] Implement __builtin_cpu_supports, compiler-rt tests. (#82378)
The patch complements https://github.com/llvm/llvm-project/pull/68919
and adds AArch64 support for builtin
`__builtin_cpu_supports("feature1+...+featureN")`
which return true if all specified CPU features in argument are
detected. Also compiler-rt aarch64 native run tests for features
detection mechanism were added and 'cpu_model' check was fixed after its
refactor merged https://github.com/llvm/llvm-project/pull/75635 Original
RFC was https://reviews.llvm.org/D153153
2024-02-22 23:33:54 +00:00
Florian Mayer
6ddb25ed9c
[scudo] increase frames per stack to 16 for stack depot (#82427)
8 was very low and it is likely that in real workloads we have more than
an average of 8 frames per stack given on Android we have 3 at the
bottom: __start_main, __libc_init, main, and three at the top: malloc,
scudo_malloc and Allocator::allocate. That leaves 2 frames for
application code, which is clearly unreasonable.
2024-02-22 11:19:02 -08:00
Mingming Liu
0e8d1877cd
Revert type profiling change as compiler-rt test break on Windows. (#82583)
Examples
https://lab.llvm.org/buildbot/#/builders/127/builds/62532/steps/8/logs/stdio
2024-02-21 21:41:33 -08:00
Mingming Liu
db7e9e6841
[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling. (#81691)
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
  - Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
  
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
  
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600

---------

Co-authored-by: modiking <modiking213@gmail.com>
2024-02-21 20:59:42 -08:00
PiJoules
a976e3c695
[compiler-rt][Fuchsia] Propogate raw_report to UnmapOrDieVmar (#82566)
As of #77488, UnmapOrDie now accepts raw_report which allows the program
to crash without calling Report(). We should propogate this value
through UnmapOrDieVmar and have that call ReportMunmapFailureAndDie
which uses `raw_report`.
2024-02-21 17:53:53 -08:00
Florian Mayer
d17eade22a
Do not call disable / enable on null depot (#82542)
depot can be null if allocation_ring_buffer_size=0
2024-02-21 14:28:34 -08:00
Alexander Richardson
99c457dc2e
Unbreak *tf builtins for hexfloat (#82208)
This re-lands cc0065a7d082f0bd322a538cf62cfaef1c8f89f8 in a way that 
keeps existing targets working.

---------

Original commit message:
#68132 ended up removing
__multc3 & __divtc3 from compiler-rt library builds that have
QUAD_PRECISION but not TF_MODE due to missing int128 support. 
I added support for QUAD_PRECISION to use the native hex float long double representation.

---------

Co-authored-by: Sean Perry <perry@ca.ibm.com>
2024-02-21 20:59:56 +00:00
Mingming Liu
4247175d45
[nfc]For InstrProfData.inc, clang-format functions and opt-out of formatting on the rest (#82057)
Without this, each time `InstrProfData.inc` is modified (like in
https://github.com/llvm/llvm-project/pull/81691), pre-commit CI
clang-format aggressively formats many lines in an unreadable way. Pull
request with red pre-commit checks are usually frowned upon.

* Use `// clang-format:<reason>` instead of `/* clang-format */`. The
former
[allows](563ef30601/clang/lib/Format/Format.cpp (L4108-L4113))
specifying a reason but the latter is
[not](563ef30601/clang/lib/Format/Format.cpp (L4105-L4106)).
- Filed https://github.com/llvm/llvm-project/issues/82426 to track the
issue in clang-format.
2024-02-21 10:55:59 -08:00
Jooyung Han
ec516ff3e6
Fix __isOSVersionAtLeast for Android (#80496)
Allow pre-release APIs on pre-release devices.

The current implementation requires __ANDROID_API_FUTURE__ to use new
APIs on pre-release system. This makes it hard to maintain the codebase
because it should be switched a concrete version (e.g. __ANDROID_API_X__
on release of X).

Instead, we can just allow pre-release APIs on pre-release system
without mandating the major version of __ANDROID_API_FUTURE__.

Note that this doesn't make API guards just no-op in pre-release builds.
We can still rely on its compile-time checks and it still works as
expected with release builds. Even with pre-release builds, it's the
same as before because we would pass __ANDROID_API_FUTURE__ to make the
calls anyway.
2024-02-20 21:46:25 -08:00
James Robinson
7f3980a7b2
[Fuzzer] Use user signal to coordinate handler shutdown (#82067)
This updates the signal handle thread coordinating to use a user signal
bit on the SignalHandlerEvent to coordinate shutdown instead of closing
the event handle. Closing the event handle is racy as the handle may be
closed before the signal handler thread resolves the handle value in
_zx_object_wait_many() and we would like to make this an explicit error.
Using the user signal bit 1 instead and then closing the event object
after the signal handler thread is joined cannot race as the wait will
terminate whether the signal is raised before or after the wait begins.
2024-02-20 09:49:20 -08:00
Enna1
d043b4bc7e
[Sanitizer][Windows] Fix Windows buildbot failure after 64790064e82467b43c04a70b6e9873e6939be81f (#82215)
In #77488, a param raw_report is added for function UnmapOrDie(), causes
the Windows buildbot failure:
- https://lab.llvm.org/buildbot/#/builders/127/builds/62395
- https://lab.llvm.org/buildbot/#/builders/265/builds/2662

This patch should fix the Windows buildbot failure.
2024-02-19 16:42:48 +08:00
Enna1
9b76515b1b
[sanitizer][fuchsia] Fix fuchsia buildbot failure after 64790064e82467b43c04a70b6e9873e6939be81f (#82202)
In https://github.com/llvm/llvm-project/pull/77488, a param `raw_report`
is added for function `UnmapOrDie()`.
But missing the corresponding change for fuchsia, causes the buildbot
failure, see https://lab.llvm.org/buildbot/#/builders/98/builds/33593.
This patch should fix the fuchsia buildbot failure.
2024-02-19 12:14:49 +08:00
Enna1
64790064e8
[asan] Use InternalMmapVectorNoCtor for error_message_buffer, reallocate if needed (#77488)
- Add a param `raw_report` which defaults to false for function
`UnmapOrDie()` like we do for `MmapOrDie()`
- Add a template param `raw_report` which defaults to false for class
`InternalMmapVectorNoCtor`. `raw_report` will be passed to `MmapOrDie()`
and `UnmapOrDie()` when they are called in class
`InternalMmapVectorNoCtor` member functions.
- Use `InternalMmapVectorNoCtor<char, true>` for `error_message_buffer`
and reallocate if needed.
2024-02-19 10:27:54 +08:00
Florian Mayer
b366643ca3 [NFC] fix typo 2024-02-16 23:26:49 -08:00
Florian Mayer
133b6a088e [NFC] fix type mismatch in test. 2024-02-16 23:22:19 -08:00
Florian Mayer
3da0166331 Reland^2 "[scudo] resize stack depot for allocation ring buffer"
Fix some warnings by matching types.

This reverts commit e1164d063558b1e89f20109d83c079caae1825d8.
2024-02-16 22:59:53 -08:00
Fangrui Song
8443ce563b
[sanitizer] Lift AsanDoesNotSupportStaticLinkage to sanitizer_common.h. NFC (#80948)
The `_DYNAMIC` reference from `AsanDoesNotSupportStaticLinkage` ensures
that `clang++ -fsanitize=address -static` gets a linker error.
`MemprofDoesNotSupportStaticLinkage` is similar for `-fmemory-profile`.
Move the functions to sanitizer_common.h to be used by more sanitizers
on ELF platforms.

Fuchsia does not use interposition and opts out the check (its
`AsanDoesNotSupportStaticLinkage` is a no-op).
2024-02-16 19:36:39 -08:00
Florian Mayer
e1164d0635
Revert "Reland "[scudo] resize stack depot for allocation ring buffer"" (#82088)
Reverts llvm/llvm-project#81028
2024-02-16 17:58:54 -08:00
Florian Mayer
aff6cb4957
Reland "[scudo] resize stack depot for allocation ring buffer" (#81028)
First commit of the stack is a clean reland, second is  the fix.

There was a typo in the `static_assert` that meant we were asserting the
size of the pointer, not the struct.

Also changed `alignas` to be more intuitive, but that is NFC.

Ran builds in Android here: https://r.android.com/2954411
2024-02-16 17:10:54 -08:00
David CARLIER
691b12a2dc
[compiler-rt] simplifying ::ReExec for freebsd. (#79711)
taking the getauxval route since elf_aux_info is available since FBSD
12.
2024-02-16 23:59:38 +00:00
Fabio D'Urso
cc673867d9
[scudo] Add ALWAYS_INLINE to ScopedTSD ctor (#81982)
Fix for performance regression introduced by #80061 that slowed
down Fuchsia's MallocFree microbenchmark by 3.5 - 8%
2024-02-16 19:48:07 +01:00
Wael Yehia
15cccc5591
[AIX] Add a dummy variable in the __llvm_orderfile section (#81968)
to satisfy the __start___llvm_orderfile reference when linking with
-bexpfull and -fprofile-generate on AIX.
2024-02-16 12:55:20 -05:00
Rainer Orth
8c2033719a
[asan] Intercept __makecontext_v2 on Solaris/SPARC (#81588)
As detailed in [GCC PR
sanitizer/113785](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113785),
the GCC test `c-c++-common/asan/swapcontext-test-1.c` `FAIL`s on
Solaris/sparc.

This is due to the fact that Solaris 10/SPARC changed the semantics of
`makecontext` so `ucontext_t.uc_stack.ss_sp` refers to the stack base
address. To maintain binary compatiblity, the external name was changed
to `__makecontext_v2`, keeping the old version.

To match this, `__makecontext_v2` needs to be intercepted instead of
`makecontext`.

Tested on GCC trunk on `sparc-sun-solaris2.11`, `i386-pc-solaris2.11`,
and `x86_64-pc-linux-gnu`.

Also tested on the same targets on LLVM `main`. However, this only
proves that Linux/x86_64 isn't broken, since all `makecontext` tests are
Linux-specific.
2024-02-16 11:42:13 +01:00
Vitaly Buka
39e32b451c
[hwasan] Fix stack tag mismatch report (#81939)
Existing code worked only for local, recorder FP, and the faulty address
are the same 1 MiB page.

Now, instead of guessing FP, we guess variable address.
We need to try just two cases of addresses around of faulty one.

Fixes https://github.com/google/sanitizers/issues/1723
2024-02-15 16:59:49 -08:00
Vitaly Buka
72e14fb33f [NFC][hwasan] Reduce nesting in function 2024-02-15 15:29:12 -08:00
Vitaly Buka
fbacf70f64 [NFC][hwasan] Add CHECK_LT(fp, kRecordFPModulus) 2024-02-15 15:29:12 -08:00
Ellis Hoag
f872706615
[InstrProf] Test that entry coverage counts accumulate (#81806) 2024-02-15 08:06:15 -10:00