Commit Graph

15424 Commits

Author SHA1 Message Date
David Spickett c01548c7e0 [compiler-rt][lsan] Increase libdl_deadlock test timeout
We (Linaro) still have the occasional failure here due
to high load on a shared buildbot machine.

We are looking into general soloutions but perhaps this
will help in the meantime.
2022-02-03 10:54:25 +00:00
Tim Northover becb29aeb6 Revert "[compiler-rt][Darwin] Add arm64 to simulator platforms"
This reverts commit a8e5ce76b4.

It looks like older Xcodes' headers don't allow arm64 builds so it was causing
CI failures.
2022-02-03 09:42:49 +00:00
Kirill Stoimenov 8b899e067e [ASan] Added intermediate functions between assembly and __asan_report.* to avoid link errors.
Instead of calling asan_report.* directly from assembly code they have been replaced with corresponding asan_report.*_asm function, which call asan_report.*. All asan_report.* are now undefined weak symbols, which allows DSOs to link when z defs is used.

Reviewed By: MaskRay, morehouse

Differential Revision: https://reviews.llvm.org/D118813
2022-02-03 00:31:27 +00:00
Tobias Hieta a8e5ce76b4 [compiler-rt][Darwin] Add arm64 to simulator platforms
I was looking around and noticed that builtins for iossim, tvossim
and watchossim was missing arm64 builds, while apple's clang
toolchain ship with these. After a bit of searching around it just
seems like these are not listed correctly in CMake to be enabled.

I enabled just arm64 since I saw that Apple clang didn't include
arm64e.

Reviewed By: t.p.northover

Differential Revision: https://reviews.llvm.org/D118759
2022-02-02 10:37:51 +01:00
Rainer Orth d83c9005cf [sanitizer_common][test] Enable tests on SPARC
Unfortunately, the `sanitizer_common` tests are disabled on many targets
that are supported by `sanitizer_common`, making it easy to miss issues
with that support.  This patch enables SPARC testing.

Beside the enabling proper, the patch fixes (together with D91607
<https://reviews.llvm.org/D91607>) the failures of the `symbolize_pc.cpp`,
`symbolize_pc_demangle.cpp`, and `symbolize_pc_inline.cpp` tests.  They
lack calls to `__builtin_extract_return_addr`.  When those are added, they
`PASS` when compiled with `gcc`.  `clang` incorrectly doesn't implement a
non-default `__builtin_extract_return_addr` on several targets, SPARC
included.

Because `__builtin_extract_return_addr(__builtin_return_addr(0))` is quite
a mouthful and I'm uncertain if the code needs to compile with msvc which
appparently has it's own `_ReturnAddress`, I've introduced
`__sanitizer_return_addr` to hide the difference and complexity.  Because
on 32-bit SPARC `__builtin_extract_return_addr` differs when the calling
function returns a struct, I've added a testcase for that.

There are a couple more tests failing on SPARC that I will deal with
separately.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D91608
2022-02-01 22:33:56 +01:00
Fangrui Song 9477a308ca [hwasan][test] Remove obsoleted/removed -fno-experimental-new-pass-manager 2022-02-01 13:24:39 -08:00
Florian Mayer aefb2e134d [hwasan] work around lifetime issue with setjmp.
setjmp can return twice, but PostDominatorTree is unaware of this. as
such, it overestimates postdominance, leaving some cases (see attached
compiler-rt) where memory does not get untagged on return. this causes
false positives later in the program execution.

this is a crude workaround to unblock use-after-scope for now, in the
longer term PostDominatorTree should bemade aware of returns_twice
function, as this may cause problems elsewhere.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D118647
2022-02-01 12:14:20 -08:00
Matt Morehouse de4e8bc3ac [HWASan] Properly handle musttail calls.
Fixes a compile error when the `clang::musttail` attribute is used.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D118712
2022-02-01 11:23:43 -08:00
David Spickett df3d121bb9 [compiler-rt][fuzzer] Disable 2 tests for Arm Thumb builds
These tests appear to be causing timeouts on our silent
Thumbv7 bot: https://lab.llvm.org/staging/#/builders/162/builds/260

It is possible they would complete given enough time. value-profile-switch
seems to take a long time even on a powerful Armv8 machine.
2022-02-01 10:13:23 +00:00
Snehasish Kumar 8306968b59 [memprof] Move the meminfo block struct to MemProfData.inc.
The definition of the MemInfoBlock is shared between the memprof
compiler-rt runtime and llvm/lib/ProfileData/. This change removes the
memprof_meminfoblock header and moves the struct to the shared include
file. To enable this sharing, the Print method is moved to the
memprof_allocator (the only place it is used) and the remaining uses are
updated to refer to the MemInfoBlock defined in the MemProfData.inc
file.

Also a couple of other minor changes which improve usability of the
types in MemProfData.inc.
* Update the PACKED macro to handle commas.
* Add constructors and equality operators.
* Don't initialize the buildid field.

Differential Revision: https://reviews.llvm.org/D116780
2022-01-31 15:04:41 -08:00
Anatoly Trosinenko 4bcd2588a9 [compiler-rt][builtins] Use c[tl]zsi macro instead of __builtin_c[tl]z
`__builtin_c[tl]z` accepts `unsigned int` argument that is not always the
same as uint32_t. For example, `unsigned int` is uint16_t on MSP430.

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D86547
2022-01-30 23:04:07 +03:00
Anatoly Trosinenko 9595f00510 [compiler-rt][builtins] Use explicitly-sized integer types for LibCalls
Use s[iu]_int instead of `(unsigned) int` and d[ui]_int instead of
`(unsigned) long long` for LibCall arguments.

Note: the `*vfp` LibCall versions were NOT touched.

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D86546
2022-01-30 21:10:54 +03:00
Rainer Orth 067650fd12 [sanitizer_common] Use atomic builtin in sanitizer_atomic_clang.h
As discussed in D118021 <https://reviews.llvm.org/D118021>, `clang -m32` on
Solaris/sparcv9 currently incorrectly doesn't inline atomics on 8-byte
operands, unlike `gcc`.  With the workaround in that patch in place, we're
left with may undefined references to `__sync_val_compare_and_swap_8`,
which isn't provided by `libatomic`.  This reference is due to the use of
`__sync_val_compare_and_swap` in `sanitizer_atomic_clang.h`'s
`atomic_compare_exchange_strong`.  As is already done in
`scudo/standalone/atomic_helpers.h`, using `__atomic_compare_exchange`
instead avoids this problem.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D118024
2022-01-29 22:52:55 +01:00
John Ericson 7017e6c9cf [cmake] Partially deduplicate `{llvm,compiler_rt}_check_linker_flag` for runtime libs and llvm
We previously had a few varied definitions of this floating around.

I had tried to make the one installed with LLVM handle all the cases, and then made the others use it, but this ran into issues with `HandleOutOfTreeLLVM` not working for compiler-rt, and also `CMAKE_EXE_LINKER_FLAGS` not working right without `CMP0056` set to the new behavior.

 My compromise solution is this:

 - No not completely deduplicate: the runtime libs will instead use a version that still exists as part of the internal and not installed common shared CMake utilities. This avoids `HandleOutOfTreeLLVM` or a workaround for compiler-rt.

- Continue to use `CMAKE_REQUIRED_FLAGS`, which effects compilation and linking. Maybe this is unnecessary, but it's safer to leave that as a future change. Also means we can avoid `CMP0056` for now, to try out later, which is good incrementality too.

- Call it `llvm_check_compiler_linker_flag` since it, in fact is about both per its implementation (before and after this patch), so there is no name collision.

In the future, we might still enable CMP0056 and make compiler-rt work with HandleOutOfTreeLLVM, which case we delete `llvm_check_compiler_flag` and go back to the old way (as these are, in fact, linking related flags), but that I leave for someone else as future work.

The original issue was reported to me in https://reviews.llvm.org/D116521#3248117 as
D116521 made clang and LLVM use the common cmake utils.

Reviewed By: sebastian-ne, phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D117537
2022-01-29 06:07:24 +00:00
Fangrui Song c80d349859 [msan][tsan] Refine __fxstat{,at}{,64} condition
In glibc before 2.33, include/sys/stat.h defines fstat/fstat64 to
`__fxstat/__fxstat64` and provides `__fxstat/__fxstat64` in libc_nonshared.a.
The symbols are glibc specific and not needed on other systems.

Reviewed By: vitalybuka, #sanitizers

Differential Revision: https://reviews.llvm.org/D118423
2022-01-28 09:15:39 -08:00
Matt Morehouse f7c28332de [HWASan] Leave pointer tagged when calling memmove.
Fixes a false positive that occurs when a user-implemented memmove is
instrumented by HWASan.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D118180
2022-01-28 06:15:38 -08:00
Martin Storsjö aa45fc41c8 [sanitizers] Silence warnings about unused variables in i386 build. NFC. 2022-01-28 12:30:38 +02:00
Ellis Hoag 11d3074267 [InstrProf] Add single byte coverage mode
Use the llvm flag `-pgo-function-entry-coverage` to create single byte "counters" to track functions coverage. This mode has significantly less size overhead in both code and data because
  * We mark a function as "covered" with a store instead of an increment which generally requires fewer assembly instructions
  * We use a single byte per function rather than 8 bytes per block

The trade off of course is that this mode only tells you if a function has been covered. This is useful, for example, to detect dead code.

When combined with debug info correlation [0] we are able to create an instrumented Clang binary that is only 150M (the vanilla Clang binary is 143M). That is an overhead of 7M (4.9%) compared to the default instrumentation (without value profiling) which has an overhead of 31M (21.7%).

[0] https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D116180
2022-01-27 17:38:55 -08:00
Nico Weber 912f1c8ce3 [gn build] slighly reformat files to make sync script work 2022-01-27 20:09:04 -05:00
David Tenty 492cbbc36a [compiler-rt][profile][AIX] pass extra link opts for test
This is a follow up to D118101, that added bexpfull to the test on instrprof-get-filename-merge-mode.c AIX, in order to get the
necessary symbols exported. But unfortunately the extra dependent symbols this exports actually cause segfaults, which is why
this isn't really recommended in the first place, so just use an actual export list.

Differential Revision: https://reviews.llvm.org/D118310
2022-01-27 15:25:19 -06:00
Ellis Hoag c9baa5608b [InstrProf][Correlate] Verify debug info with llvm-profdata show
Use the `llvm-profdata show` command to verify debug info for profile correlation using the `--debug-info` option.

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D118181
2022-01-27 10:11:04 -08:00
Roland McGrath 1510668fb0 [asan] Add missing #include of sanitizer_platform.h
The "asan/asan_mapping.h" header relies on sanitizer_platform.h
macros, but doesn't directly include the header.  All the existing
uses until recently happened to be in places where some other header
had indirectly included sanitizer_platform.h first.  The addition of
asan_rtl_x86_64.S was the first place to use "asan/asan_mapping.h"
alone.  It so happens that its uses of the macros make having no
macros defined equivalent to SANITIZER_LINUX, so this did not affect
Linux builds.  But the assembly constants in asan_rtl_x86_64.S were
wrong for Fuchsia when SANITIZER_FUCHSIA was not properly defined.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D118296
2022-01-26 18:19:08 -08: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
Petr Hosek 0606817d0b [CMake] Handle in-tree libc++ for sanitizer tests
We have been relying on the logic for C++ ABI library for sanitizer
tests but that's incorrect since most tests require a full C++ library
and not just C++ ABI. This change tries to address this by using the
dependency on libc++ if available.

Differential Revision: https://reviews.llvm.org/D118163
2022-01-26 13:09:17 -08:00
Arthur Eubanks 092f6ae292 [test][ASan][Win] Print more info when LoadLibrary fails
Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D118206
2022-01-26 10:33:23 -08:00
Ellis Hoag f170595249 [InstrProf][Correlator] Do not compress names when reading debug info
There is no need to compress the names string when correlating with
debug info since InstrProfReader will immediately uncompress it anyway.
This also removes the dependency on zlib in this case.

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D118176
2022-01-25 12:52:37 -08:00
Ellis Hoag 9c2891a8ed [InstrProf][correlation] Read DWARFv5 `OP_addrx` location
Correctly read `OP_addrx` type encodings for DWARFv5 locations.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D118098
2022-01-25 11:03:25 -08:00
David Tenty a09be08594 [compiler-rt][profile][AIX] pass extra link opts for test
The AIX linker doesn't export any symbols by default, so an export list is usually used. Since clang doesn't have the tools to auto-generate an export list yet, just pass the linker an extra opt to tell it to export everything. This is  generally not recommended for real shared libs, but is fine for the purpose of this test.

Differential Revision: https://reviews.llvm.org/D118101
2022-01-25 13:57:02 -05:00
Hans Wennborg 38e16e1ceb Use -gdwarf-4 in compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
otherwise the test fails after the recent DWARF 4 -> 5 default change,
see https://github.com/llvm/llvm-project/issues/53387
2022-01-24 19:03:08 +01:00
Julian Lettner 1f4a0531b3 [TSan] Mark test unsupported on Darwin 2022-01-23 22:01:48 -08:00
Julian Lettner db07e082ab [TSan] Omit vfork interceptor iOS simulator runtime
`_vfork` moved from libsystem_kernel.dylib to libsystem_c.dylib as part
of the below changes.  The iOS simulator does not actually have
libsystem_kernel.dylib of its own, it only has the host Mac's.  The
umbrella-nature of Libsystem makes this movement transparent to
everyone; except the simulator! So when we "back deploy", i.e., use the
current version of TSan with an older simulator runtime then this symbol
is now missing, when we run on the latest OS (but an older simulator
runtime).

Note we use `SANITIZER_IOS` because usage of vfork is forbidden on iOS
and the API is completely unavailable on watchOS and tvOS, even if this
problem is specific to the iOS simulator.

Caused by:
rdar://74818691 (Shim vfork() to fork syscall on iOS)
rdar://76762076 (Shim vfork() to fork syscall on macOS)

Radar-Id: rdar://8634734
2022-01-21 17:36:12 -08:00
Petr Hosek 10e5c513b5 Revert "[cmake] Duplicate `{llvm,compiler_rt}_check_linker_flag` for runtime libs and llvm"
This reverts commit 4af11272f5.
2022-01-21 09:53:14 -08:00
David Tenty 5659638418 Revert "[compiler-rt][cmake] Use HandleOutOfTreeLLVM like libcxx and friends"
This reverts commit 8c9f62ea90, which is causing build failures on
the bots because it inadvertently changes the output directory of the compiler-rt libs when
built as a runtime.

Differential Revision: https://reviews.llvm.org/D117815
2022-01-21 12:22:17 -05:00
John Ericson 4af11272f5 [cmake] Duplicate `{llvm,compiler_rt}_check_linker_flag` for runtime libs and llvm
We previously had a few varied definitions of this floating around. I made the one installed with LLVM handle all the cases, and then made the others use it.

This issue was reported to me in https://reviews.llvm.org/D116521#3248117 as
D116521 made clang and llvm use the common cmake utils.

Reviewed By: sebastian-ne, phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D117537
2022-01-20 21:18:42 +00:00
John Ericson 8c9f62ea90 [compiler-rt][cmake] Use HandleOutOfTreeLLVM like libcxx and friends
This gives us the option of using CMake modules from LLVM, and other
things. We will use that to deduplicate code later.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D117815
2022-01-20 21:17:31 +00:00
zijunzhao c0f9592daa add tsan shared library
Add tsan shared library on Android. Only build tsan when minSdkVersion is above 23.

Reviewed By: danalbert, vitalybuka

Differential Revision: https://reviews.llvm.org/D108394
2022-01-20 17:54:16 +00:00
Ellis Hoag ccb09a4889 Fix broken comment in InstrProfData.inc
This comment was introduced in https://reviews.llvm.org/D117631

Differential Revision: https://reviews.llvm.org/D117705
2022-01-19 10:38:13 -08:00
Ellis Hoag 88d81770f1 [InstrProf] Restore InstrProfData.inc to fix Fuchsia builds
https://reviews.llvm.org/D116179 introduced some changes to
`InstrProfData.inc` which broke some downstream builds. This commit
reverts those changes since they only changes two field names.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D117631
2022-01-19 10:10:58 -08:00
Ed Maste 64de0064f3 [sanitizer] Improve FreeBSD ASLR detection
The kern.elf64.aslr.pie_enable and kern.elf32.aslr.pie_enable sysctls
control the default setting for PIE binary address randomization, but
it is possible to enable or disable ASLR on a per-process basis.  So,
use procctl(2) to query whether ASLR is enabled.

(Note that with ASLR enabled but sysctl kern.elf64.aslr.pie_enable=0
a PIE binary will in effect have randomization disabled, and would be
functional with msan.  This is not intended as as a user-facing control
though; proccontrol(1) should be used to disable aslr for the process.)

Reviewed By: devnexen

Differential Revision: https://reviews.llvm.org/D117521
2022-01-18 17:07:13 -05:00
John Ericson 09949c48cb [compiler-rt][cmake] Use `GNUInstallDirs` to support custom installation dirs
I am breaking apart D99484 so the cause of build failures is easier to
understand.

Differential Revision: https://reviews.llvm.org/D117420
2022-01-17 03:13:56 +00:00
hyeongyu kim be9eafc710 [msan] reflect the changed flag to the tests.
1b1c8d changed `enable-noundef-analysis` flag to
`disable-noundef-analysis`.  noundef_analysis.cpp was using old
`enable-noundef-analysis` flag and this patch fixes it.
2022-01-16 20:48:05 +09:00
John Ericson da77db58d7 Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
https://lab.llvm.org/buildbot/#/builders/46/builds/21146 Still have
this odd error, not sure how to reproduce, so I will just try breaking
up my patch.

This reverts commit 4a678f8072.
2022-01-16 05:48:30 +00:00
John Ericson 4a678f8072 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-16 05:33:07 +00:00
Lang Hames 1088c78c3b [ORC-RT] Remove some stale comments.
We switched to SPS serialization for these functions in 089acf2522.
2022-01-16 14:03:15 +11:00
Lang Hames 0ede1b906d [ORC-RT] Update WrapperFunctionCall for 089acf2522.
089acf2522 updated WrapperFunctionCall to carry arbitrary argument payloads
(rather than plain address ranges). This commit implements the corresponding
update for the ORC runtime.
2022-01-16 13:48:11 +11:00
Alexandre Ganea 5d5d806e7b Silence warning with MSVC.
Fixes:

[2587/4073] Building CXX object projects\compiler-rt\lib\sanitizer_common\CMakeFiles\RTSanitizerCommon.x86_64.dir\sanitizer_stoptheworld_win.cpp.obj
D:\git\llvm-project\compiler-rt\lib\sanitizer_common\sanitizer_stoptheworld_win.cpp(125,33): warning: comparison of integers of different signs: 'DWORD' (aka 'unsigned long') and 'int' [-Wsign-compare]
      if (SuspendThread(thread) == -1) {
          ~~~~~~~~~~~~~~~~~~~~~ ^  ~~
1 warning generated.
2022-01-15 12:06:38 -05:00
Alexandre Ganea 7fcc44bca4 [compiler-rt][cmake] Fix clang-cl warnings introduced in ae4c643bcd
See report in https://reviews.llvm.org/D116872#3245667
2022-01-15 12:06:38 -05:00
Fangrui Song be622a47ff [CMake] Fix compiler-rt -Wl,-z,gnu-version-script-compat warnings on non-Solaris 2022-01-15 01:35:48 -08:00
John Ericson 6e52bfe09d Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
Sorry for the disruption, I will try again later.

This reverts commit efeb501970.
2022-01-15 07:35:02 +00:00
Kevin Athey 0f93448235 enable noundef analysis with -fsanitize-memory-param-retval
Enable noundef analysis (-enable-noundef-analysis) via the -fsanitize-memory-param-retval clang flag.
This completes the work found in:
  - https://reviews.llvm.org/D116855
  - https://reviews.llvm.org/D116633

Depends on D116633

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D117293
2022-01-14 17:18:29 -08:00
John Ericson efeb501970 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-15 01:08:35 +00: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
Ellis Hoag f21473752b [InstrProf][NFC] Do not assume size of counter type
Existing code tended to assume that counters had type `uint64_t` and
computed size from the number of counters. Fix this code to directly
compute the counters size in number of bytes where possible. When the
number of counters is needed, use `__llvm_profile_counter_entry_size()`
or `getCounterTypeSize()`. In a later diff these functions will depend
on the profile mode.

Change the meaning of `DataSize` and `CountersSize` to make them more clear.
* `DataSize` (`CountersSize`) - the size of the data (counter) section in bytes.
* `NumData` (`NumCounters`) - the number of data (counter) entries.

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D116179
2022-01-14 11:29:11 -08:00
Nenad Mikša 0c391133c9 Fix registers for Windows on ARM64
Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D116376
2022-01-13 21:39:01 -08:00
Emily Shi 53cb3a7bb4 Revert "[compiler-rt][darwin] check for strcmp to test interceptors instead of pthread_create"
This reverts commit 1e36bd8516.
2022-01-13 10:31:52 -08:00
Emily Shi 1e36bd8516 [compiler-rt][darwin] check for strcmp to test interceptors instead of pthread_create
If `pthread_create` is not available on a platform, we won't be able to check if interceptors work. Use `strcmp` instead.

Reviewed By: yln

Differential Revision: https://reviews.llvm.org/D116989
2022-01-12 16:17:26 -08:00
Kuba Mracek 23e8a4d160 [UBSan] Relax test expectations in Misc/objc-cast.m test
The test checks that an array of Obj-C literal integers (e.g. `@1`) gets a UBSan
warning when cast to an NSString, however the actual concrete Obj-C class of
literal integers doesn't always need to be __NSCFNumber. Let's relax the test
expectations to allow NSConstantIntegerNumber. Which exact subclass of NSNumber
is used is not actually important for the test (the test is just checking that
the invalid cast warning is thrown).
2022-01-12 05:25:02 -08:00
Julian Lettner 7acb68b80b [NFC] Fixup for comment 2022-01-11 15:35:15 -08:00
Julian Lettner ff11cd9550 [TSan][Darwin] Enable Trace/TraceAlloc unit tests
These tests are now green:
```
  Trace.MultiPart
  Trace.RestoreAccess
  Trace.RestoreMutexLock
  TraceAlloc.FinishedThreadReuse
  TraceAlloc.FinishedThreadReuse2
  TraceAlloc.SingleThread
```

rdar://82107856
2022-01-11 15:33:29 -08:00
Julian Lettner 4614b93f53 [TSan][Darwin] Mark test UNSUPPORTED for iOS simulator 2022-01-11 15:01:24 -08:00
Rainer Orth c79d372791 [sanitizer_common] Only use NT_GNU_BUILD_ID in sanitizer_linux_libcdep.cpp if supported
D114294 <https://reviews.llvm.org/D114294> broke the Solaris buildbots:

  /opt/llvm-buildbot/home/solaris11-amd64/clang-solaris11-amd64/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp:613:29: error: use of undeclared identifier 'NT_GNU_BUILD_ID'
          if (nhdr->n_type == NT_GNU_BUILD_ID && nhdr->n_namesz == kGnuNamesz) {
                              ^

Like D107556 <https://reviews.llvm.org/D107556>, it forgot that
`NT_GNU_BUILD_ID` is an unportable GNU extension.

Fixed by making the code conditional on the definition of the macro.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D117051
2022-01-11 23:50:37 +01:00
Alexandre Ganea ae4c643bcd [compiler-rt] Silence warnings when building with MSVC
Differential Revision: https://reviews.llvm.org/D116872
2022-01-11 10:36:57 -05:00
Julian Lettner f4ab0f6e09 [TSan] Avoid deadlock in test for compiler-rt debug build
rdar://86776155
2022-01-10 11:40:54 -08:00
jinge90 6fab274275 Control-flow Enforcement Technology (CET), published by Intel, introduces
indirect branch tracking(IBT) feature aiming to ensure the target address
of an indirect jump/call is not tampered.
When IBT is enabled, each function or target of any indirect jump/call will start
with an 'endbr32/64' instruction otherwise the program will crash during execution.
To build an application with CET enabled. we need to ensure:

  1. build the source code with "-fcf-protection=full"
  2. all the libraries linked with .o files must be CET enabled too

This patch aims to enable CET for compiler-rt builtins library, we add an option
"COMPILER_RT_ENABLE_CET" whose default value is OFF to enable CET for compiler-rt
in building time and when this option is "ON", "-fcf-protection=full" is added to
BUILTINS_CFLAG and the "endbr32/64" will be placed in the beginning of each assembly
function. We also enabled CET for crtbegin, crtend object files in this patch.

Reviewed by: MaskRay, compnerd, manojgupta, efriedma
Differential Revision: https://reviews.llvm.org/D109811

Signed-off-by: jinge90 <ge.jin@intel.com>
2022-01-10 11:01:11 +08:00
Lang Hames 3e9919cf57 [ORC-RT] Add missing headers from 1d82e19f37.
This should fix the build failure at
https://lab.llvm.org/buildbot/#/builders/165/builds/12997
2022-01-08 17:46:14 +11:00
Lang Hames 1d82e19f37 [ORC-RT] Add debug logging macros.
Inspired by LLVM_DEBUG, but using environment variables rather than command line
options.

Code can use ORC_RT_DEBUG(...) (if ORC_RT_DEBUG_TYPE is set), or
ORC_RT_DEBUG_WITH_TYPE(<type>, ...) (if ORC_RT_DEBUG_TYPE is not set. E.g. in
headers).

Debug logging is enabled in the executor by setting the ORC_RT_DEBUG environment
variable. Debug logging can be restricted by type by setting the
ORC_RT_DEBUG_TYPES environment variable to a comma separated list of types,
e.g. ORC_RT_DEBUG_TYPES=macho_platform,sps.

Differential Revision: https://reviews.llvm.org/D116139
2022-01-08 17:28:02 +11:00
Lang Hames 089acf2522 [ORC][JITLink] Merge JITLink AllocActionCall and ORC WrapperFunctionCall.
These types performed identical roles. Merging them simplifies interoperability
between JITLink and ORC APIs (allowing us to address a few FIXMEs).
2022-01-08 16:46:15 +11:00
Ben Wagner fb1582f6c5 [libc++] Disable coverage with sanitize-coverage=0
When building libcxx, libcxxabi, and libunwind the build environment may
specify any number of sanitizers. For some build feature tests these
sanitizers must be disabled to prevent spurious linking errors. With
-fsanitize= this is straight forward with -fno-sanitize=all. With
-fsanitize-coverage= there is no -fno-sanitize-coverage=all, but there
is the equivalent undocumented but tested -fsanitize-coverage=0.

The current build rules fail to disable 'trace-pc-guard'. By disabling
all sanitize-coverage flags, including 'trace-pc-guard', possible
spurious linker errors are prevented. In particular, this allows libcxx,
libcxxabi, and libunwind to be built with HonggFuzz.

CMAKE_REQUIRED_FLAGS is extra compile flags when running CMake build
configuration steps (like check_cxx_compiler_flag). It does not affect
the compile flags for the actual build of the project (unless of course
these flags change whether or not a given source compiles and links or
not). So libcxx, libcxxabi, and libunwind will still be built with any
specified sanitize-coverage as before. The build configuration steps
(which are mostly checking to see if certain compiler flags are
available) will not try to compile and link "int main() { return 0;}"
(or other specified source) with sanitize-coverage (which can fail to
link at this stage in building, since the final compile flags required
are yet to be determined).

The change to LIBFUZZER_CFLAGS was done to keep it consistent with the
obvious intention of disabling all sanitize-coverage. This appears to
be intentional, preventing the fuzzer driver itself from showing up in
any coverage calculations.

Reviewed By: #libunwind, #libc, #libc_abi, ldionne, phosek

Differential Revision: https://reviews.llvm.org/D116050
2022-01-07 17:53:21 -08:00
Julian Lettner bdef75fd61 [Darwin][Sanitizer] Lower Python requirement for iOS simulator testing
Lower Python requirements: 3.7 -> 3.6

Workaround introduced in: ebd8eee62a
2022-01-07 17:37:29 -08:00
Julian Lettner ebd8eee62a [Darwin] Apply workaround to make symbolication in iOS simulators work
Specify `ASAN_SYMBOLIZER_PATH` when running simulator tests.  This will
unblock simulator testing in GreenDragon (Apple's open source testing).
2022-01-07 16:49:12 -08:00
Julian Lettner 6f480655e6 [ASan][Darwin] Avoid crash during ASan initialization
Always pass `depth=1` to `vm_region_recurse_64()`.  `depth` is a in-out
parameter and gets reset to 0 after the first call, so we incorrectly
pass `depth=0` on subsequent calls.

We want to avoid the following crash:
```
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000180000000
Exception Codes: 0x0000000000000001, 0x0000000180000000
VM Region Info: 0x180000000 is not in any region. Bytes after previous region: 277577729 Bytes before following region: 384270336
   REGION TYPE         START - END   [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
   Stack          16f64c000-16f748000 [ 1008K] rw-/rwx SM=PRV thread 0
---> GAP OF 0x27730000 BYTES
   unused shlib __TEXT   196e78000-196eac000 [ 208K] r-x/r-x SM=COW ... this process
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [767]
```

Crashing code:
```
static mach_header *get_dyld_image_header() {
 unsigned depth = 1;
 vm_size_t size = 0;
 vm_address_t address = 0;
 kern_return_t err = KERN_SUCCESS;
 mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;

 while (true) {
  struct vm_region_submap_info_64 info;
  err = vm_region_recurse_64(mach_task_self(), &address, &size, &depth,
                (vm_region_info_t)&info, &count);
  if (err != KERN_SUCCESS) return nullptr;

  if (size >= sizeof(mach_header) && info.protection & kProtectionRead) {
   mach_header *hdr = (mach_header *)address;
   if ((hdr->magic == MH_MAGIC || hdr->magic == MH_MAGIC_64) &&   // << CRASH: sanitizer_procmaps_mac.cpp:176
     hdr->filetype == MH_DYLINKER) {
    return hdr;
   }
  }
  address += size;
 }
}
```

Radar-Id: rdar://problem/86773501

Differential Revision: https://reviews.llvm.org/D116240
2022-01-07 12:28:38 -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
Qiu Chaofan c2cc70e4f5 [NFC] Fix endif comments to match with include guard 2022-01-07 15:52:59 +08:00
Andrew Browne 7607ddd981 [NFC][DFSan] Cleanup code to use align functions.
Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D116761
2022-01-06 14:42:38 -08:00
Andrew Browne 32167bfe64 [DFSan] Refactor dfsan_mem_shadow_transfer.
Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D116704
2022-01-06 09:33:19 -08:00
Vitaly Buka 6396a44361 Revert "SIGSEGV in Sanitizer INTERCEPTOR of strstr function."
Breaks Asan on Fuchsia's and ubsan with gcc.

This reverts commit 685c94c6cb.
2022-01-05 21:28:01 -08:00
Petr Hosek 9eeb2c98f4 [msan] Check for AVX regs using offset
glibc versions < 2.26 use different names for the fields.
However the layout is unchanged, so using the offset should be a
portable way to address this issue across platforms.

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

Patch By: paulkirth

Differential Revision: https://reviews.llvm.org/D116695
2022-01-05 19:24:00 -08:00
Andrew Browne 4e173585f6 [DFSan] Add option for conditional callbacks.
This allows DFSan to find tainted values used to control program behavior.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D116207
2022-01-05 15:07:09 -08:00
Petr Hosek 96e36048fd [CMake] Move the AIX archiver settings to a module
This allows their reuse across projects. The name of the module
is intentionally generic because we would like to move more platform
checks there.

Differential Revision: https://reviews.llvm.org/D115276
2022-01-05 11:46:30 -08:00
Nico Weber 085f078307 Revert "Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`.""
This reverts commit 859ebca744.
The change contained many unrelated changes and e.g. restored
unit test failes for the old lld port.
2022-01-05 13:10:25 -05:00
David Salinas 859ebca744 Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`."
This reverts commit 640beb38e7.

That commit caused performance degradtion in Quicksilver test QS:sGPU and a functional test failure in (rocPRIM rocprim.device_segmented_radix_sort).
Reverting until we have a better solution to s_cselect_b64 codegen cleanup

Change-Id: Ibf8e397df94001f248fba609f072088a46abae08

Reviewed By: kzhuravl

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

Change-Id: Id169459ce4dfffa857d5645a0af50b0063ce1105
2022-01-05 17:57:32 +00:00
Kirill Stoimenov 027ffb173a [ASan] Moved optimized callbacks into a separate library.
This will allow linking in the callbacks directly instead of using PLT.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116182
2022-01-05 17:26:44 +00:00
Dmitry Vyukov 38f69eb77e msan: mark test as x86-specific
Differential Revision: https://reviews.llvm.org/D116653
2022-01-05 13:41:12 +01:00
Dmitry Vyukov 395f737c33 msan: check that ucontext_t is initialized on signal return
A signal handler can alter ucontext_t to affect execution after
the signal returns. Check that the contents are initialized.
Restoring unitialized values in registers can't be good.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116209
2022-01-05 13:20:50 +01:00
Dmitry Vyukov 1298273e82 msan: account for AVX state when unpoison ucontext_t
ucontext_t can be larger than its static size if it contains
AVX state and YMM/ZMM registers.
Currently a signal handler that tries to access that state
can produce false positives with random origins on stack.
Account for the additional ucontext_t state.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116208
2022-01-05 13:20:40 +01:00
Bharadwaj, Ritanya B 685c94c6cb SIGSEGV in Sanitizer INTERCEPTOR of strstr function.
This is a segmentation fault in INTERCEPTOR function on a special edge
case of strstr libc call. When 'Haystack'(main string to be examined) is
NULL and 'needle'(sub-string to be searched in 'Haystack') is an empty
string then it hits a SEGV while using sanitizers and as a 'string not
found' case otherwise.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D115919
2022-01-05 00:11:59 -08:00
Florian Mayer 4ecfa0a0c5 [sanitizers] Fix integer underflow when parsing ELF.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116639
2022-01-04 21:47:02 -08:00
John Ericson 949bbd0a68 [CMake] Use `LLVM_COMMON_CMAKE_UTILS` in runtimes just for clarity
In D116472 we created conditionally defined variables for the tools to
unbreak the legacy build where they are in `llvm/tools`.

The runtimes are not tools, so that flexibility doesn't matter. Still,
it might be nice to define (unconditionally) and use the variable for
the runtimes simply to make the code a bit clearer and document what is
going on.

Also, consistently put project dirs at the beginning, not end of `CMAKE_MODULE_PATH`. This ensures they will properly shadow similarly named stuff that happens to be later on the path.

Reviewed By: mstorsjo, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D116477
2022-01-03 20:55:44 +00:00
Vitaly Buka c36081fe49
[NFC][sanitizer] Allow madvise in symbolizer 2022-01-03 00:34:20 -08:00
Alexandre Ganea 7cd109b92c [asan] Additionnal prologue decoding for WinSDK 10.0.22000
Fixes interception of atoi() entry point.
2021-12-30 20:11:45 -05:00
John Ericson bde561c481 [compiler-rt][cmake] Factor out extend_install_path function
It is likely to become used again, if other projects want their own per-project
install directory variables. `install` is removed from the name since it is not inherently about installing.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D115746
2021-12-30 06:19:30 +00:00
Ellis Hoag 18ffb5dc25 [InstrProf] Prevent duplicate functions in correlated data
When using debug info for profile correlation, avoid adding duplicate
functions in the synthetic Data section.

Before this patch, n duplicate function entries in the Data section would
cause counter values to be a factor of n larger. I built instrumented
clang with and without debug info correlation and got these summaries.

```
# With Debug Info Correlate
$ llvm-profdata show default.profdata
Instrumentation level: IR  entry_first = 0
Total functions: 182530
Maximum function count: 52034
Maximum internal block count: 5763

# Without
$ llvm-profdata show default.profdata
Instrumentation level: IR  entry_first = 0
Total functions: 183212
Maximum function count: 52034
Maximum internal block count: 5766
```

The slight difference in counts seem to be mostly from FileSystem and
Map functions and the difference in the number of instrumented functions
seems to come from missing debug info like destructors without source.

Reviewed By: kyulee

Differential Revision: https://reviews.llvm.org/D116051
2021-12-28 14:20:59 -08:00
Gulfem Savrun Yeniceri f261e258ec [profile] Fix writing binary id into profiles
This patch adds support to read all the PT_NOTE segments in the
executable to find the binary ids. Previously, it was only reading
the first PT_NOTE segment, and this was missing the cases where
binary id is in the following segments. As a result, binary-id.c
and binary-id-padding.c test were failing in the following cases:
1) sanitizer-x86_64-linux bot
   https://lab.llvm.org/staging/#/builders/97
2) OpenSuse Tumbleweed
   https://github.com/llvm/llvm-project/issues/52695

Differential Revision: https://reviews.llvm.org/D115830
2021-12-27 19:20:19 +00:00
Krasimir Georgiev 969a51ff36 Revert "[ASan] Moved optimized callbacks into a separate library."
We need some internal updates for this, shared directly with the author.

This reverts commit 71b3bfde9c.
2021-12-24 12:01:36 +01:00
Kirill Stoimenov 71b3bfde9c [ASan] Moved optimized callbacks into a separate library.
This will allow linking in the callbacks directly instead of using PLT.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116182
2021-12-24 00:40:44 +00:00
Vitaly Buka 7cd7b4d2f8 [sanitizer] Add common "demangle" flag
Reviewed By: browneee

Differential Revision: https://reviews.llvm.org/D116202
2021-12-23 14:36:39 -08:00
Vitaly Buka f103ee2e9e [sanitizer] Move internal_symbolizer "inline" option
This option is per process anyway. I'd like to add more options, but
having them as parameters of __sanitizer_symbolize_code looks
inconvenient.

Reviewed By: browneee

Differential Revision: https://reviews.llvm.org/D116201
2021-12-23 11:28:03 -08:00
Vitaly Buka a7ebf2010e [NFC][sanitizer] Increase kArgVMax to 16
D116202 uses all availible slots.
2021-12-23 11:11:47 -08:00
Vitaly Buka 9fe0d67c9a [sanitizer] Check kArgVMax in SymbolizerProcess::GetArgV 2021-12-23 11:05:37 -08:00