Commit Graph

16033 Commits

Author SHA1 Message Date
Michał Górny ea953b9d9a [compiler-rt] [test] Handle missing ld.gold gracefully
Fix the is_binutils_lto_supported() function to handle missing
executables gracefully.  Currently, the function does not catch
exceptions from subprocess.Popen() and therefore causes lit to crash
if config.gold_executable does not specify a valid executable:

```
lit: /usr/lib/python3.11/site-packages/lit/TestingConfig.py:136: fatal: unable to parse config file '/tmp/portage/sys-libs/compiler-rt-
15.0.0/work/compiler-rt/test/lit.common.cfg.py', traceback: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/lit/TestingConfig.py", line 125, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py", line 561, in <module>
    if is_binutils_lto_supported():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py", line 543, in is_binutils_lto_supported
    ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1022, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1899, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'GOLD_EXECUTABLE-NOTFOUND'
```

Differential Revision: https://reviews.llvm.org/D133358
2022-09-07 07:14:31 +02:00
Florian Mayer 4f5147a7cf [HWASan] Show memory rather than tag addresses in tag dump
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D133380
2022-09-06 16:54:34 -07:00
Vitaly Buka 2eda7c5b38 [test][hwasan] Update test for D132622 2022-09-06 15:54:04 -07:00
Florian Mayer 9006b082a5 [HWASan] rename left/right to before/after.
left/right is a weird way to refer to address ordering.

Reviewed By: eugenis, vitalybuka

Differential Revision: https://reviews.llvm.org/D132622
2022-09-06 13:52:28 -07:00
Florian Mayer a51d19636c [ASan] Fix libfuzzer test 2022-09-06 13:37:35 -07:00
Florian Mayer be366041fa [ASan] rename left/right to before/after.
left/right is a weird way to refer to address ordering.

Reviewed By: eugenis, MaskRay

Differential Revision: https://reviews.llvm.org/D132611
2022-09-06 13:25:15 -07:00
Vitaly Buka b4257d3bf5 [tsan] Replace mem intrinsics with calls to interceptors
After https://reviews.llvm.org/rG463aa814182a23 tsan replaces llvm
intrinsics with calls to glibc functions. However this approach is
fragile, as slight changes in pipeline can return llvm intrinsics back.
In particular InstCombine can do that.

Msan/Asan already declare own version of these memory
functions for the similar purpose.

KCSAN, or anything that uses something else than compiler-rt, needs to
implement this callbacks.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D133268
2022-09-06 13:09:31 -07:00
Vitaly Buka 4a0b18c2cd [tsan][go] Fix buildgo.sh when GOAMD64 undefined 2022-09-06 13:02:11 -07:00
Vitaly Buka c51a12d598 Revert "[tsan] Replace mem intrinsics with calls to interceptors"
Breaks
http://45.33.8.238/macm1/43944/step_4.txt
https://lab.llvm.org/buildbot/#/builders/70/builds/26926

This reverts commit 77654a65a3.
2022-09-06 09:47:33 -07:00
Vitaly Buka 77654a65a3 [tsan] Replace mem intrinsics with calls to interceptors
After https://reviews.llvm.org/rG463aa814182a23 tsan replaces llvm
intrinsics with calls to glibc functions. However this approach is
fragile, as slight changes in pipeline can return llvm intrinsics back.
In particular InstCombine can do that.

Msan/Asan already declare own version of these memory
functions for the similar purpose.

KCSAN, or anything that uses something else than compiler-rt, needs to
implement this callbacks.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D133268
2022-09-06 08:25:32 -07:00
Igor Kudrin 84c4efbc6d [ubsan-minimal] Report the address of an error
This implements a FIXME in the runtime library and adds printing the
address at the end of the message as "by 0x123abc". The buffer for the
message is allocated on the stack in a handler, so the stack memory
consumption is slightly increased. No additional external dependencies
are added.

Differential revision: https://reviews.llvm.org/D131914
2022-09-05 14:18:25 +04:00
Krzysztof Parzyszek 98c2754abd [Libfuzzer] Include signal.h for SIGINT
Or else compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp fails to compile
on FreeBSD.
2022-09-04 11:31:15 -05:00
Lang Hames 1169586dcd [ORC-RT] Refactor ORC runtime CMake for future test tool(s).
We want to move functionality from the LLVM ORCTargetProcess library into the
ORC runtime, and this will mean implementing remote-executor testing tools
(like llvm-jitlink-executor and lli-child-target) in the ORC runtime.

This patch refactors the ORC runtime build system to introduce an
add_orc_tool function that can be used to add new test tools. The code is
modeled on existing functions for adding unit tests.

A placeholder orc-rt-executor tool and test are added to verify that the
config changes behave as expected.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D133084
2022-09-02 20:59:57 -07:00
Andrew Browne 64529eb291 [DFSan] Increase size of buffer to fix possibly-flakey test.
Observed a test failure where "Returned length: 3054".

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D133227
2022-09-02 17:52:12 -07:00
Leonard Grey f458d9f6f8 [lsan][darwin] Unmask camouflaged class_rw_t pointers
Detailed motivation here: https://docs.google.com/document/d/1xUNo5ovPKJMYxitiHUQVRxGI3iUmspI51Jm4w8puMwo

check-asan (with LSAN enabled) and check-lsan are currently broken on recent macOS versions, due to pervasive false positives. Whenever the Objective-C runtime realizes a class, it allocates data for it, then stores that data with flags in the low bits. This means LSAN can not recognize it as a pointer while scanning.

This change checks every potential pointer on Apple platforms, and if the high bit is set, attempts to extract a pointer by masking out the high bit and flags. This is ugly, but it's also the best approach I could think of (see doc above); very open to other suggestions.

Differential Revision: https://reviews.llvm.org/D133126
2022-09-02 11:25:22 -04:00
Lang Hames acce424111 [ORC-RT] Fix typo.
Removes the stray '$' that slipped in to c1c585a065.
2022-09-01 23:16:45 -07:00
Lang Hames c1c585a065 [ORC-RT] Don't unconditionally add dependence on llvm-jitlink.
Commit 4adc5bead4 moved a dependence on llvm-jitlink from
SANITIZER_COMMON_LIT_TEST_DEPS to ORC_TEST_DEPS, but in doing so it moved it
out from under a 'NOT COMPILER_RT_STANDALONE_BUILD ...' conditional. This led
to failures on standalone builds.

This commit adds the conditional to the ORC_TEST_DEPS assignment to work
around the issue while we look a longer term fix.

rdar://99453446
2022-09-01 22:53:30 -07:00
Lang Hames 6ca9f42189 [ORC][ORC-RT] Consistently use pointed-to type as template arg to wrap/unwrap.
Saves wrap/unwrap implementers from having to use std::remove_pointer_t to get
at the pointed-to type.
2022-09-01 20:54:24 -07:00
Vitaly Buka ad2b356f85 [msan] Use no-origin functions when possible
Saves 1.8% of .text size on CTMark

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D133077
2022-09-01 19:18:38 -07:00
Kevin Athey 0b509f2d1a [MSAN] removing redundant tests and parameters (NFC)
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D117622
2022-09-01 14:03:55 -07:00
Vitaly Buka 960e7a5513 [msan] Use Debug Info to point to affected fields
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D132909
2022-08-31 13:12:17 -07:00
Vitaly Buka c059ede28e [msan] Add more specific messages for use-after-destroy
Reviewed By: kda, kstoimenov

Differential Revision: https://reviews.llvm.org/D132907
2022-08-30 19:52:32 -07:00
Lang Hames 4adc5bead4 [ORC-RT] Make llvm-jitlink an ORC-RT specific dependence.
The llvm-jitlink tool is not needed by other sanitizer tests.
2022-08-30 17:19:54 -07:00
Gulfem Savrun Yeniceri 999886325e [profile] Create only prof header when no counters
When we use selective instrumentation and instrument a file
that is not in the selected files list provided via -fprofile-list,
we generate an empty raw profile. This leads to empty_raw_profile
error when we try to read that profile. This patch fixes the issue by
generating a raw profile that contains only a profile header when
there are no counters and profile data.

A small reproducer for the above issue:
echo "src:other.cc" > code.list
clang++ -O2 -fprofile-instr-generate -fcoverage-mapping
-fprofile-list=code.list code.cc -o code
./code
llvm-profdata show default.profraw

Differential Revision: https://reviews.llvm.org/D132094
2022-08-30 19:50:41 +00:00
Lang Hames 6d71c4e86b [ORC-RT] unit tests do not need access to LLVM headers.
Also delete trailing whitespace in lib/orc/CMakeLists.txt
2022-08-29 14:45:02 -07:00
Hans Wennborg 54e17931a6 Mark compiler-rt/test/profile/instrprof-merging.cpp unsupported on Windows
It is not reliable. See #57430.
2022-08-29 21:36:22 +02:00
Vitaly Buka 64dbcca6cf [test][msan] Add debug info use-after-dtor tests 2022-08-28 23:05:23 -07:00
Alexey Baturo fba042dabb [RISC-V][HWASAN] Save sp address at the start of tag mismatch routine
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131574
2022-08-28 21:12:37 +03:00
Alexey Baturo 38b04fd9c0 [RISC-V][HWASAN] Add runtime support for HWASAN for RISC-V
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131342
2022-08-28 20:43:31 +03:00
Alexey Baturo f8b71a307e [RISC-V][HWASAN] Add tag mismatch routines for HWASAN required for RISC-V
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D131341
2022-08-28 19:42:08 +03:00
Akira Hatanaka f051c1ded4 [compiler-rt][builtins] Pass -Werror to check_cxx_compiler_flag
This is needed to avoid passing flags that are supported by the compiler
but cause warnings to be emitted.
2022-08-27 13:39:28 -07:00
Rainer Orth a31426dc87 [asan][test] Fix typo in Unit/lit.site.cfg.py.in
I noticed that `test/asan/Unit/lit.site.cfg.py.in` contains two typos,
using the FreeBSD forms of the `LD_*LIBRARY_PATH*` variables on Solaris.

Tested on `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D132736
2022-08-27 07:50:18 +02:00
Lang Hames 16d538c5ef [ORC-RT] Remove __orc_rt::apply_tuple.
This utility was a substitute for std::apply, which is now available.
2022-08-26 17:06:56 -07:00
Julian Lettner 3d928e1d28 [TSan] Fix pointer/type-mismatch bug in test that has turned into a compile error
Fixes this test compile error:
```
<path>/compiler-rt/test/tsan/debug_alloc_stack.cpp:54:7: error: no matching function for call to '__tsan_get_alloc_stack'
      __tsan_get_alloc_stack(mem, trace, num_frames, &thread_id, &thread_os_id);
      ^~~~~~~~~~~~~~~~~~~~~~
<path>/compiler-rt/test/tsan/debug_alloc_stack.cpp:17:16: note: candidate function not viable: no known conversion from 'uint64_t **' (aka 'unsigned long long **') to 'uint64_t *' (aka 'unsigned long long *') for 5th argument; remove &
extern "C" int __tsan_get_alloc_stack(void *addr, void **trace, size_t size,
               ^
<path>/compiler-rt/test/tsan/debug_alloc_stack.cpp:61:46: warning: format specifies type 'unsigned long long' but the argument has type 'uint64_t *' (aka 'unsigned long long *') [-Wformat]
  fprintf(stderr, "thread os id = 0x%llx\n", thread_os_id);
                                    ~~~~     ^~~~~~~~~~~~
1 warning and 1 error generated.
```
2022-08-26 16:29:30 -07:00
Lang Hames ac0c8cb3ff [ORC-RT] Add "wrap" and "unwrap" steps to __orc_rt::ExecutorAddr toPtr/fromPtr.
The wrap/unwrap operations are applied to pointers after/before conversion to/from
raw addresses. They can be used to tag, untag, sign, or strip signing from
pointers. They currently default to 'rawPtr' (identity) on all platforms, but it
is expected that the default will be set based on the host architecture, e.g.
they would default to signing/stripping for arm64e.

This is the ORC runtime counterpart to f14cb494a34:
2022-08-26 15:58:10 -07:00
Lang Hames faabefe3c8 [ORC-RT] Add a std::identity substitute.
The __orc_rt::identity utility is intended to serve as a substitute for
c++20's std::identity until we can use the latter (when LLVM moves to c++20).
2022-08-26 15:58:10 -07:00
Julian Lettner af64a9248f [Tests][TSan] Remove bash-ism `|&`, which is unsupported on other shells 2022-08-26 14:38:06 -07:00
Akira Hatanaka 2e9df86046 [compiler-rt][builtins] Add compiler flags to catch potential errors
that can lead to security vulnerabilities

Also, fix a few places that were causing -Wshadow and
-Wformat-nonliteral warnings to be emitted.

This reapplies the patch that was reverted in caaafe4ae2 because it
broke Fuchsia builders.

I reverted the changes I made to InstrProfData.inc and instead renamed
the variables in InstrProfilingWriter.c. Also fixed a bug in function
add_security_warnings that was causing it to pass -Wformat-nonliteral
when the compiler doesn't support it.
2022-08-26 08:35:19 -07:00
Alexander Potapenko 5d82819583 [compiler-rt][hwasan] Support for Intel LAM v6 API
Version 6 of Intel LAM kernel patches
(https://lore.kernel.org/all/20220815041803.17954-1-kirill.shutemov@linux.intel.com/)
introduces arch_prctl(ARCH_GET_MAX_TAG_BITS), which (unlike
ARCH_GET_UNTAG_MASK) can be used to determine if the kernel really
supports pointer tagging. arch_prctl(ARCH_GET_UNTAG_MASK) will be used to
verify that HWASan can place tags in the given bit range.

Depends on D132545

Differential Revision: https://reviews.llvm.org/D132546
2022-08-26 10:21:18 +02:00
Akira Hatanaka caaafe4ae2 [compiler-rt][builtins] Revert all the recent changes I made for adding
security-related compiler flags

The changes broke Fuchsia builders.
2022-08-25 13:37:36 -07:00
Akira Hatanaka df75c0f56e [compiler-rt][builtins] Check whether the flags are usable before adding
them to the compiler command line

This is another attempt to fix the broken window bot.
2022-08-25 12:51:09 -07:00
Akira Hatanaka 387a05dbfa [compiler-rt][builtins] Check whether -Wformat-security is usable before
adding it to the compiler command line

This is an attempt to fix the window bot broken by
e1dcd4ba44
2022-08-25 11:45:19 -07:00
Alexander Potapenko 811f958eef [compiler-rt][hwasan] Factor out CanUseTaggingAbi() and EnableTaggingAbi()
Simplify InitializeOsSupport() by separating code for detecting and
enabling the tagged address ABI.

Also drop the unnecessary errno checks (regardless of errno value, we
cannot assume that tagging works if the system call failed) and ensure
prctl(PR_SET_TAGGED_ADDR_CTRL) is only called on Android, not on x86
(where arch_prctl(ARCH_ENABLE_TAGGED_ADDR, kTagBits) is used).

Depends on D132544

Differential Revision: https://reviews.llvm.org/D132545
2022-08-25 10:43:27 +02:00
Alexander Potapenko ebad19fedc [compiler-rt][hwasan] Introduce MaybeDieIfNoTaggingAbi()
Use a helper function to print an error message and die in the case
flags()->fail_without_syscall_abi is set.

Because x86 doesn't have `sysctl abi.tagged_addr_disabled`, do not
mention it in the error message for non-Android runtime.

Depends on D132543

Differential Revision: https://reviews.llvm.org/D132544
2022-08-25 10:32:01 +02:00
Alexander Potapenko c747451dc0 [compiler-rt][hwasan] Massage prctl/arch_prctl API constants.
Move the definitions outside InitializeOsSupport(). Also remove the
undefs, as these constants won't be visible outside the .cpp file anyway.

Differential Revision: https://reviews.llvm.org/D132543
2022-08-25 10:09:29 +02:00
Akira Hatanaka e1dcd4ba44 [compiler-rt][builtins] Add compiler flags to catch potential errors
that can lead to security vulnerabilities

Also, fix a few places that were causing -Wshadow and
-Wformat-nonliteral warnings to be emitted.

This reapplies the patch that was reverted in 0d66dc57e8 because it
broke a few bots.

I made changes so that cmake checks whether some of the flags are
supported by the compiler that is used before adding them to the list.
Also, I moved function add_security_warnings to CompilerRTUtils.cmake so
that it is defined before it's used.

Differential Revision: https://reviews.llvm.org/D131714
2022-08-24 15:52:31 -07:00
Keith Randall f202662ec3 tsan: add ability to compile for different Go subarch values.
Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D131927
2022-08-24 07:11:13 -04:00
Teresa Johnson d10c1b88f0 [memprof] Correct max size and access count computations
The existing code resulted in the max size and access counts being equal
to the min. Compute the max instead (max lifetime was already correct).

Differential Revision: https://reviews.llvm.org/D132515
2022-08-23 16:53:46 -07:00
Vitaly Buka 89476dbca1 [symbolizer] Fix build after 342e0eb
342e0eb reverted LLVM_ENABLE_RUNTIMES incompletly and missed /runtimes
part. This target has no issues with LLVM_ENABLE_RUNTIMES, so we can
keep it.
2022-08-23 14:51:39 -07:00
Vitaly Buka 11633314d8 [symbolizer] Remove check if it's monorepo 2022-08-23 14:49:05 -07:00