Commit Graph

13303 Commits

Author SHA1 Message Date
Vitaly Buka
0e07bf91f7 [NFC][sanitizer] Rename to Lock{Before,After}Fork StackDepotBase locking (#76303)
Followup to #76279
2023-12-23 16:23:55 -08:00
Vitaly Buka
f78a742ab8 [NFC][sanitizer] Rename Lock{Before,After}Fork suffixes locking StackDepotBase (#76279)
This is preparation for performance optimization.

We need to highlight that this is very specific lock, and should not be
used for other purposes.
Add `fork_child` parameter to distinguish processes after fork.
2023-12-22 23:38:01 -08:00
Rainer Orth
5cb7534a7d [tsan] Only intercept pthread_mutex_clocklock on Linux (#76220)
`tsan_interceptors_posix.cpp` doesn't compile on FreeBSD 14.0/amd64:
```
In file included from /vol/llvm/src/llvm-project/local-freebsd/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:25:
/vol/llvm/src/llvm-project/local-freebsd/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp: In function ‘void __tsan::InitializeInterceptors()’:
/vol/llvm/src/llvm-project/local-freebsd/compiler-rt/lib/tsan/rtl/../../interception/interception.h:243:25: error: ‘real_pthread_mutex_clocklock’ is not a member of ‘__interception’; did you mean ‘real_pthread_mutex_unlock’?
```
Fixed by wrapping the `TSAN_INTERCEPT` invocation with `SANITIZER_LINUX`
as is already done for the interceptor definition.

Tested on `amd64-pc-freebsd14.0`.
2023-12-22 15:58:03 +01:00
Aiden Grossman
a15532d764 [X86] Add CPU detection for more znver2 CPUs (#74955)
This patch adds proper detection support for more znver2 CPUs.

Specifically, this adds in support for CPUs codenamed Renoir, Lucienne,
and Mendocino.

This was originally proposedfor Renoir in
https://reviews.llvm.org/D96220 and
got approved, but slipped through the cracks. However, there is still a
demand for this feature.

In addition to adding support for more znver2 CPUs, this patch also includes
some additional refactoring and comments related to cpu model
information for zen CPUs.

Fixes https://github.com/llvm/llvm-project/issues/74934.
2023-12-21 23:39:28 -08:00
Vitaly Buka
7db28dd3f8 [hwasan] Classify stack overflow, and use after scope (#76133)
We can't distinguish UAR and UAS, but by definition
UAR is already UAS.
2023-12-21 17:51:14 -08:00
Vitaly Buka
7c3b67d203 [hwasan] Respect strip_path_prefix printing locals (#76132) 2023-12-21 16:03:06 -08:00
Vitaly Buka
528150b90b [hwasan] Separate sections in report (#76130)
It makes them easier to read.
2023-12-21 12:37:17 -08:00
Vitaly Buka
5e92fa69ea [NFC][sanitizer] Fix typo in comment 2023-12-20 18:40:26 -08:00
kda
9e012c76fb [sanitizer] Add graceful handling of exceeding StackStore limit. (#76115) 2023-12-20 17:58:03 -08:00
Vitaly Buka
3dca63a32f [symbolizer] Don't threat symbolizer API as optional (#76103)
There is an assumption that we dont need to to mix sanitizer with
symbolizer from different LLVM revison. If so we can detect it by
`__sanitizer_symbolize_code` and assume that the rest is present.
2023-12-20 15:38:43 -08:00
Zequan Wu
688fa35df0 [Profile] Dump binary id to raw profiles on Windows. (#75618)
#74652 adds `__buildid` symbol which allows us to dump it at runtime.
2023-12-20 10:41:36 -05:00
Jon Roelofs
394e481a38 fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
https://github.com/llvm/llvm-project/pull/75635#issuecomment-1863662913
2023-12-19 17:48:24 -07:00
Ben Langmuir
dc58f781b6 [ORC-RT] Fix ptrauth signing for dlsym return value (#75972)
dlsym signs text symbols as functions rather than data in dyld, so match
that for orc runtime dlsym. This fixes run_program on arm64e.
2023-12-19 14:56:42 -08:00
Jon Roelofs
52e7b6f5c5 fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
https://github.com/llvm/llvm-project/pull/75635#issuecomment-1863433937

```
/b/s/w/ir/x/w/llvm_build/./bin/clang --target=aarch64-unknown-linux-gnu --sysroot=/b/s/w/ir/x/w/cipd/linux -DHAS_ASM_LSE -DVISIBILITY_HIDDEN  --target=aarch64-unknown-linux-gnu -O2 -g -DNDEBUG -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -DCOMPILER_RT_HAS_FLOAT16 -MD -MT CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -MF CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o.d -o CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
In file included from /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c:43:
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/sysauxv.inc:5:41: error: use of undeclared identifier 'HWCAP_ATOMICS'
    5 |   __aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
      |                                         ^
1 error generated.
```
2023-12-19 14:20:27 -07:00
Shoaib Meenai
85d5ed81b1 [compiler-rt] Fix obvious syntax error
This is breaking Android compiler-rt builds.
2023-12-19 12:59:05 -08:00
Jon Roelofs
c88e74c26d fixup! fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI 2023-12-19 11:46:40 -07:00
Jon Roelofs
a5a17e8fad fixup! [builtins] Refactor cpu_model support to reduce #if nesting. NFCI 2023-12-19 11:39:13 -07:00
Jon Roelofs
256b214b6b [builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)
This is a re-land of https://github.com/llvm/llvm-project/pull/73685
2023-12-19 11:20:03 -07:00
Jon Roelofs
9237cfa65b [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
Reviewers: petrhosek, DavidSpickett

Pull Request: https://github.com/llvm/llvm-project/pull/75635
2023-12-19 11:19:51 -07:00
Jon Roelofs
b72e160914 Revert "[builtins] Refactor cpu_model support to reduce #if nesting. NFCI"
This reverts commit 025d048b1c.

It broke one of the sanitizer bots:

https://lab.llvm.org/buildbot/#/builders/240/builds/20666
2023-12-19 11:17:24 -07:00
Jon Roelofs
b8b40e2fb9 Revert "[builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)"
This reverts commit 17aa520171.
2023-12-19 11:17:04 -07:00
Jon Roelofs
17aa520171 [builtins][arm64] Implement __init_cpu_features_resolver on Apple platforms (#75636)
This is a re-land of https://github.com/llvm/llvm-project/pull/73685
2023-12-19 11:11:42 -07:00
Jon Roelofs
025d048b1c [builtins] Refactor cpu_model support to reduce #if nesting. NFCI
Reviewers: petrhosek, DavidSpickett

Pull Request: https://github.com/llvm/llvm-project/pull/75635
2023-12-19 11:09:50 -07:00
David Spickett
849c951191 [compiler-rt][asan] Remove reference to asan_lock.h which was removed.
By commit 12ed2c90a1.

Fixes #75736
2023-12-19 09:26:14 +00:00
Florian Mayer
4f9ad0f856 [scudo] [NFC] remove unused method 2023-12-18 18:54:32 -08:00
Thomas Schenker
3effc191e3 [sanitizers] improve debug output for failed suppression parse (#72066)
If a sanitizer suppression file can not be parsed, add the supported
suppression types to the error message.

See https://github.com/llvm/llvm-project/issues/72060.

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2023-12-18 17:10:55 -08:00
Fangrui Song
e777317227 [tsan] Make pthread_mutex_clocklock Linux only
Many systems (glibc<2.30, Bionic before 2019, musl, macOS, etc) do not have the function.
2023-12-18 15:01:25 -08:00
Fangrui Song
b9935bb02a asan_static x86-64: Support 64-bit ASAN_SHADOW_OFFSET_CONST (#75748)
Fix #57086: when ASAN_SHADOW_OFFSET_CONST >= 0x80000000 (FreeBSD,
NetBSD, etc), `movsbl ASAN_SHADOW_OFFSET_CONST(%r10),%r10d` has an
invalid displacement (not representable as a signed 32-bit integer),
which will be diagnosed by GNU assembler.

```
% cat a.s
movsbl 0x80000000(%r10),%r10d
% as a.s
a.s: Assembler messages:
a.s:1: Error: 0x80000000 out of range of signed 32bit displacement
% clang -c a.s
```

The integrated assembler after #75747 will diagnose the invalid
displacement as well.
```
% clang -c a.s
a.s:1:19: error: displacement 2147483648 is not within [-2147483648, 2147483647]
movsbl 0x80000000(%r10),%r10d
                  ^
```

If ASAN_SHADOW_OFFSET_CONST cannot be encoded as a displacement, switch
to `movabsq+movsbl`.
2023-12-18 13:48:46 -08:00
Yvan
5ccad1b9c3 [TSAN] add instrumentation for pthread_mutex_clocklock (#75713)
The function `pthread_mutex_clocklock` is not supported by TSAN yet,
which is mentioned by[
llvm/llvm-project/issues/62623](https://github.com/llvm/llvm-project/issues/62623#issue-1701600538).
This patch is to handle this function.
2023-12-18 13:39:01 -08:00
Azharuddin Mohammed
2a03854e4c [sanitizer] [Darwin] Disable InstallAtForkHandler
This is a followup to d01be3c631.
2023-12-18 12:32:17 -08:00
Vitaly Buka
d01be3c631 [sanitizer] Disable InstallAtForkHandler on Solaris, NetBSD (#75659)
Handlers need missing FutexWait implementation.

Reported in #75290.
2023-12-18 10:50:55 +01:00
David Spickett
3a31cf8853 Revert "[builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)"
And its follow up "fixup! [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)".

This reverts commit 5b470522cd and
212a5e1b9c.

Due to build failures on Windows:
```
C:\Users\Tcwg\llvm-worker\clang-arm64-windows-msvc-2stage\llvm\compiler-rt\lib\builtins\cpu_model.c(1571,2): error: No support for checking hwcap on this platform yet.
 1571 | #error No support for checking hwcap on this platform yet.
      |  ^
```
https://lab.llvm.org/buildbot/#/builders/120/builds/5990
2023-12-15 12:45:50 +00:00
Florian Mayer
fd8e854a86 [scudo] simplify flag parser out of bounds logic (#72371)
almost NFC, just that now we accept INT_MIN and INT_MAX

as discussed in https://r.android.com/2831100, but I didn't add the
*ValueEnd != Value check because I want to keep this change
behaviour-keeping.
2023-12-14 16:35:58 -08:00
Ben Langmuir
1c58a6b8b4 [orc-rt] Add ORC_ENABLE_OSX to control whether to build the orc runtime (#75536)
Embedded Darwin platforms have generalized COMPILER_RT_ENABLE_<PLATFORM>
configuration settings, but currently 'osx' is always eabled on Darwin.
Add ORC_ENABLE_OSX to allow explicitly *disabling* the orc runtime for
macOS platform. This can be useful if you only want to build a specific
embedded platform. It would be nice to generalize this to handle other
compiler-rt projects (i.e. add COMPILER_RT_ENABLE_OSX), but would
require additional attention from each compiler-rt project.

Note: some tests currently only are configured for osx, so these are
disabled when osx is disabled.
2023-12-14 15:28:45 -08:00
Jon Roelofs
5b470522cd fixup! [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685) 2023-12-14 15:13:30 -07:00
Jon Roelofs
212a5e1b9c [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685) 2023-12-14 14:57:38 -07:00
Zequan Wu
ab3430f891 [Profile] Add binary profile correlation for code coverage. (#69493)
## Motivation
Since we don't need the metadata sections at runtime, we can somehow
offload them from memory at runtime. Initially, I explored [debug info
correlation](https://discourse.llvm.org/t/instrprofiling-lightweight-instrumentation/59113),
which is used for PGO with value profiling disabled. However, it
currently only works with DWARF and it's be hard to add such artificial
debug info for every function in to CodeView which is used on Windows.
So, offloading profile metadata sections at runtime seems to be a
platform independent option.

## Design
The idea is to use new section names for profile name and data sections
and mark them as metadata sections. Under this mode, the new sections
are non-SHF_ALLOC in ELF. So, they are not loaded into memory at runtime
and can be stripped away as a post-linking step. After the process
exits, the generated raw profiles will contains only headers + counters.
llvm-profdata can be used correlate raw profiles with the unstripped
binary to generate indexed profile.

## Data
For chromium base_unittests with code coverage on linux, the binary size
overhead due to instrumentation reduced from 64M to 38.8M (39.4%) and
the raw profile files size reduce from 128M to 68M (46.9%)
```
$ bloaty out/cov/base_unittests.stripped -- out/no-cov/base_unittests.stripped
    FILE SIZE        VM SIZE
 --------------  --------------
  +121% +30.4Mi  +121% +30.4Mi    .text
  [NEW] +14.6Mi  [NEW] +14.6Mi    __llvm_prf_data
  [NEW] +10.6Mi  [NEW] +10.6Mi    __llvm_prf_names
  [NEW] +5.86Mi  [NEW] +5.86Mi    __llvm_prf_cnts
   +95% +1.75Mi   +95% +1.75Mi    .eh_frame
  +108%  +400Ki  +108%  +400Ki    .eh_frame_hdr
  +9.5%  +211Ki  +9.5%  +211Ki    .rela.dyn
  +9.2% +95.0Ki  +9.2% +95.0Ki    .data.rel.ro
  +5.0% +87.3Ki  +5.0% +87.3Ki    .rodata
  [ = ]       0   +13% +47.0Ki    .bss
   +40% +1.78Ki   +40% +1.78Ki    .got
   +12% +1.49Ki   +12% +1.49Ki    .gcc_except_table
  [ = ]       0   +65% +1.23Ki    .relro_padding
   +62% +1.20Ki  [ = ]       0    [Unmapped]
   +13%    +448   +19%    +448    .init_array
  +8.8%    +192  [ = ]       0    [ELF Section Headers]
  +0.0%    +136  +0.0%     +80    [7 Others]
  +0.1%     +96  +0.1%     +96    .dynsym
  +1.2%     +96  +1.2%     +96    .rela.plt
  +1.5%     +80  +1.2%     +64    .plt
  [ = ]       0 -99.2% -3.68Ki    [LOAD #5 [RW]]
  +195% +64.0Mi  +194% +64.0Mi    TOTAL
$ bloaty out/cov-cor/base_unittests.stripped -- out/no-cov/base_unittests.stripped
    FILE SIZE        VM SIZE
 --------------  --------------
  +121% +30.4Mi  +121% +30.4Mi    .text
  [NEW] +5.86Mi  [NEW] +5.86Mi    __llvm_prf_cnts
   +95% +1.75Mi   +95% +1.75Mi    .eh_frame
  +108%  +400Ki  +108%  +400Ki    .eh_frame_hdr
  +9.5%  +211Ki  +9.5%  +211Ki    .rela.dyn
  +9.2% +95.0Ki  +9.2% +95.0Ki    .data.rel.ro
  +5.0% +87.3Ki  +5.0% +87.3Ki    .rodata
  [ = ]       0   +13% +47.0Ki    .bss
   +40% +1.78Ki   +40% +1.78Ki    .got
   +12% +1.49Ki   +12% +1.49Ki    .gcc_except_table
   +13%    +448   +19%    +448    .init_array
  +0.1%     +96  +0.1%     +96    .dynsym
  +1.2%     +96  +1.2%     +96    .rela.plt
  +1.2%     +64  +1.2%     +64    .plt
  +2.9%     +64  [ = ]       0    [ELF Section Headers]
  +0.0%     +40  +0.0%     +40    .data
  +1.2%     +32  +1.2%     +32    .got.plt
  +0.0%     +24  +0.0%      +8    [5 Others]
  [ = ]       0 -22.9%    -872    [LOAD #5 [RW]]
 -74.5% -1.44Ki  [ = ]       0    [Unmapped]
  [ = ]       0 -76.5% -1.45Ki    .relro_padding
  +118% +38.8Mi  +117% +38.8Mi    TOTAL
```

A few things to note:
1. llvm-profdata doesn't support filter raw profiles by binary id yet,
so when a raw profile doesn't belongs to the binary being digested by
llvm-profdata, merging will fail. Once this is implemented,
llvm-profdata should be able to only merge raw profiles with the same
binary id as the binary and discard the rest (with mismatched/missing
binary id). The workflow I have in mind is to have scripts invoke
llvm-profdata to get all binary ids for all raw profiles, and
selectively choose the raw pnrofiles with matching binary id and the
binary to llvm-profdata for merging.
2. Note: In COFF, currently they are still loaded into memory but not
used. I didn't do it in this patch because I noticed that `.lcovmap` and
`.lcovfunc` are loaded into memory. A separate patch will address it.
3. This should works with PGO when value profiling is disabled as debug
info correlation currently doing, though I haven't tested this yet.
2023-12-14 14:16:38 -05:00
Vitaly Buka
fcce843227 [msan] Use pthread_atfork instead of interceptor (#75398)
This is done for consistency with other sanitizers.
Also lock the allocator.
2023-12-13 15:36:38 -08:00
Vitaly Buka
8d300e67d2 [hwasan] Improve support of forking with threads (#75291)
Lock Lsan and Thread related date at_fork.

Clean shadow before thread starts, forked process may reuse already
mapped stack of 'lost' parent thread for new threads.
2023-12-13 14:50:26 -08:00
Vitaly Buka
192840113a [NFC][msan] Clang-format some includes 2023-12-13 14:46:08 -08:00
Vitaly Buka
e065841cb0 [asan] Install pthread_atfork (#75290)
This prevents deadlocks in forked process
if parent had more then one running threads.
2023-12-13 13:42:24 -08:00
Vitaly Buka
14d7e0bb0f [lsan] Install pthread_atfork (#75281)
This prevents deadlocks in forked process on essencial
runtime components.
2023-12-13 13:09:36 -08:00
Vitaly Buka
64fa90bf89 [hwasan] Add __hwasan_get_tag_from_pointer (#75267)
This simplifies handling tags by user code. Now code does not need
to know bit size of tag and its position.
2023-12-13 11:22:10 -08:00
Vitaly Buka
e1e5f35409 [NFC][lsan] clang-format includes 2023-12-12 20:53:08 -08:00
Vitaly Buka
9567b33fa1 [asan] Switch initialization to "double-checked locking"
This allows to remove `asan_init_is_running` which likely had a data
race.

Simplifies https://github.com/llvm/llvm-project/pull/74086 and reduces a difference between platforms.

Reviewers: zacklj89, eugenis, dvyukov

Reviewed By: zacklj89, dvyukov

Pull Request: https://github.com/llvm/llvm-project/pull/74387
2023-12-12 13:57:24 -08:00
Christopher Ferris
a8ef9c0969 [scudo] Add utilization percentages for stats. (#75101)
Refactor the percentage display in the secondary code. Re-use that to
display a utilization percentage when displaying fragmentation data.
2023-12-11 16:42:44 -08:00
Zequan Wu
da0decf002 [Profile] Add missing COMPILER_RT_VISIBILITY to __llvm_profile_disable_continuous_mode. 2023-12-11 15:47:01 -05:00
Zequan Wu
ace26b380f [Profile] Disable continuous mode when reset to default.profraw due to malformed LLVM_PROFILE_FILE. (#74879)
When LLVM_PROFILE_FILE is set incorrectly (e.g. multiple %c) and it
falls back to use `default.profraw` name, but continuous mode is still
set. This might cause signal bus in the following scenario.

LLVM_PROFILE_FILE is set incorrectly (with "%c%c") for process A and B.
Suppose A starts first and falls back to use `default.profraw` and
mmaped its file content to memory. Later B starts and also falls back to
use `default.profraw`, but it will truncate the file because online
merging is disable when reseting to `default.profraw`. When A tries to
update counter via mmaped memory, signal bus will occur.

This fixes it by disabling continuous mode when reset to
default.profraw.
2023-12-11 10:13:08 -05:00
Jan Svoboda
f1e3e8a14f [ORC-RT][ORC][MachO] Fix build after 437b4f1c 2023-12-08 18:09:44 -08:00
Florian Mayer
a5bdc4a460 [scudo] do not store size inside ring buffer (#74541) 2023-12-08 17:16:56 -08:00