Commit Graph

12853 Commits

Author SHA1 Message Date
Leandro Lupori
33acdc1e2f [compiler-rt][xray] Fix alignment of XRayFileHeader
XRayFileHeader storage was obtained from std::aligned_storage
using its default alignment and not the struct's alignment
requirement. This was causing a bus error on AArch32, on armv8
machines, where vld1.64/vst1.64 instructions with 128-bit
alignment requirement were being used to copy XRayFileHeader.

There is still another issue with fdr-single-thread.cpp test on
armv7. Now it runs until completion and produces a valid log file,
but for some reason the function name appears as _end in it,
instead of the expected mangled fn name.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155013
2023-07-17 10:51:27 -03:00
Simi Pallipurath
6f4f1023fa [compiler-rt] [Arm] Make the tests for the runtime functions __aeabi_c{d,f} work on Big-Endian.
We are trying to build the compiler-rt as big-endian. And found that the tests compiler-rt/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c and compiler-rt/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c do not work on big endian at the moment. This patch makes these tests work on big endian as well.

Reviewed By: peter.smith, simon_tatham

Differential Revision: https://reviews.llvm.org/D155208
2023-07-17 12:27:32 +01:00
Sylvestre Ledru
b446c6dfcf cmake: set _LARGEFILE_SOURCE=1 to fix a cmake error
```
-- Performing additional configure checks with target flags: -mips32r2;-mabi=32;-D_LARGEFILE_SOURCE;-D_FILE_OFFSET_BITS=64
-- Performing Test COMPILER_RT_HAS_mips_FLOAT16
CMake Error: Parse error in command line argument: _LARGEFILE_SOURCE
 Should be: VAR:type=value
```
See: https://buildd.debian.org/status/fetch.php?pkg=llvm-toolchain-16&arch=mips64el&ver=1%3A16.0.6-4&stamp=1689111818&raw=0

Differential Revision: https://reviews.llvm.org/D155409
2023-07-17 09:59:56 +02:00
Martin Storsjö
c6bd873403 [CMake] Switch the CMP0091 policy (MSVC_RUNTIME_LIBRARY) to the new behaviour
With the new behaviour, the /MD or similar options aren't added to
e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake.
They can be changed by the cmake variable
CMAKE_MSVC_RUNTIME_LIBRARY or with the target property
MSVC_RUNTIME_LIBRARY.

LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE,
which affects which CRT is used for release mode builds. Deprecate
these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly
instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY
based on the existing LLVM_USE_CRT_ flags). This only handles the
simple cases, it doesn't handle multi-config generators with
different LLVM_USE_CRT_* variables for different configs though,
but that's probably fine - we should move over to the new upstream
CMake mechanism anyway, and push users towards that.

Change code in compiler-rt, that previously tried to override the
CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of
meddling in the old variables.

This resolves the policy issue in
https://github.com/llvm/llvm-project/issues/63286, and should
handle the issues that were observed originally when the
minimum CMake version was bumped, in
https://github.com/llvm/llvm-project/issues/62719 and
https://github.com/llvm/llvm-project/issues/62739.

Differential Revision: https://reviews.llvm.org/D155233
2023-07-17 09:59:05 +03:00
Weining Lu
ef33d6cbfc [XRay] Add initial support for loongarch64
Only support patching FunctionEntry/FunctionExit/FunctionTailExit for now.

Reviewed By: MaskRay, xen0n
Co-Authored-By: zhanglimin <zhanglimin@loongson.cn>

Differential Revision: https://reviews.llvm.org/D140727
2023-07-14 09:27:13 +08:00
Pavel Iliin
61962aa1ee [compiler-rt][AArch64] Correct how FMV use ifunc resolver abi.
The patch fixes second argument of Function Multi Versioning resolvers,
it is pointer to an extendible struct containing hwcap and hwcap2 not a
unsigned long hwcap2. Also fixes FMV features caching in resolver.

Differential Revision: https://reviews.llvm.org/D155026
2023-07-14 00:37:48 +01:00
Dmitry Vyukov
1377179396 sanitizer_common: initialize sanitizer runtimes lazily from signal interceptors
Currently if a program calls sigaction very early (before non-lazy sanitizer
initialization, in particular if .preinit_array initialization is not enabled),
then sigaction will wrongly fail since the interceptor is not initialized yet.

In all other interceptors we do lazy runtime initialization for this reason,
but we don't do it in the signal interceptors.
Do lazy runtime initialization in signal interceptors as well.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D155188
2023-07-13 16:28:25 +02:00
Blue Gaston
020cdaff61 [Asan][Darwin][GCD] Add interceptor for dispatch_mach_create_f
When enabling DriverKit, Address Sanitizer was unable to
intercept thread creation directly for dispatch workerthreads.

Because of this calls to GetStackTraceFromID failed and ASan was
unable to capture a meaningful stack trace.

This patch adds an interceptor for a dispatch function as a proxy
that is "close enough" to thread creation so that ASan is able
to meaningfully capture and register the dispatched thread.

Note: I propose not adding a test for this change.
Because this change is only meaningful in such a narrow usecase on Darwin
and is incredibly difficult to add a meaningful test.

Differential Revision: https://reviews.llvm.org/D154753
2023-07-12 20:52:10 -07:00
Petr Hosek
bb7a902c76 [CMake] Use COMPILER_RT_BUILD_CRT in the condition for test
Unlike COMPILER_RT_HAS_CRT this handles the case where CRT is available
but has been disabled by setting COMPILER_RT_BUILD_CRT. This addresses
an issue reported on D153989.

Differential Revision: https://reviews.llvm.org/D155126
2023-07-12 22:30:43 +00:00
Chia-hung Duan
1a4bc114ec Reland "[scudo] Support partial concurrent page release in SizeClassAllocator64"
This reverts commit 2f04b688aa.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D155015
2023-07-12 18:25:01 +00:00
Petr Hosek
b47beecc81 [compiler-rt] Move crt into builtins
On Linux crt is typically use in combination with builtins. In the Clang
driver the use of builtins and crt is controlled by the --rtlib option.
Both builtins and crt also have similar build requirements where they
need to be built before any other runtimes and must avoid dependencies.
We also want builtins and crt these to be buildable separately from the
rest of compiler-rt for bootstrapping purposes. Given how simple crt is,
rather than maintaining a separate directory with its own separate build
setup, it's more efficient to just move crt into builtins. We still use
separate CMake option to control whether to built crt same as before.

This is an alternative to D89492 and D136664.

Differential Revision: https://reviews.llvm.org/D153989
2023-07-11 23:05:45 +00:00
Thurston Dang
0c9145f413 [msan] Fix -Wcast-qual error in msan_dl.cpp
Fix build breakage from https://reviews.llvm.org/D154272.
(I accidentally dropped the fix when I relanded the patch.)
2023-07-11 21:04:51 +00:00
Chia-hung Duan
2f04b688aa Revert "[scudo] Support partial concurrent page release in SizeClassAllocator64"
We should merge two top TransferBatches so that the range marking can be
done correctly

This reverts commit 57ae8a2a1a.

Differential Revision: https://reviews.llvm.org/D155009
2023-07-11 20:33:58 +00:00
Thurston Dang
9095d5c44b Reland '[msan] Intercept dladdr1, and refactor dladdr'
Relanding with #if SANITIZER_GLIBC to avoid breaking FreeBSD.
Also incorporates Arthur's BUILD.gn fix (thanks!) from https://reviews.llvm.org/rGc1e283851772ba494113311405d48cfb883751d1

Original commit message:
This patch adds an msan interceptor for dladdr1 (with support for RTLD_DL_LINKMAP and RTLD_DL_SYMENT) and an accompanying test. It also adds a helper file, msan_dl.cpp, that contains UnpoisonDllAddrInfo (refactored out of the dladdr interceptor) and UnpoisonDllAddr1ExtraInfo.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D154272
2023-07-11 20:05:54 +00:00
Petr Hosek
7c4dbff05d Revert "[compiler-rt] Move crt into builtins"
This reverts commit dae9d1b524 since
it caused https://github.com/llvm/llvm-project/issues/63799.
2023-07-11 15:32:49 +00:00
Petr Hosek
dae9d1b524 [compiler-rt] Move crt into builtins
On Linux crt is typically use in combination with builtins. In the Clang
driver the use of builtins and crt is controlled by the --rtlib option.
Both builtins and crt also have similar build requirements where they
need to be built before any other runtimes and must avoid dependencies.
We also want builtins and crt these to be buildable separately from the
rest of compiler-rt for bootstrapping purposes. Given how simple crt is,
rather than maintaining a separate directory with its own separate build
setup, it's more efficient to just move crt into builtins. We still use
separate CMake option to control whether to built crt same as before.

This is an alternative to D89492 and D136664.

Differential Revision: https://reviews.llvm.org/D153989
2023-07-11 07:41:04 +00:00
Chia-hung Duan
280ffafca5 [scudo] Simple coding style fix in mem_map_base.h (NFC)
Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D154894
2023-07-10 21:29:26 +00:00
Chia-hung Duan
316ca42a65 [scudo] Print PushedBytesDelta in getStats()
This gives a hint of potential bytes to release. Also remove the RSS
which is not supported yet. Will add it back when it's available.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D154551
2023-07-10 21:29:18 +00:00
Chia-hung Duan
57ae8a2a1a [scudo] Support partial concurrent page release in SizeClassAllocator64
After extracting memory groups, it's safe to do
1. markFreeBlocks
2. releaseFreeMemoryToOS concurrently with pushBlocks() and
popBatches(). This will improve the throughput of Scudo.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D153608
2023-07-10 17:24:37 +00:00
Zequan Wu
985486dca4 [Profile] Remove duplicate file locks when enabled continuous mode and online merging.
In `initializeProfileForContinuousMode`, we have already locked the profile file when merging is enabled, so there's no need to lock the same file second time in `openFileForMerging`.

On Linux/Darwin, the locking the same file twice doesn't cause any problem. But on Windows, it causes the problem to hang forever.

With this minor fix, continuous mode seems working with online merging on Windows.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D154748
2023-07-10 11:01:28 -04:00
Chia-hung Duan
399eb5632f [scudo] Explicit casting for u16 arithmetic operation
This fixes the werror from https://lab.llvm.org/buildbot/#/builders/165/builds/38829

Reviewed By: enh

Differential Revision: https://reviews.llvm.org/D154733
2023-07-07 19:58:02 +00:00
Chia-hung Duan
1ff3a5d9bb [scudo] Allow pushing single block to the freelist of BatchClass
This CL removes the restriction that pushing blocks into BatchClassId
can only be done when freelist is not empty. Without this constraint,
BatchClassId is also available for gathering blocks into groups.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D153492
2023-07-07 17:27:48 +00:00
Kirill Stoimenov
a34e702aa1 [ASAN] Add mmap and munmap interceptor in ASAN
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D154659
2023-07-07 15:48:12 +00:00
Kito Cheng
2b5ea51a41 [compiler-rt][RISCV] Fix __fe_getround and __fe_raise_inexact for Zfinx
Zfinx extension also provide floating point environment like F extension, so
enable that on `__fe_getround` and `__fe_raise_inexact` too.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D154570
2023-07-07 14:24:50 +08:00
Thurston Dang
667b9add73 Revert "Reland '[msan] Intercept dladdr1, and refactor dladdr'"
This reverts my commit 015dabd767
due to breaking non-glibc builds.
2023-07-07 00:23:03 +00:00
Thurston Dang
1da10d25d9 [msan] Fix -Wcast-qual error in msan_dl.cpp
Attempt 2 at fixing a buildbot error https://lab.llvm.org/buildbot#builders/57/builds/28143
that I had introduced in D154272
2023-07-06 18:04:22 +00:00
Chia-hung Duan
bce8c9e3d7 [scudo] Try to release pages after unlocking the TSDs
This increases the parallelism and the usage of TSDs

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D152988
2023-07-06 17:40:26 +00:00
Chia-hung Duan
531f90acc5 [scudo] Verify the size of free blocks in primary allocator
When all the blocks (local caches are included) are freed, the size of
free blocks should be equal to `AllocatedUser`.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D152769
2023-07-06 17:40:25 +00:00
Thurston Dang
015dabd767 Reland '[msan] Intercept dladdr1, and refactor dladdr'
Reland with -Wcast-qual issue fixed

Original commit message:
This patch adds an msan interceptor for dladdr1 (with support for RTLD_DL_LINKMAP and RTLD_DL_SYMENT) and an accompanying test. It also adds a helper file, msan_dl.cpp, that contains UnpoisonDllAddrInfo (refactored out of the dladdr interceptor) and UnpoisonDllAddr1ExtraInfo.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D154272
2023-07-06 16:16:22 +00:00
Marco Elver
65bc9c3666 [compiler-rt] Fix __sanitizer_cpuset size on newer FreeBSD
Current FreeBSD has increased size of cpuset. Match it to not break the
build on newer FreeBSD.

Patch by John F. Carr

Fixes: https://github.com/llvm/llvm-project/issues/63485
2023-07-06 12:34:36 +02:00
Fangrui Song
9e7a052eef [XRay][AArch64] Implement __xray_ArgLoggerEntry 2023-07-05 20:56:00 -07:00
Chia-hung Duan
b0ec18a3d1 [scudo] Extract steps releaseToOSMaybe into functions in
This refactor helps us identify which steps need FLLock so that we can
reduce the holding time of FLLock in SizeClassAllocator64.

Also move the data members to the end of class to align the style in
SizeClassAllocator32.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D152596
2023-07-05 20:31:32 +00:00
Caslyn Tonelli
4a5d626783 [scudo] SCUDO_FUCHSIA uses ReservedMemoryDefault
Some Fuchsia zx tests failed from https://reviews.llvm.org/D153888:
https://turquoise-internal-review.git.corp.google.com/c/integration/+/729619

Use `ReservedMemoryDefault` for `SCUDO_FUCHSIA` to use the default
MemMap API, while test failures are debugged.

Differential Revision: https://reviews.llvm.org/D154538
2023-07-05 20:22:17 +00:00
Fabio D'Urso
3003da7154 [scudo] Implement Fuchsia backend for the new MemMap API
Reviewed By: Caslyn, Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D153888
2023-07-05 14:07:37 +02:00
Blue Gaston
f171c76b68 [ASanAbi][Darwin] Build ios stable ABI library
In the initially commit, we limited the static archive to osx.

This patch removes that limitation.

Differential Revision: https://reviews.llvm.org/D153789
2023-07-04 14:32:59 -07:00
Thurston Dang
8ccf0426a4 Revert "[msan] Intercept dladdr1, and refactor dladdr"
Reverting my commit because of buildbot breakage.

This reverts commit d0b0dbeae1.
2023-07-01 20:27:11 +00:00
Thurston Dang
d0b0dbeae1 [msan] Intercept dladdr1, and refactor dladdr
This patch adds an msan interceptor for dladdr1 (with support
for RTLD_DL_LINKMAP and RTLD_DL_SYMENT) and an accompanying
test. It also adds a helper file, msan_dl.cpp, that contains
UnpoisonDllAddrInfo (refactored out of the dladdr interceptor)
and UnpoisonDllAddr1ExtraInfo.

Differential Revision: https://reviews.llvm.org/D154272
2023-07-01 19:18:27 +00:00
fernandosalas
85c622b597 [scudo] Improve Secondary Cache Dump
Exclude cached blocks with invalid start address. Mainly concerned with
cached blocks that are still available/unused.

Reviewed By: Chia-hungDuan, cferris

Differential Revision: https://reviews.llvm.org/D154148
2023-06-30 20:55:41 +00:00
Chia-hung Duan
da8cc061f2 [scudo] Restore Freelist when we fail on PageMap creation
Differential Revision: https://reviews.llvm.org/D154041
2023-06-30 20:54:08 +00:00
Jin Xin Ng
f768e5310c [dfsan] Add missing functions to done_abilist.txt
__sanitizer_get_allocated_begin and __sanitizer_get_allocated_size_fast
were introduced recently in D147005 and D151360, but not added here,
leading to linker errors.

Differential Revision: https://reviews.llvm.org/D153680
2023-06-30 17:39:15 +00:00
Fabio D'Urso
0e93c4a5fd [scudo] SizeClassAllocator64: dispatch all the classes in init()
This will make it easier to verify in a future patch that the ReservedMemory object has been fully dispatched.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D153019
2023-06-30 17:13:41 +02:00
Christopher Ferris
36ca9a2902 [scudo] Use getMonotonicTimeFast for tryLock.
In tryLock, the Precedence value is set using the fast time function
now. This should speed up tryLock calls slightly.

This should be okay even though the value is used as a kind of random
value in getTSDAndLockSlow. The fast time call still sets enough bits
to avoid getting the same TSD on every call.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D154039
2023-06-29 13:07:08 -07:00
zhanglimin
310a6f12b5 [MSan] Enable MSAN for loongarch64
This patch adds basic memory sanitizer support for loongarch64
with 47-bit VMA, which memory layout is based on x86_64.

The LLVM part of the LoongArch memory sanitizer implementation will
be done separately, which will fix failing tests in check-msan.
These failing tests fail with the following same error: "error in
backend: unsupported architecture".

Reviewed By: #sanitizers, vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D140528
2023-06-29 11:33:04 +08:00
Christopher Ferris
bd694683eb [scudo] Use fast get time in secondary.
When I moved the primary to use the faster get time syscall, I missed
the secondary use. Now fix the secondary to use this function too.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D154012
2023-06-28 17:29:47 -07:00
Leonard Grey
4fd517d613 [lsan] Be more conservative in SuspendedThreadsListMac::GetRegistersAndSP
Currently, we only return REGISTERS_UNAVAILABLE_FATAL if we receive
KERN_INVALID_ARGUMENT from thread_status. In reality, there are other
possible return values (MACH_SEND_INVALID_DEST for example) that make it
dangerous to read memory. This can be demonstrated by running
create_thread_leak.cpp in standalone mode where it will appear to hang
due to a EXC_BAD_ACCESS while scanning the stack.

This change reverses the current logic to treat MIG_ARRAY_TOO_LARGE as
non-fatal, and all other errors as fatal.

Differential revision: https://reviews.llvm.org/D153072
2023-06-28 10:40:07 +02:00
Fangrui Song
dcef530878 sanitizer_allocator_test: guard SpecialSizeClassMap test with !ALLOCATOR64_SMALL_SIZE
This artificial size class map uses a very large kMaxSize (1<<34) which is not
suitable for small kAddressSpaceSize systems (aarch64-*-linux-android, riscv64).
Exposed by D153664.
2023-06-27 21:17:34 -07:00
Fangrui Song
9971269ea7 [sanitizer] Relax the restriction on SizeClassAllocator64::kAllocatorSize
Commit 278ccdacdc says that kAllocatorSize
must be >= (1<<32), but this is not accurate. This static_assert causes 128GiB
kAllocatorSize to be unable to select DefaultSizeClassMap (kRegionSize is
1<<31).

Relax the restriction to be able to satisfy the largest size class. This allows
DefaultSizeClassMap to be usable with 128GiB kAllocatorSize, with
check-{asan,lsan,sanitizer} passing.

Reviewed By: #sanitizers, vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D153664
2023-06-27 19:47:03 -07:00
Alex Richardson
f05c5c9c2c [builtins] Avoid using floating point q suffix. NFCI
The q floating point suffix is not supported by all compilers
configurations (e.g. GCC only supports it for some targets), so use a
macro (much like UINT64_C) instead. As this touches almost all lines in
the two tests also run them through clang-format.
2023-06-27 16:54:29 -07:00
Alex Richardson
f157afceb0 [builtins] Fix __floattitf and __floatuntitf on x86
These conversion functions were using LDBL_MANT_DIG (which is the 80-bit
extended float on x86) instead of the appropriate macro for the 128-bit
floating point type expected by the *tf* softfloat library calls.
This was discovered while testing D98261 (which allows building the *tf*
functions on x86).

This also changes the constants used in the two tests to use 128-bit
floating-point literals instead of long double ones to ensure that the
comparison succeeds on platforms with smaller long double (e.g. x86_64)

Reviewed By: scanon

Differential Revision: https://reviews.llvm.org/D131787
2023-06-27 09:22:25 -07:00
Advenam Tacet
0b2c0dc63f [ASan] Remove sanity checks during annotation of contiguous container
This revision removes sanity checks in
`__sanitizer_annotate_contiguous_container`.
(Changed them to `DCHECK_EQ`.)
Those checks may be problematic, if someone manually unpoisoned memory block.
Manual unpoisoning may be used if part of the program is not
instrumented.

Those checks are helpful while confirming correctness of ASan annotations
implementation.

Originally suggested here: https://reviews.llvm.org/D136765#4174546

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D145482
2023-06-27 06:07:03 +02:00