Commit Graph

15325 Commits

Author SHA1 Message Date
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