17703 Commits

Author SHA1 Message Date
Nikita Popov
89361007aa
[hwasan] Move __hwasan_thread_enter/__hwasan_thread_exit out of namespace (#72123)
Due to a GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25940),
GCC doesn't consider extern "C" functions with the same name but
different namespace to be the same. As such, the default visibility
attribute (on a declaration outside the namespace) doesn't get applied
to the definition in the namespace and the symbol is not exported.

This came up as an ABI diff when switching between gcc and clang for
compiling compiler-rt.
2023-11-15 09:38:24 +01:00
Andres Villegas
3dc098d392
[NFC, sanitizer_symbolizer] Split Fuchsia and Markup. (#72305)
This PR separates parts of the symbolizer markup
implementation that are Fuchsia OS specific. This
is in preparation of enabling symbolizer markup
in other OSs.
2023-11-14 16:39:04 -08:00
Vitaly Buka
60f740a305 [test][msan] Reformat RUN lines 2023-11-14 15:42:53 -08:00
Florian Mayer
8aed91631d [NFC] remove static asserts 2023-11-14 15:27:40 -08:00
Florian Mayer
d1168df2a4
[scudo] change allocation buffer size with env var (#71703)
We don't allow SCUDO_OPTIONS to be preserved across SELinux transitions,
so introducing a more constrained one that we can preserve.
2023-11-14 14:59:25 -08:00
Florian Mayer
a66dc461ac
[scudo] allocation_ring_buffer_size <= 0 disables buffer (#71791)
Prevent a null pointer exception for allocation_ring_buffer_size < 0.
2023-11-14 14:58:05 -08:00
Zequan Wu
0358825906
[Profile] Remove __llvm_profile_has_correlation() (#71996)
As discussed in
https://github.com/llvm/llvm-project/pull/70856#issuecomment-1791465183
and
https://github.com/llvm/llvm-project/pull/70856#issuecomment-1806281746,
it's better not to do runtime check for VARIANT_MASK_DBG_CORRELATE bit
in __llvm_profile_raw_version when deciding if profile data/name
sections should be dropped or not.
2023-11-14 14:03:10 -05:00
Alex Richardson
e9e51da447 [builtins] Add back trailing space removed in dc298fecb79608
This should fix the reported build-bot failure.

Fixes: dc298fecb79608e6628bd730ece42a6a77197a3c
2023-11-14 08:31:26 -08:00
Paulo Matos
5ef9ba7412
[compiler-rt] Remove reference to Type::getInt8PtrTy; NFC (#71570)
Removed as part of 7b9d73c2f90c0ed8497339a16fc39785349d9610 .
2023-11-14 07:57:27 +01:00
Alex Richardson
dc298fecb7 [builtins] Build with -Wbuiltin-declaration-mismatch if supported
GCC is able to check that the signatures of the builtins are as expected
and this shows some incorrect signatures on ld80 platforms (i.e. x86).
The *tf* functions should take 128-bit arguments but until the latest fixes
they used 80-bit long double.

Differential Revision: https://reviews.llvm.org/D153814
2023-11-13 11:06:22 -08:00
Mariusz Borsa
c2205ab309
[Sanitizers][Darwin] Pass offset to __asan_set_shadow_xx (#71745)
Normally, when __asan_option_detect_stack_use_after_return option is
set,
the instrumentation passed the adress of the shadow memory bytes to be
set, for detecting problems with local variables.
This can be a problem when the -fsanitize-stable-abi option is in
effect,
since the ABI implementation doesn't have means to communicate the
current shadow memory base address
back to its users.

This change addresses it simply by setting
__asan_shadow_memory_dynamic_address to zero. It means
that __asan_set_shadow_xx will be now called with the offset relative to
the current shadow memory
base, and the ABI implementation needs to adapt accordingly.

The other change here is to set
__asan_option_detect_stack_use_after_return to nonzer by default,
which is needed for instrumentation to take paths using the
__asan_shadow_memory_dynamic_address
and __asan_set_shadow_xx calls.

Co-authored-by: Mariusz Borsa <m_borsa@apple.com>
2023-11-12 14:44:43 -08:00
Fangrui Song
ee7d41d179
[asan] Report executable/DSO name for report_globals=2 and odr-violation checking (#71879)
For an odr-violation error due to a source file linked into two DSOs, or
one DSO and the main executable, it can be difficult to identify the DSO
name. Let's print the module name in the error report.

```
echo 'extern long var; int main() { return var; }' > a.cc
echo 'long var;' > b.cc
clang++ -fpic -fsanitize=address -shared b.cc -o b.so
clang++ -fsanitize=address a.cc b.cc ./b.so -o a
```

w/o this patch:
```
==1375386==ERROR: AddressSanitizer: odr-violation (0x56067cb06240):
  [1] size=8 'var' b.cc
  [2] size=8 'var' b.cc
...
```
w/ this patch:
```
==1375386==ERROR: AddressSanitizer: odr-violation (0x56067cb06240):
  [1] size=8 'var' b.cc in /tmp/c/a
  [2] size=8 'var' b.cc in ./b.so
```

In addition, update the `report_globals=2` message to include the module
name
```
==1451005==Added Global[0x7fcfe59ae040]: beg=0x7fcfe59ae140 size=8/32 name=var source=b.cc module=./b.so dyn_init=0 odr_indicator=0x55754f939260
```
2023-11-10 13:12:27 -08:00
Amara Emerson
77d75dc9be
[builtins] Guard the divtc3_test.c test with CRT_HAS_TF_MODE (#71876)
The bots on https://green.lab.llvm.org/green/job/clang-stage1-RA/ were
failing this test.
2023-11-10 11:30:18 -08:00
Zachary Johnson
5d6304f017 [NFC][asan] Change asan_init and asan_init_is_running; add setters/getters
For #71833
2023-11-09 13:57:46 -08:00
Zachary Johnson
08771c4e0e [ASan] Clang-format for #71833 2023-11-09 13:57:46 -08:00
Evgenii Stepanov
180b99c302
[scudo] Relax MemtagTag.SelectRandomTag. (#68048)
As it turns out, PRNGs have varying quality.
Relax the test to accept less-then-perfect tag distribution.
2023-11-09 13:14:20 -08:00
Thurston Dang
a34f3772e8 [sanitizer_common] Fix build breakage by guarding #include <dlfcn.h>
My change
(0be4c6b948) broke the Windows buildbot
(https://lab.llvm.org/buildbot/#/builders/127/builds/57976/steps/4/logs/stdio)

This fixes forward by adding a guard
2023-11-09 21:00:33 +00:00
Thurston Dang
0be4c6b948
[sanitizer_common] Add experimental flag to tweak dlopen(<main program>) (#71715)
This introduces an experimental flag 'test_only_replace_dlopen_main_program'. When enabled, this will replace dlopen(main program,...) with dlopen(NULL,...), which is the correct way to get a handle to the main program.

This can be useful when ASan is statically linked, since dladdr((void*)pthread_join) or similar will return the path to the main program.

Note that dlopen(main program,...) never ends well:
- PIE in recent glibc versions (glibc bugzilla 24323), or non-PIE: return an error
- PIE in current GRTE and older glibc: attempt to load the main program again, leading to reinitializing ASan and failing to remap the shadow memory.

---------

Co-authored-by: Thurston Dang <thurston@google.com>
2023-11-09 12:53:06 -08:00
Cullen Rhodes
0199d514ee
[compiler-rt][www] replace deprecated LLVM_CONFIG_PATH with LLVM_CMAKE_DIR (#71500)
This updates the standalone build docs for compiler-rt to replace
deprecated LLVM_CONFIG_PATH with LLVM_CMAKE_DIR. A warning (added in
D137024) is emitted for the current instructions.

---------

Co-authored-by: Chris B <cbieneman@microsoft.com>
2023-11-09 08:05:32 +00:00
ChiaHungDuan
048ece4413
[scudo] Calling initCache() in init() of SizeClassAllocatorLocalCache (#71427)
initCacheMaybe() will init all the size class arrays at once and it
doesn't have much work to do even if it supports partial initialization.
This avoids the call to initCacheMaybe in each allocate()/deallocate().
2023-11-09 01:31:58 +08:00
Florian Mayer
1a4754c8c8
[NFC] turn comment into static_assert (#71504) 2023-11-08 01:23:55 -08:00
Kenny Yu
1146d96096
[TSAN] Add __tsan_check_no_mutexes_held helper (#71568)
This adds a new helper that can be called from application code to
ensure that no mutexes are held on specific code paths. This is useful
for multiple scenarios, including ensuring no locks are held:

- at thread exit
- in peformance-critical code
- when a coroutine is suspended (can cause deadlocks)

See this discourse thread for more discussion:

https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051

This resubmits and fixes #69372 (was reverted because of build
breakage).
This also includes the followup change #71471 (to fix a land race).
2023-11-08 08:02:14 +01:00
Mitch Phillips
8a220b229e Disable UBSan vptr tests on Android.
Unclear what's going on here. I can reproduce the test failure at
https://lab.llvm.org/buildbot/#/builders/77/builds/31875 and well before
it as well.

Doesn't look like the device has changed, and I can also repro the
problem on Android 11 and Android 14. Disabling until further notice.
2023-11-07 16:34:36 +01:00
Hans Wennborg
27156dd575 Revert "[TSAN] Add __tsan_check_no_mutexes_held helper (#69372)"
The new lit test fails, see comment on the PR. This also reverts
the follow-up commit, see below.

> This adds a new helper that can be called from application code to
> ensure that no mutexes are held on specific code paths. This is useful
> for multiple scenarios, including ensuring no locks are held:
>
> - at thread exit
> - in peformance-critical code
> - when a coroutine is suspended (can cause deadlocks)
>
> See this discourse thread for more discussion:
>
> https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051

This reverts commit bd841111f340a73eb23c1be70ff1be4c8a6afb0c.
This reverts commit 16a395b74d35c564f6f36ba4a167950a323badd9.
2023-11-07 16:08:01 +01:00
Kirill Stoimenov
4d9f3ca77c
[HWASAN] Add memset interceptor (#71244)
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2023-11-07 00:01:04 -08:00
Charlie Barto
16a395b74d
Add SANITIZER_CDECL to __tsan_check_no_mutexes_held (#71471)
in https://github.com/llvm/llvm-project/pull/69625 @strega-nil added
cdecl to a huge number of sanitizer interface declarations. It looks
like she was racing against @kennyyu adding a tsan interface function. I
noticed this when merging in the latest changes from llvm/main and
corrected it.

Co-authored-by: Charlie Barto <Charles.Barto@microsoft.com>
2023-11-06 17:29:22 -08:00
Christopher Ferris
e15fcd7ba4
[scudo] Use the releaseAndZeroPagesToOS function. (#71256)
All of the code assumes that when the pages are released, the entry is
zero'd, so use the correct function. On most systems, this does not
change anything.
2023-11-06 12:46:37 -08:00
Shoaib Meenai
1ad920f05e [compiler-rt] Pass CMAKE_TOOLCHAIN_FILE through to custom libc++ build
This can be used to configure runtimes builds (instead of setting flags
individually), and we need to pass it down to the custom libc++ build
for it to work correctly.
2023-11-06 11:27:47 -08:00
Heejin Ahn
d859403037
[sanitizer] Fix pthread_exit interceptor's return type (#71253)
`pthread_exit`'s return type is void.
2023-11-05 22:41:37 -08:00
Jonathan Wakely
c670cdb968
[sanitizers] Do not define __has_feature in sanitizer/common_interface_defs.h (#66628)
Public headers intended for user code should not define `__has_feature`,
because this can break preprocessor checks done later in user code, e.g.
if they test `#ifdef __has_feature` to check for real support in the
compiler.

Replace the only use in the public header with a check for it being
supported before trying to use it. Define the fallback definition in the
internal headers, so that other internal sanitizer headers can continue
to use it as preferred.

This resolves a bug reported to GCC as https://gcc.gnu.org/PR109882
2023-11-05 15:22:56 -08:00
Kirill Stoimenov
3cf9bf343d
[HWASAN] Enable memcpy and memmove interceptors (#71217) 2023-11-03 14:17:45 -07:00
Kirill Stoimenov
ddf4a9ce63
[test][HWASAN] Force interceptors tests for memcmp and bcmp call interceptor (#71215) 2023-11-03 13:55:52 -07:00
Ben Langmuir
05a0d94416
[orc][mach-o] Fix mixing objc and swift code in a single JITDylib (#69258)
The system linker merges __objc_imageinfo flags values to select a
compatible set of flags using the minimum swift version and only
erroring on incompatible ABIs. Match that behaviour in the orc macho
platform. One wrinkle is that the JIT can add new objects after the
dylib is running code. In that case we only check for known incompatible
flags and ignore the swift version. It's too late to change the flags at
that point and swift version is unlikely to change runtime behaviour in
practice.
2023-11-03 08:32:08 -07:00
Kenny Yu
bd841111f3
[TSAN] Add __tsan_check_no_mutexes_held helper (#69372)
This adds a new helper that can be called from application code to
ensure that no mutexes are held on specific code paths. This is useful
for multiple scenarios, including ensuring no locks are held:

- at thread exit
- in peformance-critical code
- when a coroutine is suspended (can cause deadlocks)

See this discourse thread for more discussion:

https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051
2023-11-03 06:53:52 +01:00
Ryan Prichard
3747cde5e8
[Fuzzer] Enable custom libc++ for Android (#70407)
The Android LLVM build system builds the arm64 fuzzer lib without
HWASan, but then applications that enable HWASan can generated an object
file with a HWASan-ified version of some libc++ symbols (e.g.
`std::__1::piecewise_construct`). The linker can choose the HWASan-ified
definition, but then it cannot resolve the relocation from
libclang_rt.fuzzer-aarch64-android.a to this symbol because the high
bits of the address are unexpectedly set. This produces an error:

```
relocation R_AARCH64_ADR_PREL_PG_HI21 out of range
```

Fix this problem by linking a custom isolated libc++ into Android's
fuzzer library.

We need to pass through ANDROID_NATIVE_API_LEVEL so that the libc++ for
32-bit Android (API < 24) uses LLVM_FORCE_SMALLFILE_FOR_ANDROID.
2023-11-02 14:07:39 -07:00
Zequan Wu
7fa9930847 Rename hasCorrelation to __llvm_profile_has_correlation 2023-11-02 14:45:59 -04:00
Thurston Dang
7d039effc4
[tsan] Increase size of shadow mappings for C/C++ on linux/x86_64 (#70517)
The current TSan mappings for C/C++ on linux/x86_64 have 0.5TB
for low app mem, 1.5TB (1.17TB usable) for mid app mem and
1.5TB for high app mem.
This can get a bit cramped if the apps are huge, and/or (in the
case of mid/high app mem) with significant ASLR entropy
(default ASLR setting of 28-bits = 1TB).

This patch increases the mapping sizes to 2TB, 5TB, and 6TB for
the low, mid and high app regions respectively. This is compatible
with up to 30-bits of ASLR entropy. It is difficult to make the
mappings any larger, given the 44-bit pointer compression.

It also moves the heap region to avoid HeapEnd() overlapping with
the newly enlarged high app region.

For convenience, we now use kShadowAdd instead of kShadowXor for
this set of mappings. This should be roughly equivalent in
runtime performance.
2023-11-02 09:49:19 -07:00
Zequan Wu
56e205a89c [Profile] Fix debug info correlation test failure on mac. 2023-11-02 11:30:26 -04:00
Davide Italiano
d06596516f [build_symbolizer] Fix typo in 2c81d70747ac81b37b6c7639fe7afa328e8f5e79 2023-11-01 18:40:11 -07:00
Davide Italiano
4de92601c8
[build_symbolizer] Introduce ZLIB_SRC to specify an on-disk location for (#70994)
zlib.

Not everyone wants to checkout from `git`. Tested with and without the
env var.
2023-11-01 15:39:01 -07:00
nicole mazzuca
05ebc70453
[MSVC][ASan] fix interface header (#70992)
looks like there may be some missing testing here.
2023-11-01 15:09:49 -07:00
Zequan Wu
d871456659 [Profile] Remove inline for hasCorrelation. 2023-11-01 15:48:50 -04:00
Zequan Wu
3c97c8b6fc
[Profile] Refactor profile correlation. (#70856)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

#70712 was reverted due to linking failures. So, `-debug-info-correlate` remains unchanged and no new flag added.
2023-11-01 14:16:43 -04:00
nicole mazzuca
15b0cb4c72
[windows][ASan] Fix build (#70855)
PR #69625 broke the build - I put __cdecl on the wrong side of the `*`
in function pointer declarations.

Lesson learned - run check-all!
2023-10-31 14:14:58 -07:00
Martin Storsjö
703de006d3
[compiler-rt] [test] Apply the MSVC scalbn test exceptions to MinGW too (#70776)
MinGW mode can also use the MSVC/UCRT math functions. On ARM/ARM64,
mingw-w64 has always used the UCRT scalbn function. On x86, mingw-w64
recently changed to prefer the UCRT version for a large number of math
functions.
2023-10-31 22:38:53 +02:00
nicole mazzuca
b799080f19
[ASan][Windows] Add __cdecl to public sanitizer functions (#69625)
This is necessary for many projects which pass `/Gz` to their compiles,
which makes their default calling convention `__stdcall`.

(personal note, I _really_ wish there was a pragma for this)
2023-10-31 12:59:24 -07:00
Daniel Bertalan
fab5c8fa40 [compiler-rt] Build crtbegin.o/crtend.o for SerenityOS
Differential Revision: https://reviews.llvm.org/D154398
2023-10-31 18:46:59 +01:00
Zequan Wu
db7a1ed9a2 Revert "[Profile] Refactor profile correlation. (#70712)"
This reverts commit 4b383d0af93136b80841fc140da0823dfc441dd4.
2023-10-31 10:53:45 -04:00
Zequan Wu
4b383d0af9
[Profile] Refactor profile correlation. (#70712)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

Rebase of https://github.com/llvm/llvm-project/pull/69656 on top of main
as it was messed up.
2023-10-31 10:41:01 -04:00
David Truby
dbb4f90252
[compiler-rt] Don't link builtins against the CRT on Windows (#70675)
compiler-rt/builtins doesn't depend on anything from the CRT but
currently links against it and embeds a `/defaultlib:msvcrt` in the
`.lib` file, forcing anyone linking against it to also link against that
specific CRT. This isn't necessary as the end user can just choose which
CRT they want to use independently.
2023-10-31 12:51:38 +00:00