17463 Commits

Author SHA1 Message Date
Farzon Lotfi
5a48a824aa [compiler-rt] Fix interception_win.cpp arm64 instruction lengths
Updates GetInstructionSize to account for arm64 instruction sizes.

ARM64 instruction are always 4 bytes long but GetInstructionSize in
interception_win.cpp assumes x86_64 which has mixed sizes.

Fix is for: https://github.com/llvm/llvm-project/issues/64319

Before the changeclang_rt.asan_dynamic-aarch64.dll would crash at:
OverrideFunction -> OverrideFunctionWithHotPatch -> GetInstructionSize:825

After the change:
dllthunkintercept -> dllthunkgetrealaddressordie -> InternalGetProcAddress
2023-09-12 22:43:51 -04:00
Vitaly Buka
7b3bdc1472 [sanitizer] Remove SYMBOLIZER_DEPS from symbolizer
This loop is wrong, most of targets are not defined yet.
Also if we build with LLVM_ENABLE_RUNTIMES, these deps
are irrelevant.
2023-09-12 13:11:52 -07:00
Haowei Wu
063cd5545b [compiler-rt] Add missing include in unittest
This patch adds a missing header to sanitizer_lzw_test to fix a build
breakage after 54c1a9b20d89e85cd60d002c77b34c00f36520f4 is landed.
2023-09-12 11:05:01 -07:00
Christopher Ferris
8feeba643d [scudo] Allow using a different test main.
Fuchsia already uses a different main function for tests, so allow
anybody to use this mechanism.

Specifically, Android has a test main that allows tests to be run
in isolation and in parallel which speeds up the unit test runs
from ~14 seconds to ~4 seconds.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D159501
2023-09-12 11:03:18 -07:00
Vitaly Buka
11c8b9c907 [hwasan] Re-enable the test with fallback
The test passes without stdc++, but we prefer to run it with stdc++ if
availibe.
2023-09-11 22:38:39 -07:00
zhanglimin
ec42c78cc4 [sanitizer][msan] VarArgHelper for loongarch64
This patch adds support for variadic argument for loongarch64,
which is based on MIPS64. And `check-msan` all pass.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D158587
2023-09-12 09:51:18 +08:00
Vitaly Buka
8ee0874eca [test][hwasan] Fix UNSUPPORTED condition 2023-09-11 17:37:02 -07:00
Vitaly Buka
8b3ba143b0 [test][hwasan] Disable the test as it fails on Arm as well 2023-09-11 17:29:11 -07:00
Vitaly Buka
903008d56c [test][hwsasan] Invert enable_aliases check
For some reasons enable_aliases is not set when we
LLVM_ENABLE_RUNTIMES=compiler-rt instead of LLVM_ENABLE_PROJECTS.
2023-09-11 16:26:34 -07:00
Vitaly Buka
f665700647 [test][hwasan] Relax test condition
The test is flaky after Kernel upgrade from 6.0 to 6.5.
2023-09-11 14:40:40 -07:00
Vitaly Buka
aaf87dd2ae [test][hwasan] Disable test failing on x86_64 with no -lstdc++ 2023-09-11 14:34:30 -07:00
Vitaly Buka
4ee7cf72a3
[sanitizer] Change return type of __sanitizer_symbolize_demangle to bool (#65991)
To match other internal symbolizer functions.

This makes harder to distighush small buffer from a different failure,
but we has the same problem for the rest of the lib.

Still we use 16k buffer so it should be enough most of the time.
We can fix all function togerher if future, if needed.
2023-09-11 13:27:01 -07:00
Vitaly Buka
16a2aa3267 [test][tsan] Disable flaky test on PPC
COMPILER_RT_DEBUG was just added to sanitizer-ppc64le-linux, and this
test is already broken there.
2023-09-11 13:19:35 -07:00
Vitaly Buka
2344a72dd6 [test][sanitizer] Check LINKER_IS_LLD to detect LLD
This enables some tests requiring LLD when we test
compiler-rt activated with LLVM_ENABLE_RUNTIMES.
2023-09-11 11:02:01 -07:00
Vitaly Buka
2873a9ae27 [symbolizer] Check if dependecy exist
Deppending on how we build compiler-rt, as a project,
or as runtime, tools needed to build can be prebuilt or
exist as a target.
2023-09-10 16:58:49 -07:00
Vitaly Buka
8362ddb657 [test][sanitizer] Reduce output noise in test 2023-09-10 16:51:39 -07:00
Vitaly Buka
6766295985 [NFC][sanitizer] Return nullptr from PlatformDemangle
Use fallback name only on the top level, in Symbolizer::Demangle or
DlAddrSymbolizer. This makes PlatformDemangle to be more consistent with
SymbolizerTool and the loop in Symbolizer::Demangle which iterates over
all availible options.
2023-09-09 13:59:18 -07:00
Vitaly Buka
9f73a9ef6e [NFC][sanitizer] Clarify nullability of Symbolizer::Demangle result 2023-09-09 13:59:01 -07:00
Vitaly Buka
20941cdcd1 [NFC][sanitizer] Return nullptr instead of 0 2023-09-09 13:58:10 -07:00
Vitaly Buka
9dc5d8df16 [sanitizer] Add CMake flag to build with internal symbolizer
This intermediate result in moving internal symbolizer build
from sh script to CMake rules.

The flag is supposed to be used with:
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" -DLLVM_ENABLE_RUNTIMES="libunwind;libcxx;libcxxabi" -Sllvm-project/llvm

After converting sh script into cmake, we may add support for other build modes.

For https://github.com/llvm/llvm-project/issues/30098

Reviewed By: kstoimenov, MaskRay

Differential Revision: https://reviews.llvm.org/D157947
2023-09-08 16:56:57 -07:00
Vitaly Buka
0fefa6d01b [NFC][sanitizer] Add a few missed RTSanitizerCommonSymbolizerInternal
Reland edb211cb78317ad73aa4bd2d3df75194b7f23a72 and
5d7b75e2a5846f72f04a6fdb25a0df338f1825a1 without stats broken on OSX.
2023-09-08 15:01:38 -07:00
Jonas Devlieghere
0f50d0108c
Revert RTSanitizerCommonSymbolizerInternal changes
This reverts the following commits:

 - 5d7b75e2a5846f72f04a6fdb25a0df338f1825a1
  [NFC][memprof] Temporarly remove RTSanitizerCommonSymbolizerInternal

 - edb211cb78317ad73aa4bd2d3df75194b7f23a72
   [NFC][memprof] Temporarly remove RTSanitizerCommonSymbolizerInternal

 - 4d14b4a872577bf7ab5ef5bb6f8a2f10781a5f18
   [sanitizer] Add CMake flag to build with internal symbolizer

They break macOS nodes because CMake can't evaluate generator expressions:

  Error evaluating generator expression:

    $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.osx>
    $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.ios>
    $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.iossim>
2023-09-08 08:03:34 -07:00
Vitaly Buka
5d7b75e2a5 [NFC][memprof] Temporarly remove RTSanitizerCommonSymbolizerInternal
It's not supposed to be used anywere yet, as it was just added.
2023-09-07 22:39:37 -07:00
Vitaly Buka
edb211cb78 [NFC][sanitizer] Add a few missed RTSanitizerCommonSymbolizerInternal 2023-09-07 19:36:10 -07:00
Vitaly Buka
4d14b4a872 [sanitizer] Add CMake flag to build with internal symbolizer
This intermediate result in moving internal symbolizer build
from sh script to CMake rules.

The flag is supposed to be used with:
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" -DLLVM_ENABLE_RUNTIMES="libunwind;libcxx;libcxxabi" -Sllvm-project/llvm

After converting sh script into cmake, we may add support for other build modes.

For https://github.com/llvm/llvm-project/issues/30098

Reviewed By: kstoimenov, MaskRay

Differential Revision: https://reviews.llvm.org/D157947
2023-09-07 19:34:21 -07:00
Vitaly Buka
2f183d6efb [test][hwasan] Try to deflake release-shadow.c 2023-09-07 17:55:03 -07:00
Arseny Kapoulkine
bede46f57e
[Fuzzer] Optimize UpdateFeatureFrequency (#65288)
Instead of a linear scan, use a bitset to track rarity of features. This
improves fuzzer throughput rather dramatically (close to 2x) in early
exploratory phases; in steady state this seems to improve fuzzing
throughput by ~15% according to perf.

The benchmarks are done on an executable with ~100k features, so the
results may change based on the executable that's being fuzzed.

kFeatureSetSize is 2M so the bitset is adding 256 KB to
sizeof(InputCorpus), but this should be fine since there's already three
arrays indexed by feature index for a total of 200 MB.
2023-09-07 16:51:05 -07:00
Arseny Kapoulkine
d3440304b1
[Fuzzer] Update build.sh to fix build errors (#65496)
Switch from C++11 to C++14 as fuzzer requires std::chrono and stdlibc++
doesn't provide chrono literals when using -std=c++11.

Also remove 'u' from ar command to fix this warning: ar: `u' modifier
ignored since `D' is the default (see `U')
2023-09-07 16:38:28 -07:00
bipmis
370880cdcc [InstCombine] Fold icmp into phi beyond the same BB.
The icmp is being folded in phi only if they belong in the same BB.
This patch extends the same beyond the BB.
Have seen scenarios where this seems to be beneficial.

Differential Revision: https://reviews.llvm.org/D157740
2023-09-07 16:53:29 +01:00
Ying Yi
61d6154044 [llvm-cov] Fix the test of bnary-id-lookup.c after the commit cd8fe1dbc. 2023-09-06 16:44:19 +01:00
Fabio D'Urso
fdb29f7db5 [scudo] Rename AllocatorRingBuffer into scudo:ring_buffer
To maintain the convention of Scudo names starting with "scudo:",
which is used by some tooling to categorize memory usage.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D157102
2023-09-06 11:23:27 +02:00
Jie Fu
1438544e23 [DFSAN] Silence parameter 'va_labels' set but not used warning (NFC)
/data/llvm-project/compiler-rt/lib/dfsan/dfsan_custom.cpp:2546:37: error: parameter 'va_labels' set but not used [-Werror,-Wunused-but-set-parameter]
                       dfsan_label *va_labels, dfsan_label *ret_label,
                                    ^
1 error generated.
2023-09-06 09:28:43 +08:00
Tomasz Kuchta
8dbcf8eba7 [DFSAN] Add support for sscanf.
Reviewed By: browneee

Differential Revision: https://reviews.llvm.org/D153775
2023-09-06 01:16:31 +00:00
Chia-hung Duan
4c676d5265 [scudo] Clean up decl of RSSLimit funtions (NFC)
Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D159389
2023-09-05 18:37:15 +00:00
Petr Hosek
360d67730a
[compiler-rt] Link atomic against builtins (#65239)
The atomic shared library needs to be linked against builtins. The
`add_compiler_rt_runtime` call already has `DEP builtins` but that only
ensures that the `builtins` target is built before `clang_rt.atomic` but
doesn't link against `clang_rt.builtins`, to do so we need to use
`LINK_LIBS clang_rt.builtins`.
2023-09-03 22:45:11 -07:00
Jessica Clarke
4bb2416d42 [builtins][AArch64] Implement _sync out-of-line atomics
Whilst Clang does not use these, recent GCC does, and so on systems such
as FreeBSD that wish to use compiler-rt as the system runtime library
but also wish to support building programs with GCC these interfaces are
needed.

This is a light adaptation of the code committed to GCC by Sebastian Pop
<spop@amazon.com>, relicensed with permission for use in compiler-rt.

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

Reviewed By: sebpop, MaskRay

Differential Revision: https://reviews.llvm.org/D158536
2023-09-04 01:46:02 +01:00
Ulrich Weigand
208f9a2afc [msan][s390x] Fix long double interceptors
s390x is one of the architectures where the "long double" type was changed
from a 64-bit IEEE to a 128-bit IEEE type back in the glibc 2.4 days.
This means that glibc still exports two versions of the long double functions
(those that already existed back then), and we have to intercept the correct
version. There is already an existing define SANITIZER_NLDBL_VERSION that
indicates this situation, we simply have to respect it when intercepting
strtold and wcstold.

In addition, on s390x a long double return value is passed in memory via
implicit reference. This means the interceptor for functions returning
long double has to unpoison that memory slot, or else we will get
false-positive uninitialized memory reference warnings when the caller
accesses that return value - similar to what is already done in the
mallinfo interceptor. Create a variant macro INTERCEPTOR_STRTO_SRET and
use it on s390x.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159378
2023-09-02 12:36:53 +02:00
Fangrui Song
678e3ee123 [lldb] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 21:32:24 -07:00
Rainer Orth
d39a9e3b4d [Driver] Support GNU ld on Solaris
This patch supports GNU ld on Solaris in addition to Solaris ld, the
default.

- Linker selection is dynamic: one can switch between Solaris ld and GNU ld
  at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`.

- Testcases have been adjusted to test both variants in case there are
  differences.

- The `compiler-rt/cmake/config-ix.cmake` and
  `llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to
  Solaris ld are necessary because GNU accepts unknown `-z` options, but
  warns every time they are used, creating a lot of noise.  Since there
  seems to be no way to check for those warnings in
  `llvm_check_compiler_linker_flag` or `llvm_check_compiler_linker_flag`, I
  restrict the cmake tests to Solaris ld in the first place.

- The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and
  `flang/test/Driver/linker-flags.f90` are required when LLVM is built with
  `-DCLANG_DEFAULT_LINKER=gld` on Solaris: `MSVC.cpp`
  `visualstudio::Linker::ConstructJob` ultimately calls
  `GetProgramPath("gld")`, resulting in a search for `gld`, which exists in
  `/usr/bin/gld` on Solaris.  With `-fuse-ld=`, this doesn't happen and the
  expected `link` is returned.

- `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to
  enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld
  which has the `-S` semantics expected by the test.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both
`-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`.
No regressions in either case.

Differential Revision: https://reviews.llvm.org/D85309
2023-09-01 21:42:05 +02:00
Martin Storsjö
1f9eff100c [compiler-rt] Rename the now lone i386/chkstk2.S to i386/chkstk.S
This step was omitted from the previous commit,
885d7b759b5c166c07c07f4c58c6e0ba110fb0c2, for clarity.
2023-09-01 19:43:56 +03:00
Martin Storsjö
885d7b759b [compiler-rt] [builtins] Remove unused/misnamed x86 chkstk functions
For both MSVC and MinGW targets, the compiler generates calls to
functions for probing the stack, in functions that allocate a larger
amount of stack space.

The exact behaviour of these functions differ per architecture (some
decrement the stack, some actually decrement the stack pointer,
some only probe the stack). In MSVC mode, the compiler always
generates calls to a symbol named "__chkstk". In MinGW mode, the
symbol is named "__alloca" on i386 and "___chkstk_ms" on x86_64,
but the functions behave exactly the same as their MSVC counterparts
despite the differing names.

(On i386, these names are the raw symbol names - if considering
a C level function name with the extra implicit leading underscore,
they would be called "_chkstk" and "_alloca".)

Remove the misleading duplicate and unused functions. These were
added in fbfed869106cc9c9cad7538db5e65bcd24f4d92e /
c27de5b2790b65394c50ba13fab319995dbf5956 (adding "___chkstk_ms"
for both architectures, even if that symbol name only was used
on x86_64) and 40eb83ba56ba9c1d2e6de44deacf889ac0143cf7
(adding "__alloca" and "___chkstk", even if the former only was
used on i386, and the latter seeming like a misspelled form of
the MSVC function, with three underscores instead of two).

The x86_64 "___chkstk" was doubly surprising as that function had
the same behaviour as the function used on i386, while the
"__chkstk" that MSVC emitted calls to should behave exactly like
the preexisting "___chkstk_ms".

Remove the unused functions, and rename the misspelled MSVC-like
symbols to the correct name that MSVC mode actually uses.

Note that these files aren't assembled at all when building
compiler-rt builtins in MSVC mode, as they are expected to be
provided by MSVC libraries when building code in MSVC mode.

Differential Revision: https://reviews.llvm.org/D159139
2023-09-01 19:43:50 +03:00
Vitaly Buka
469c3e77cb [test][fuzzer] Deflake fork_corpus_groups.test 2023-09-01 01:11:58 -07:00
Vitaly Buka
99e5f6066e [test][fuzzer] Deflake fork.test 2023-09-01 00:57:35 -07:00
Artem Dergachev
0a3519d5a2 [LSan] Mark create_thread_leak.cpp as UNSUPPORTED: darwin.
It started to fail in a flaky manner a few days ago on GreenDragon buildbots
(i.e. x86_64-darwin). I didn't track down the root cause but LSan isn't
actually supported on darwin anyway, so UNSUPPORTED seems appropriate.

Prior art: 3ff080b5.
2023-08-31 16:41:35 -07:00
Leonard Chan
7ce67d3310 [scudo][tests] Store the allocator instance in a global rather than posix_memalign it
The combined scudo allocator object is over 4MB in size which gets created via
the posix_memalign on every test run. If the tests are sanitized with asan,
then the asan allocator will need to mmap this large object every single time a
test is run. Depending on where this is mapped, we might not be able to find a
large enough contiguous space for scudo's primary allocator to reserve an arena.
Such a case is more likely to occur on 39-bit vma for RISCV where the arena size
is roughly a quarter of the whole address space and fragmentation can be a big issue.

This helps reduce fragmentation by instead placing the allocator instance in a
global storage rather than doing an anonymous mmap.

Differential Revision: https://reviews.llvm.org/D158767
2023-08-31 22:27:14 +00:00
Karl-Johan Karlsson
831b509d5f [builtins] Fix signed integer overflows in fp_fixint_impl.inc
When compiling the builtins with the undefined behavior sanitizer and running
testcases you end up with the following warning:

UBSan: fp_fixint_impl.inc:39:42: left shift of 8388608 by 40 places cannot be represented in type 'fixint_t' (aka 'long long')
UBSan: fp_fixint_impl.inc:39:17: signed integer overflow: -1 * -9223372036854775808 cannot be represented in type 'fixint_t' (aka 'long long')

This can be avoided by doing the shift and the multiplication in a matching
unsigned variant of the type.

The added test only trigger the intended signed overflow case when the builtins
are built with -D__SOFTFP__.

This was found in an out of tree target.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D159069
2023-08-31 10:08:15 +02:00
Leonard Chan
1abcf58402 [lsan][Fuchsia] Fix bounds checking for thread_local allocator cache when scanning TLS regions
When scanning over TLS regions, we attempt to check if one of the regions is
one of the thread_local allocator caches which would be located in one of the
TLS blocks pointer to by the DTV. This is to prevent marking a pointer that was
allocated by the primary allocator (from a thread_local cache) as reachable. The
check is a simple bounds check to see if the allocator cache is within the
bounds of one of the TLS block we're iterating over, but it looks like the check
for the end of the cache is slightly incorrect.

Differential Revision: https://reviews.llvm.org/D156015
2023-08-30 20:49:21 +00:00
Christopher Ferris
c8bf93dba0 [scudo] Remove RSS checking code.
The RSS code is not very useful and can be replicated by using
ulimit. Remove it and remove the options associated with it.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D159155
2023-08-30 12:35:14 -07:00
Ian Anderson
680da4b5d7 [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized
stdarg.h and stddef.h have to be textual headers in their upcoming modules to support their `__needs_xxx` macros. That means that they won't get precompiled into their modules' pcm, and instead their declarations will go into every other pcm that uses them. For now that's ok since the type merger can handle the declarations in these headers, but it's suboptimal at best. Make separate headers for all of the pieces so that they can be properly modularized.

Reviewed By: aaron.ballman, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D158709
2023-08-30 11:41:12 -07:00
Alex Brachet
445978ee8c [compiler-rt] Use just built libatomic if available
Use libclang_rt.atomic.so instead of the libatomic installed
on the system if it is available.

Differential Revision: https://reviews.llvm.org/D151680
2023-08-29 21:38:56 +00:00