16453 Commits

Author SHA1 Message Date
Michał Górny
da3cd333be [compiler-rt] [test] Mark dfsan tests XFAIL on glibc-2.37
Mark the two dfsan tests that are known to be broken on glibc-2.37
as XFAIL, to make the test suite start passing on Gentoo again.

Bug: https://github.com/llvm/llvm-project/issues/60678

Differential Revision: https://reviews.llvm.org/D148496

(cherry picked from commit 488a4b24817ae7d9319d8a99bd96c491b2035641)
2023-05-02 10:50:56 -07:00
Leandro Lupori
bd6783b380 [compiler-rt] Fix invalid triple on ARM build
The fuzzer build was failing on armv7l, with an invalid triple
error. This happened because CMake's get_compiler_rt_target
function was missing some code to correctly handle arm archs,
such as armhf.

This was originaly part of https://reviews.llvm.org/D140011, that
landed on main with commit cd173cbd7cca69c29df42cd4b42e60433435c29b.

Fixes #60115

Differential Revision: https://reviews.llvm.org/D142906
2023-04-27 11:10:43 +00:00
Leandro Lupori
ccbab5979b [compiler-rt] Fix scudo build on ARM
The build of scudo was failing on armv7l, with undefined references
to unwinder symbols, such as __aeabi_unwind_cpp_pr0. These are
needed by RTGwpAsan and thus, on ARM, scudo must also be linked
against an unwind library.

The cmake command that caused the build failure was:

cmake --fresh -S "$PWD/llvm/" -B "$PWD/build/" -G Ninja \
  -DCMAKE_INSTALL_PREFIX="$PWD/install" \
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;clang-tools-extra;polly" \
  -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
  -DLLVM_TOOLCHAIN_TOOLS="llvm-ar;llvm-ranlib;llvm-objdump;\
llvm-rc;llvm-cvtres;llvm-nm;llvm-strings;llvm-readobj;\
llvm-dlltool;llvm-pdbutil;llvm-objcopy;llvm-strip;llvm-cov;\
llvm-profdata;llvm-addr2line;llvm-symbolizer;llvm-windres;llvm-ml;\
llvm-readelf;llvm-size" \
  -DLLVM_INSTALL_BINUTILS_SYMLINKS=OFF -DLLVM_PARALLEL_LINK_JOBS=1

Fixes #60115

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D142888

(cherry picked from commit e1e972689b9138db795885a5468a15aafbe7cb51)
2023-04-27 11:10:43 +00:00
Ivan Trofimov
dbcd2e9330 [runtimes][asan] Fix swapcontext interception
Resetting oucp's stack to zero in swapcontext interception is incorrect,
since it breaks ucp cleanup after swapcontext returns in some cases:

Say we have two contexts, A and B, and we swapcontext from A to B, do
some work on Bs stack and then swapcontext back from B to A. At this
point shadow memory of Bs stack is in arbitrary state, but since we
can't know whether B will ever swapcontext-ed to again we clean up it's
shadow memory, because otherwise it remains poisoned and blows in
completely unrelated places when heap-allocated memory of Bs context
gets reused later (see https://github.com/llvm/llvm-project/issues/58633
for example). swapcontext prototype is swapcontext(ucontext* oucp,
ucontext* ucp), so in this example A is oucp and B is ucp, and i refer
to the process of cleaning up Bs shadow memory as ucp cleanup.

About how it breaks:
Take the same example with A and B: when we swapcontext back from B to A
the oucp parameter of swapcontext is actually B, and current trunk
resets its stack in a way that it becomes "uncleanupable" later. It
works fine if we do A->B->A, but if we do A->B->A->B->A no cleanup is
performed for Bs stack after B "returns" to A second time. That's
exactly what happens in the test i provided, and it's actually a pretty
common real world scenario.

Instead of resetting oucp's we make use of uc_stack.ss_flags to mark
context as "cleanup-able" by storing stack specific hash. It should be
safe since this field is not used in [get|make|swap]context functions
and is hopefully never meaningfully used in real-world scenarios (and i
haven't seen any).

Fixes https://github.com/llvm/llvm-project/issues/58633

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D137654

(cherry picked from commit b380e8b68951776656f286ecd079e2f30981905e)
2023-04-18 18:07:46 -07:00
Vitaly Buka
ec006fb244 [nfc][asan] Reformat the file
(cherry picked from commit 3248ca0da01c73711896ddc86ae8b045b86726c8)
2023-04-18 18:07:46 -07:00
Vitaly Buka
c4ac4533ea [test][asan] Simplify test
FileCheck is not very useful here.

(cherry picked from commit fd2cafbdc480920bcf4eb598788a906ec1f63c41)
2023-04-18 18:07:46 -07:00
Alvin Wong
1ca4b5cfaa [sanitizer][win] Change cmdline check to allow double backslashs
When `llvm-symbolizer.exe` is on the PATH in an entry containing two
consecutive backslashes, sanitizers will try to launch llvm-symbolizer
with its absolute path containing these consecutive backslashes. This
fails a sanity check in `sanitizer_symbolizer_win.cpp`.

According to the documentation of `CommandLineToArgvW` [1] and a MS blog
post [2], backslashes in general, regardless of how many of them in a
row, do not have any special effect, unless when immediately followed by
a double quote.

There already exists a check that fails when the command line arguments
contains double quote, therefore the check for double backslashes can
simply be removed.

[1]: https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw
[2]: https://learn.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way

Differential Revision: https://reviews.llvm.org/D146621

(cherry picked from commit b1871ceb1cf6c6954380867d41db3812e9e0dbfc)
2023-03-28 08:59:31 +02:00
Frederic Cambus
bec9a60769 [compiler-rt] Add missing #else clause to fix the build on NetBSD.
An #elif SANITIZER_SOLARIS clause was removed in D120048, but it also
removed the #else clause for the error fallback, causing the build to
fail on NetBSD.

Differential Revision: https://reviews.llvm.org/D146316

(cherry picked from commit 8510cf9fc1a431b70737b2b046007d318c62b7a8)
2023-03-23 15:33:47 +01:00
Xi Ruoyao
e0044a6993 [compiler-rt][builtins] Define AT_HWCAP2 for AArch64
Without the definition, build fails on AArch64 with

> error: 'AT_HWCAP2' undeclared (first use in this function);
> did you mean 'AT_HWCAP'?

with old Glibc versions.

Differential Revision: https://reviews.llvm.org/D145494

(cherry picked from commit 23fcca822a3a3b9a14b6a1ad432814e2634cdb63)
2023-03-09 06:53:51 -08:00
Alex Richardson
e0ffaabd2f [builtins] Only build float16/bfloat16 code if actually supported
When building compiler-rt builtins for x86_64 they library will by default
also be built for i386. We unconditionally add the Float16 compile flags
since the check for Float16 support will be done using x86_64 compiler
flags, but i386 does not actually support it. Fix this by moving the
COMPILER_RT_HAS_FLOAT16 and COMPILER_RT_HAS_FLOAT16 checks to a
per-target-architecture check inside the loop (using
`check_c_source_compiles` and `cmake_{push,pop}_check_state`).

Many of the checks in the builtin-config-ix file should probably also be
changed to per-target-arch checks, but so far only the Float16 one has
caused issues. This is an alternative to D136044 which added a special case
for i386 FreeBSD.

Fixes: https://github.com/llvm/llvm-project/issues/57224
Differential Revision: https://reviews.llvm.org/D145237

(cherry picked from commit 489bda6a9c0ec9d2644b7bb0c230294d38f7296e)
2023-03-09 06:34:51 -08:00
Daniel Thornburgh
60bba0f5a7 [llvm-cov] Create syntax to pass source w/o binary.
Since binary ID lookup makes CLI object arguments optional, it should be
possible to pass a list of source files without a binary. Unfortunately,
the current syntax will always interpret the first source file as a
binary. This change adds a `-sources` option to cause all later
positional arguments to be considered sources.

Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D144207

(cherry picked from commit 8007bcc13f8f5f5c352a24e122b7090494a62bfb)
2023-03-04 00:00:29 -08:00
Amy Kwan
da0580260e [scudo] Disable the GetRssFromBuffer scudo test on PPC
The GetRssFromBuffer scudo test case fails intermittently on Power, so this test
is disabled on the platform because of this.

(cherry picked from commit 0e3ef5f89749a599c652c546214a8307e3495526)
2023-03-03 23:50:17 -08:00
Tobias Hieta
21fc8d0bc2 [compiler-rt][macOS]: Disable iOS support if iOS SDK is not found
If you are missing the iOS SDK on your macOS (for example you don't have
full Xcode but just CommandLineTools) then CMake currently errors
out without a helpful message. This patch disables iOS support in
compiler-rt if the iOS SDK is not found. This can be overriden by
passing -DCOMPILER_RT_ENABLE_IOS=ON.

Reviewed By: delcypher, thetruestblue

Differential Revision: https://reviews.llvm.org/D133273

(cherry picked from commit 78fb02107ae5819501af2600b0bebd48c1900a9b)
2023-02-09 13:54:26 +01:00
Daniel Thornburgh
0b21322abe [llvm-cov] Add split-file to compiler-rt test requirements.
Differential Revision: https://reviews.llvm.org/D136702

(cherry picked from commit 0eb01a9c4581a24c163f3464cebdb20534fbda35)
2023-02-07 19:00:57 -08:00
Daniel Thornburgh
20303e551a Reland: [llvm-cov] Look up object files using debuginfod
Reviewed By: gulfem

Differential Revision: https://reviews.llvm.org/D136702

(cherry picked from commit a3b0dde4edb93248f74d86c63b0ae108854004e6)
2023-02-07 19:00:57 -08:00
Kirill Stoimenov
52400e42b8 [LSAN] Attempt to fix the ppc64 build by excluding unsupported test
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D142561

(cherry picked from commit 3348699221339870d668930171e9fd58a60acc89)
2023-02-07 18:58:58 -08:00
Sam James
60df88fd9d [compiler-rt] Fix FORTIFY_SOURCE -> _FORTIFY_SOURCE reference (NFC)
As pointed out by maskray.

Fixes: 8ab762557fb057af1a3015211ee116a975027e78
(cherry picked from commit ca50897a763c7dd0ec7c9b3ec003eeca802c5525)
2023-02-05 21:15:13 +01:00
Sam James
ccc916a827 [compiler-rt] Disable default config files for tests
Without this, if hardening measures like FORTIFY_SOURCE are are in
/etc/clang/*.cfg, many sanitizer tests will die before the sanitizer
can trap the problem being tested, because e.g. the _chk variants
of common functions will abort first.

This gets the number of failing tests down from 42->3 for me (and the
remaining 3 are unrelated).

See: 52ce6776cf98e993c6ec04ae54b52e1354fff917
See: 136f77805fd89cd30e69b3d1204fbf7efedd9a12
Closes: https://github.com/llvm/llvm-project/issues/60394

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D143322

(cherry picked from commit 8ab762557fb057af1a3015211ee116a975027e78)
2023-02-05 21:15:13 +01:00
Muhammad Omair Javaid
37505da42f [compiler-rt] Remove XFAIL decorator trampoline_setup_test.c
This patch remove xfail decorator from
builtins/Unit/trampoline_setup_test.c as it is passing on Windows/AArch64
nowz. It is being skipped in code with __clang__ not defined.

https://lab.llvm.org/buildbot/#/builders/120/builds/3873
2023-01-25 06:18:23 +05:00
Kirill Stoimenov
f057314345 [HWASAN] Copy some ASAN independent unit tests from ASAN to LSAN
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142504
2023-01-25 00:39:52 +00:00
Han Zhu
7a2f3d1886 [NFC] Update tsan_rtl.h comment after D142039 2023-01-24 10:47:02 -08:00
Marco Elver
5265adc737 [SanitizerBinaryMetadata] Declare callbacks extern weak
Declare callbacks extern weak (if no existing declaration exists), and
only call if the function address is non-null.

This allows to attach semantic metadata to binaries where no user of
that metadata exists, avoiding to have to link empty stub callbacks.

Once the binary is linked (statically or dynamically) against a tool
runtime that implements the callbacks, the respective callbacks will be
called. This vastly simplifies gradual deployment of tools using the
metadata, esp. avoiding having to recompile large codebases with
different compiler flags (which negatively impacts compiler caches).

Reviewed By: dvyukov, vitalybuka

Differential Revision: https://reviews.llvm.org/D142408
2023-01-24 12:54:20 +01:00
Vitaly Buka
5b190c4a2d Revert "[profile] Disable test which needs update after D141512"
Work around with -fno-slp-vectorize.

This reverts commit 31260a4ce43aab7c04f501095a9032de063ccaf9.
2023-01-23 17:35:38 -08:00
Kirill Stoimenov
2b0322ed56 [HWASAN] Fix PointsIntoChunk to untag pointers. Also added some checks where we know that the pointer should be untagged.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142389
2023-01-24 00:35:17 +00:00
Kirill Stoimenov
eba322e9d7 [Sanitizer] Make GetBlockBeginFastLocked parameters const.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142402
2023-01-24 00:01:35 +00:00
Kirill Stoimenov
cf6c43189f [HWASAN] Fix memory leaks in tests.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142383
2023-01-23 23:59:07 +00:00
Vitaly Buka
31260a4ce4 [profile] Disable test which needs update after D141512 2023-01-23 14:57:01 -08:00
Han Zhu
84bec0a219 [tsan] Always initialize tsan when building shared lib
Differential Revision: https://reviews.llvm.org/D142039
2023-01-23 10:30:18 -08:00
Dimitry Andric
abf399737e Revert "[compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd"
This reverts commit 45368c75582f0bded1f06d5c82c1f2ee023fb186.

There were some unexpected failures in aarch64 and arm buildbots, I will
have to investigate why these suddenly fell over.
2023-01-23 11:22:28 +01:00
Dimitry Andric
45368c7558 [compiler-rt][builtins] Skip building (b)float16 support on i386-freebsd
Since bfloat16 and float16 support is not available for i386-freebsd,
the `truncdfbf2.c` and `truncsfbf2.c` builtin sources should be skipped
when targeting that platform, and `COMPILER_RT_HAS_FLOAT16` should not
be defined.

However, the CMake configuration stage runs its tests with the default
target, which normally is amd64-freebsd, so it will detect both bfloat16
and float16 support.

Move adding of the `COMPILER_RT_HAS_FLOAT16` define to the `foreach()`
loop where all the supported architectures are handled, and do not
enable it when targeting i386-freebsd.

Also remove the bfloat16 sources from the `i386_SOURCES` list, when
targeting i386-freebsd.

Differential Revision: https://reviews.llvm.org/D136044
2023-01-22 22:16:51 +01:00
Dmitry Vyukov
f7f01599ec sanmd: refine selection of functions for UAR checking
There are no intrinsic functions that leak arguments.
If the called function does not return, the current function
does not return as well, so no possibility of use-after-return.
Sanitizer function also don't leak or don't return.
It's safe to both pass pointers to local variables to them
and to tail-call them.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D142190
2023-01-21 09:51:15 +01:00
Arthur Eubanks
2329a9266d Revert "sanmd: refine selection of functions for UAR checking"
This reverts commit 9d4f1a9eff27716069dc6a2d991baa228c197b85.

Breaks under -DCOMPILER_RT_BUILD_SANITIZERS=OFF
2023-01-20 13:40:50 -08:00
David Carlier
b4c840e70b [Sanitizers] intercept hexdump on FreeBSD.
Reviewers: vitalybuka
Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D110471
2023-01-20 18:00:38 +00:00
Dmitry Vyukov
9d4f1a9eff sanmd: refine selection of functions for UAR checking
There are no intrinsic functions that leak arguments.
If the called function does not return, the current function
does not return as well, so no possibility of use-after-return.
Sanitizer function also don't leak or don't return.
It's safe to both pass pointers to local variables to them
and to tail-call them.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D142190
2023-01-20 16:22:37 +01:00
Marco Elver
ed9ef9b4f2 tsan: Consider SI_TIMER signals always asynchronous
POSIX timer can be configured to send any kind of signal, however, it
fundamentally does not make sense to consider a timer a synchronous
signal. Teach TSan that timers are never synchronous.

The tricky bit here is correctly defining compiler-rt's siginfo
replacement, which is a rather complex struct. Extend it in a limited
way that is mostly cross-platform compatible and add offset tests in
sanitizer_platform_limits_posix.cpp.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D142117
2023-01-20 11:47:30 +01:00
Lang Hames
3507df9c20 [ORC][ORC-RT] Add support for callback-based lookup of JIT'd MachO unwind info.
In LLVM the MachOPlatform class is modified to identify unwind info sections
and the address ranges of the functions these sections cover. These address
ranges are then communicated to the ORC runtime by attaching them to the
register-object-platform-sections allocation action.

In the ORC runtime the unwind-info section addresses are recorded and used to
support lookup of unwind info via the new `findDynamicUnwindSections` function.
At bootstrap time the ORC runtime checks for the presence of new
unwind-info-lookup-registration functions in libunwind (see
https://reviews.llvm.org/D142176), and if available uses them to register the
`findDynamicUnwindSections` function with libunwind to enable callback-based
lookup. If the new unwind-info-lookup-registration functions are not available
then the ORC runtime falls back to using the existing libunwind registration
APIs.

The callback-based scheme is intended to address three shortcomings in the
current registration scheme for JIT'd unwind info on Darwin: (1) Lack of
compact-unwind support, (2) inability to describe the subarchitecture of JIT'd
frames, and (3) lack of efficient address-based lookup data structures in
libunwind.

For more details see the proposed libunwind changes in
https://reviews.llvm.org/D142176.
2023-01-19 22:37:57 -08:00
Advenam Tacet
6c485409de Adding missing colon
Simple typo fix.
The absence of this colon may be confusing and result in misinterpretation of the result.

In normal libfuzzer mode, that colon is present.

You can compare with:
aa0e9046c1/compiler-rt/lib/fuzzer/FuzzerLoop.cpp (L356)

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D142171
2023-01-19 20:57:12 -08:00
Arthur Eubanks
1f3f3c0ea7 Revert "Reland [pgo] Avoid introducing relocations by using private alias"
This reverts commit da5a8d14b8cc6cea16ee0929413c0672b47c93d9.

Causes more duplicate symbol errors, see https://bugs.chromium.org/p/chromium/issues/detail?id=1408161.
2023-01-19 10:20:38 -08:00
David Carlier
af05e818fb [Sanitizers] GetMemoryProfile implementation for FreeBSD.
Reviewers: dvyukov

Reviewed-By: dvyukov

Differental Revision: https://reviews.llvm.org/D140688
2023-01-19 18:01:03 +00:00
Kirill Stoimenov
f2b4b54417 [HWASAN] Init lsan and install at_exit hook
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141146
2023-01-19 01:40:17 +00:00
Lang Hames
ad4b66fd9b [ORC-RT] Specialize non-coalescing-IntervalMap to allow non-comparable values.
In non-coalescing IntervalMaps the value type should not be requried to be
equality-comparable.
2023-01-18 17:39:45 -08:00
Vitaly Buka
0ce4fca316 [NFC][sanitizers] Add COMPILER_RT_HAS_WTHREAD_SAFETY_*_FLAG 2023-01-18 17:27:10 -08:00
Paul Kirth
da5a8d14b8 Reland [pgo] Avoid introducing relocations by using private alias
In many cases, we can use an alias to avoid a symbolic relocations,
instead of using the public, interposable symbol. When the instrumented
function is in a COMDAT, we can use a hidden alias, and still avoid
references to discarded sections.

Previous versions of this patch allowed the compiler to name the
generated alias, but that would only be valid when the functions were
local. Since the alias may be used across TUs we use a more
deterministic naming convention, and add a ".local" suffix to the alias
name just as we do for relative vtables aliases.

https://reviews.llvm.org/rG20894a478da224bdd69c91a22a5175b28bc08ed9
removed an incorrect assertion on Mach-O which caused assertion failures in LLD.

We addressed the link errors under ThinLTO + PGO + CFI by being more
selective about which comdat functions can be given aliases.
Specifically, we now do not emit an alias in the case of a comdat
function with hidden visibility, since the alias would have the same
linkage and visibility, giving no benefit over using the symbol
directly. This also prevents LowerTypeTest from incorrectly updating the
dangling alias after GlobalOpt replaces uses, and introducing a
duplicate symbol.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D137982
2023-01-18 23:56:35 +00:00
Kirill Stoimenov
9545580447 [HWASAN] Remove FindHeapChunkByAddressFastLocked
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D142042
2023-01-18 23:33:11 +00:00
Kirill Stoimenov
005c158121 [HWASAN] Fix Fuchsia link problem
Reviewed By: mysterymath

Differential Revision: https://reviews.llvm.org/D142057
2023-01-18 22:30:27 +00:00
Johan Erlandsson
8565e8352b [hwasan] add pattern for short tag in symbolizer
Lines with 'record_addr:' are not processed when failing to decode
access tag. The regular format is: %02x/%02x but for a short tag it's:
%02x/%02x(%02x). Now it will handle both cases.

Tested-by: Ivar Henckel <ivar.henckel@sony.com>

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D141906
2023-01-18 11:12:39 -08:00
Kirill Stoimenov
1cf17279cc [HWASAN] Add leak sanitizer flag support
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141710
2023-01-18 00:03:51 -08:00
Vitaly Buka
0e08a85429 [HWASA] Restore LsanMetadata from D141642 Diff5
Unlike asan, we can't use pointer arithmetics to get from user ptr to
metadata. Asan does not use CombinedAllocator::GetMetadata and store
metadata next to the user data.
2023-01-17 23:45:51 -08:00
Vitaly Buka
c804775cd3 [hwasan] Fix LsanMetadata::LsanMetadata 2023-01-17 19:23:42 -08:00
Kirill Stoimenov
e022ca8b6e [HWASAN] Implemented LSAN SetLsanTag and IgnoreObjectLocked
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D141642
2023-01-17 17:59:17 -08:00