Commit Graph

501 Commits

Author SHA1 Message Date
Petr Hosek 18a1fc8459 [CMake][compiler-rt] Provide a dedicated option for LLVM unwinder
This allows configuring LLVM unwinder separately from the C++ library
matching how we configure it in libcxx.

This also applies changes made to libunwind+libcxxabi+libcxx in D113253
to compiler-rt.

Differential Revision: https://reviews.llvm.org/D115674
2022-06-14 17:26:25 +00:00
Alex Brachet 7df55e5ed7 [scudo] Ensure pointer is not null
Differential revision: https://reviews.llvm.org/D126499
2022-05-31 17:16:49 +00:00
Roland McGrath a27b9139ab [scudo] Clean up Zircon header file uses
Make fuchsia.h and fuchsia.cpp each include what they use.
2022-05-27 21:39:03 -07:00
John Paul Adrian Glaubitz a1ec3c5a88 [scudo] Link against libatomic on all MIPS targets
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126418
2022-05-26 00:00:16 -07:00
Leonard Chan 6edbdf80ca Revert "[compiler-rt][scudo] Add missing preprocessor token" and "[compiler-rt][scudo] Simplify TBI checks"
This reverts commit 676eaa2ca9
and f6038cdca0 since builders are still
broken.
2022-05-24 11:30:31 -07:00
Leonard Chan 676eaa2ca9 [compiler-rt][scudo] Add missing preprocessor token
This should fix build errors seen on bots like
https://lab.llvm.org/buildbot/#/builders/57/builds/18263.
2022-05-24 11:12:30 -07:00
Leonard Chan f6038cdca0 [compiler-rt][scudo] Simplify TBI checks
Differential Revision: https://reviews.llvm.org/D111080
2022-05-24 10:53:09 -07:00
Mitch Phillips e831ea6912 [NFCI] clang-format scudo standalone 2022-05-18 14:04:04 -07:00
Dominic Chen fcbca197f2 [scudo] Disable memory tagging on arm64_32
arm64_32 is an ILP32 platform

Differential Revision: https://reviews.llvm.org/D124135
2022-04-21 17:22:10 -07:00
Fangrui Song bbb72122aa [scudo][test] Link with -no-pie to be agnostic of CLANG_DEFAULT_PIE_ON_LINUX
This keeps the test behavior unchanged when CLANG_DEFAULT_PIE_ON_LINUX switches
to ON by default.

Note: current clang --target=mips64el-linux-gnu -fpie -pie -fuse-ld=lld
does not link with C++ exceptions, using -pie would lead to

```
ld.lld: error: cannot preempt symbol: DW.ref.__gxx_personality_v0
...
ld.lld: error: relocation R_MIPS_64 cannot be used against local symbol; recompile with -fPIC
...
```

when linking `ScudoUnitTests`: https://lab.llvm.org/buildbot/#/builders/169/builds/7311/steps/18/logs/stdio
2022-04-08 23:30:07 -07:00
Alex Brachet 016e59bf2c Revert "[Scudo] enabling anonymous named pages on Linux 5.17 and onwards."
This reverts commit 6194992523.
2022-04-05 16:38:49 +00:00
David Carlier 6194992523 [Scudo] enabling anonymous named pages on Linux 5.17 and onwards.
Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D122962
2022-04-05 09:46:02 +01:00
Michał Górny fd1da784ac [compiler-rt] [scudo] Use -mcrc32 on x86 when available
Update the hardware CRC32 logic in scudo to support using `-mcrc32`
instead of `-msse4.2`.  The CRC32 intrinsics use the former flag
in the newer compiler versions, e.g. in clang since 12fa608af4.
With these versions of clang, passing `-msse4.2` is insufficient
to enable the instructions and causes build failures when `-march` does
not enable CRC32 implicitly:

    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32'
      return CRC32_INTRINSIC(Crc, Data);
             ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC'
    #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
                              ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64'
    #  define FIRST_32_SECOND_64(a, b) (a)
                                       ^
    1 error generated.

For backwards compatibility, use `-mcrc32` when available and fall back
to `-msse4.2`.  The `<smmintrin.h>` header remains in use as it still
works and is compatible with GCC, while clang's `<crc32intrin.h>`
is not.

Use __builtin_ia32*() rather than _mm_crc32*() when using `-mcrc32`
to preserve compatibility with GCC.  _mm_crc32*() are aliases
to __builtin_ia32*() in both compilers but GCC requires `-msse4.2`
for the former, while both use `-mcrc32` for the latter.

Originally reported in https://bugs.gentoo.org/835870.

Differential Revision: https://reviews.llvm.org/D122789
2022-04-01 13:00:21 +02:00
Nikita Popov 985c717cdb Revert "[compiler-rt] [scudo] Use -mcrc32 on x86 when available"
This reverts commit 09b53121c3.

Breaks the build with GCC 11.2 on x86_64:

In file included from /home/npopov/repos/llvm-project/compiler-rt/lib/scudo/scudo_crc32.h:27,
                 from /home/npopov/repos/llvm-project/compiler-rt/lib/scudo/scudo_crc32.cpp:14:
/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h: In function ‘__sanitizer::u32 __scudo::computeHardwareCRC32(__sanitizer::u32, __sanitizer::uptr)’:
/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h:846:1: error: inlining failed in call to ‘always_inline’ ‘long long unsigned int _mm_crc32_u64(long long unsigned int, long long unsigned int)’: target specific option mismatch
  846 | _mm_crc32_u64 (unsigned long long __C, unsigned long long __V)
2022-04-01 09:40:48 +02:00
Michał Górny 09b53121c3 [compiler-rt] [scudo] Use -mcrc32 on x86 when available
Update the hardware CRC32 logic in scudo to support using `-mcrc32`
instead of `-msse4.2`.  The CRC32 intrinsics use the former flag
in the newer compiler versions, e.g. in clang since 12fa608af4.
With these compilers, passing `-msse4.2` is insufficient to enable
the instructions and causes build failures when `-march` does not enable
CRC32:

    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32'
      return CRC32_INTRINSIC(Crc, Data);
             ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC'
    #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
                              ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64'
    #  define FIRST_32_SECOND_64(a, b) (a)
                                       ^
    1 error generated.

For backwards compatibility, use `-mcrc32` when available and fall back
to `-msse4.2`.  The `<smmintrin.h>` header remains in use as it still
works and is compatible with GCC, while clang's `<crc32intrin.h>`
is not.

Originally reported in https://bugs.gentoo.org/835870.

Differential Revision: https://reviews.llvm.org/D122789
2022-03-31 17:49:42 +02:00
Dominic Chen 5fd0925bc9 [scudo] Reland: Add noreturn/pragma to suppress compiler warnings
Differential Revision: https://reviews.llvm.org/D121853
2022-03-30 11:42:20 -07:00
Dominic Chen 22a95dd3e6 Revert "[scudo] Wrap clang pragma to avoid GCC error"
Revert "[scudo] Add noreturn/pragma to suppress compiler warnings"

This reverts commit 686dcbe8b0.
This reverts commit 030d8262a6.
2022-03-29 17:52:20 -07:00
Dominic Chen 6ba8c8abe9 [scudo] Provide allocator declaration
Ensure that extern allocator declaration is visible before definition

Differential Revision: https://reviews.llvm.org/D121848
2022-03-29 17:39:45 -07:00
Dominic Chen 030d8262a6 [scudo] Wrap clang pragma to avoid GCC error
Fixes: [scudo] Add noreturn/pragma to suppress compiler warnings

Differential Revision: https://reviews.llvm.org/D121853
2022-03-29 17:36:33 -07:00
Dominic Chen 686dcbe8b0 [scudo] Add noreturn/pragma to suppress compiler warnings
Differential Revision: https://reviews.llvm.org/D121853
2022-03-29 14:26:15 -07:00
Dominic Chen db13f5a1b0 [scudo] Add missing include for extern variable declaration
Add include to resolve compiler warning about no previous extern declaration for non-static HashAlgorithm

Differential Revision: https://reviews.llvm.org/D122630
2022-03-29 14:26:15 -07:00
Dominic Chen d0eeb0fba0 [scudo] Fix definition of canCache() function
The called member function has boolean type, change this function to match

Differential Revision: https://reviews.llvm.org/D122631
2022-03-29 14:26:15 -07:00
Dominic Chen 92897217fa [scudo] Initialize local variable to avoid compiler warning
Compiler warns about HeaderPos possibly being uninitialized which should not be possible, but just initialize it anyway

Differential Revision: https://reviews.llvm.org/D122632
2022-03-29 14:26:15 -07:00
Dominic Chen 0e1d2007aa [scudo] Use template specialization on Quarantine to avoid zero-length array
Use a separate templated QuarantineBlocks class to avoid a zero-length array

Differential Revision: https://reviews.llvm.org/D122518
2022-03-28 21:35:49 -07:00
Dominic Chen a52868a55c Revert "[scudo] Use template specialization on Quarantine to avoid zero-length array"
This reverts commit 7dda44c189.
2022-03-28 19:08:55 -07:00
Dominic Chen 9343fc7613 [scudo] Use cast on calls to __builtin_umul_overflow/__builtin_umull_overflow
Platforms may define uintptr_t differently, so perform an explicit cast

Differential Revision: https://reviews.llvm.org/D121852
2022-03-28 16:36:30 -07:00
Dominic Chen 7dda44c189 [scudo] Use template specialization on Quarantine to avoid zero-length array
Use a separate templated QuarantineBlocks class to avoid a zero-length array

Differential Revision: https://reviews.llvm.org/D122518
2022-03-28 16:36:25 -07:00
Dominic Chen 58a583c229 [scudo] Fix static and unused function type annotations
Differential Revision: https://reviews.llvm.org/D121855
2022-03-18 12:52:29 -07:00
Dominic Chen 26a5f9bd03 [scudo] Don't assume preprocessor macro is defined
Differential Revision: https://reviews.llvm.org/D121857
2022-03-18 12:52:18 -07:00
Dominic Chen 58b6521eb5 [scudo] Use portable sysconf instead of deprecated getpagesize
Differential Revision: https://reviews.llvm.org/D121859
2022-03-17 11:02:26 -07:00
Dominic Chen 6ce08d5c27 [scudo][tests] Pass read-only vector by reference
Differential Revision: https://reviews.llvm.org/D121850
2022-03-17 10:17:36 -07:00
Dominic Chen 03e82d94fc [scudo] Fix test harness integration
Explicitly specify the class name to avoid selecting the wrong Run function, and inherit from the correct Test parent

Differential Revision: https://reviews.llvm.org/D121854
2022-03-17 10:17:36 -07:00
Dominic Chen 7abd6837a0 [scudo] Use nullptr instead of integer-to-pointer cast
Differential Revision: https://reviews.llvm.org/D121856
2022-03-17 10:17:36 -07:00
Dominic Chen 4787e5c34e [scudo] Don't unmap other low memory pages if mapping doesn't exist
Tests can register multiple allocators, but only the first will initialize since it initializes the TSDRegistrySharedT. Then, destruction of subsequent allocator may end up unmapping a nullptr PrimaryBase with non-zero PrimarySize.

Differential Revision: https://reviews.llvm.org/D121858
2022-03-17 10:17:36 -07:00
Dominic Chen e536419279 [scudo] Explicitly mark enum as unsigned
Differential Revision: https://reviews.llvm.org/D121860
2022-03-17 10:17:36 -07:00
Dominic Chen a6b7f31895 [scudo] Remove unused vector value initializer
Differential Revision: https://reviews.llvm.org/D121861
2022-03-17 10:17:35 -07:00
Stella Laurenzo 38151a08c2 Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"."
This reverts commit 7cdda6b8ce.

Differential Revision: https://reviews.llvm.org/D121020
2022-03-04 13:45:43 -08:00
Stella Laurenzo 7cdda6b8ce Revert "[cmake] Prefix gtest and gtest_main with "llvm_"."
lldb buildbot failure. will investigate and roll forward.

This reverts commit 9f37775472.
2022-03-02 11:13:46 -08:00
Stella Laurenzo 9f37775472 [cmake] Prefix gtest and gtest_main with "llvm_".
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).

This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120789
2022-03-02 10:53:32 -08:00
Gulfem Savrun Yeniceri 3d728ef0ba [scudo] Add missing <algorithm> include
After https://reviews.llvm.org/D119667, <algorithm> is no longer
transitively included from various headers. This patch adds the
<algorithm> include into scudo.

Differential Revision: https://reviews.llvm.org/D120171
2022-02-19 01:14:14 +00:00
Petr Hosek 48a38954c9 [CMake] Use generator expression to get in-tree libc++ path
When using the in-tree libc++, we should be using the full path to
ensure that we're using the right library and not accidentally pick up
the system library.

Differential Revision: https://reviews.llvm.org/D118200
2022-01-26 14:12:48 -08:00
Kostya Kortchinsky 636a1cfdcd [scudo] Make Scudo compile for C++20
In C++20 compound assignment to volatile (here `LocalData[I]++`) is
deprecated, so `mutex_test.cpp` fails to compile.

Simply changing it to `LocalData[I] = LocalData[I] + 1` fixes it.

Differential Revision: https://reviews.llvm.org/D117359
2022-01-14 14:53:40 -08:00
Dmitry Vyukov d7986bf011 scudo: fix thread-safety macro name
Missed in 765921de5b ("sanitizer_common: prefix thread-safety macros with SANITIZER_") update.

Differential Revision: https://reviews.llvm.org/D116818
2022-01-07 18:28:15 +01:00
Dmitry Vyukov 765921de5b sanitizer_common: prefix thread-safety macros with SANITIZER_
Currently we use very common names for macros like ACQUIRE/RELEASE,
which cause conflicts with system headers.
Prefix all macros with SANITIZER_ to avoid conflicts.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116652
2022-01-07 15:11:00 +01:00
Vitaly Buka 82fc4cc60b [scudo] Handle mallinfo2
mallinfo is deprecated by GLIBC

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D113951
2021-11-16 19:29:37 -08:00
Evgenii Stepanov 913d78c40c [scudo] Regression test for the MTE crash in storeEndMarker.
The original problem was fixed in D105261.

Differential Revision: https://reviews.llvm.org/D114022
2021-11-16 13:43:15 -08:00
Evgenii Stepanov 439e00a25b [scudo] Fix running tests under hwasan.
When built with hwasan, assume that the target architecture does not
support TBI. HWASan uses that byte for its own purpose, and changing it
breaks things.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D111842
2021-10-14 14:56:58 -07:00
Kostya Kortchinsky 56a9effc42 [scudo] Skip AllocAfterFork test on machines with low max_map_count
Reducing the number of iterations in that test with D111342 helped,
but the failure still occured flakily when the test is ran as part
of a large test suite.

Reducing further the number of iterations might not be good enough,
so we will skip the test if the `max_map_count` variable can be
read, and if lower than a given threshold.

Differential Revision: https://reviews.llvm.org/D111465
2021-10-11 10:33:47 -07:00
Kostya Kortchinsky 6727832c32 [scudo] Reduce the scope of AllocAfterFork
`ScudoWrappersCppTest.AllocAfterFork` was failing obscurely sometimes.
Someone pointed us to Linux's `vm.max_map_count` that can be
significantly lower on some machines than others. It turned out that
on a machine with that setting set to 65530, some `ENOMEM` errors
would occur with `mmap` & `mprotect` during that specific test.

Reducing the number of times we fork, and the maximum size allocated
during that test makes it pass on those machines.

Differential Revision: https://reviews.llvm.org/D111342
2021-10-07 14:01:58 -07:00
Leonard Chan 993555beb8 [compiler-rt][scudo] Check for failing prctl call
A bunch of MTE tests like ./ScudoUnitTest-aarch64-Test/MemtagTest.StoreTags
can fail on aarch64-linux if the kernel doesn't support the tagged address ABI. It looks like
the call to prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) can return -1, which
casted to an unsigned int and masked will return a value not equal to
PR_MTE_TCF_NONE, meaning systemDetectsMemoryTagFaultsTestOnly can return an incorrect value.

This updates the check to account for a failing prctl call.

Differential Revision: https://reviews.llvm.org/D110888
2021-10-04 13:14:20 -07:00