aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/include
AgeCommit message (Collapse)AuthorFilesLines
2021-01-05[Coverage] Add support for Branch Coverage in LLVM Source-Based Code CoverageAlan Phipps1-2/+2
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how many times individual branch-generating conditions are taken (evaluate to TRUE) and not taken (evaluate to FALSE). Individual conditions may comprise larger boolean expressions using boolean logical operators. This functionality is very similar to what is supported by GCOV except that it is very closely anchored to the ASTs. Differential Revision: https://reviews.llvm.org/D84467
2020-12-30[compiler-rt] FuzzedDataProvider: Add PickValueInArray for std::arrayMax Moroz1-0/+9
This makes `PickValueInArray` work for `std::array<T, s>` (C++11). I've also tested the C++17 `std::array` (with compiler-deduced template parameters) ``` Author: MarcoFalke <falke.marco@gmail.com> ``` Reviewed By: Dor1s Differential Revision: https://reviews.llvm.org/D93412
2020-11-20[hwasan] Implement error report callback.Evgenii Stepanov1-0/+3
Similar to __asan_set_error_report_callback, pass the entire report to a user provided callback function. Differential Revision: https://reviews.llvm.org/D91825
2020-11-19[MemProf] Add interface to dump profileTeresa Johnson1-0/+5
Add an interface so that the profile can be dumped on demand. Differential Revision: https://reviews.llvm.org/D91768
2020-11-19[sanitizer_common] Add facility to get the full report pathTeresa Johnson1-0/+3
Add a new interface __sanitizer_get_report_path which will return the full path to the report file if __sanitizer_set_report_path was previously called (otherwise it returns null). This is useful in particular for memory profiling handlers to access the path which was specified at compile time (and passed down via __memprof_profile_filename), including the pid added to the path when the file is opened. There wasn't a test for __sanitizer_set_report_path, so I added one which additionally tests the new interface. Differential Revision: https://reviews.llvm.org/D91765
2020-10-26[MemProf] Decouple memprof build from COMPILER_RT_BUILD_SANITIZERSTeresa Johnson1-1/+7
The MemProf compiler-rt support relies on some of the support only built when COMPILER_RT_BUILD_SANITIZERS was enabled. This showed up in some initial bot failures, and I addressed those by making the memprof runtime build also conditional on COMPILER_RT_BUILD_SANITIZERS (3ed77ecd0a5d5e5c33770f0f9d3d75cf2f80c80b). However, this resulted in another inconsistency with how the tests were set up that was hit by Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1142191 Undo the original bot fix and address this with a more comprehensive fix that enables memprof to be built even when COMPILER_RT_BUILD_SANITIZERS is disabled, by also building the necessary pieces under COMPILER_RT_BUILD_MEMPROF. Tested by configuring with a similar command as to what was used in the failing Chromium configure. I reproduced the Chromium failure, as well as the original bot failure I tried to fix in 3ed77ecd0a5d5e5c33770f0f9d3d75cf2f80c80b, with that fix reverted. Confirmed it now works. Differential Revision: https://reviews.llvm.org/D90190
2020-10-16[MemProf] Memory profiling runtime supportTeresa Johnson2-0/+61
See RFC for background: http://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html Follow on companion to the clang/llvm instrumentation support in D85948 and committed earlier. This patch adds the compiler-rt runtime support for the memory profiling. Note that much of this support was cloned from asan (and then greatly simplified and renamed). For example the interactions with the sanitizer_common allocators, error handling, interception, etc. The bulk of the memory profiling specific code can be found in the MemInfoBlock, MemInfoBlockCache, and related classes defined and used in memprof_allocator.cpp. For now, the memory profile is dumped to text (stderr by default, but honors the sanitizer_common log_path flag). It is dumped in either a default verbose format, or an optional terse format. This patch also adds a set of tests for the core functionality. Differential Revision: https://reviews.llvm.org/D87120
2020-10-15[PGO] Remove the old memop value profiling buckets.Hiroshi Yamauchi1-17/+1
Following up D81682 and D83903, remove the code for the old value profiling buckets, which have been replaced with the new, extended buckets and disabled by default. Also syncing InstrProfData.inc between compiler-rt and llvm. Differential Revision: https://reviews.llvm.org/D88838
2020-09-10[compiler-rt] [netbsd] Regenerate syscall hooksKamil Rytarowski1-10/+203
Sync with NetBSD 9.99.72.
2020-08-27[MSAN] Add fiber switching APIsJustin Cady1-0/+3
Add functions exposed via the MSAN interface to enable MSAN within binaries that perform manual stack switching (e.g. through using fibers or coroutines). This functionality is analogous to the fiber APIs available for ASAN and TSAN. Fixes google/sanitizers#1232 Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D86471
2020-08-14[DFSan] Don't unmap during dfsan_flush().Matt Morehouse1-3/+5
Unmapping and remapping is dangerous since another thread could touch the shadow memory while it is unmapped. But there is really no need to unmap anyway, since mmap(MAP_FIXED) will happily clobber the existing mapping with zeroes. This is thread-safe since the mmap() is done under the same kernel lock as page faults are done. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D85947
2020-08-05[compiler-rt] Normalize some in/out doxygen parameter in interfacePierre Gousseau2-11/+11
headers. NFC. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D84945
2020-08-03[PGO] Extend the value profile buckets for mem op sizes.Hiroshi Yamauchi1-0/+125
Extend the memop value profile buckets to be more flexible (could accommodate a mix of individual values and ranges) and to cover more value ranges (from 11 to 22 buckets). Disabled behind a flag (to be enabled separately) and the existing code to be removed later. Differential Revision: https://reviews.llvm.org/D81682
2020-07-22Revert D81682 "[PGO] Extend the value profile buckets for mem op sizes."Fangrui Song1-125/+0
This reverts commit 4a539faf74b9b4c25ee3b880e4007564bd5139b0. There is a __llvm_profile_instrument_range related crash in PGO-instrumented clang: ``` (gdb) bt llvm::ConstantRange const&, llvm::APInt const&, unsigned int, bool) () llvm::ScalarEvolution::getRangeForAffineAR(llvm::SCEV const*, llvm::SCEV const*, llvm::SCEV const*, unsigned int) () ``` (The body of __llvm_profile_instrument_range is inlined, so we can only find__llvm_profile_instrument_target in the trace) ``` 23│ 0x000055555dba0961 <+65>: nopw %cs:0x0(%rax,%rax,1) 24│ 0x000055555dba096b <+75>: nopl 0x0(%rax,%rax,1) 25│ 0x000055555dba0970 <+80>: mov %rsi,%rbx 26│ 0x000055555dba0973 <+83>: mov 0x8(%rsi),%rsi # %rsi=-1 -> SIGSEGV 27│ 0x000055555dba0977 <+87>: cmp %r15,(%rbx) 28│ 0x000055555dba097a <+90>: je 0x55555dba0a76 <__llvm_profile_instrument_target+342> ```
2020-07-15[PGO] Extend the value profile buckets for mem op sizes.Hiroshi Yamauchi1-0/+125
Extend the memop value profile buckets to be more flexible (could accommodate a mix of individual values and ranges) and to cover more value ranges (from 11 to 22 buckets). Disabled behind a flag (to be enabled separately) and the existing code to be removed later.
2020-06-25Revert "[PGO] Extend the value profile buckets for mem op sizes."Hiroshi Yamauchi1-82/+0
This reverts commit 63a89693f09f6b24ce4f2350d828150bd9c4f3e8. Due to a build failure like http://lab.llvm.org:8011/builders/sanitizer-windows/builds/65386/steps/annotate/logs/stdio
2020-06-25[PGO] Extend the value profile buckets for mem op sizes.Hiroshi Yamauchi1-0/+82
Extend the memop value profile buckets to be more flexible (could accommodate a mix of individual values and ranges) and to cover more value ranges (from 11 to 22 buckets). Disabled behind a flag (to be enabled separately) and the existing code to be removed later. Differential Revision: https://reviews.llvm.org/D81682
2020-06-03[profile] Sync InstrProfData.inc with llvm.Hiroshi Yamauchi1-1/+1
Reviewers: davidxl Subscribers: #sanitizers, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D81038
2020-03-25[compiler-rt] Mark FDP non-template methods inline to avoid ODR violations.Max Moroz1-8/+11
2020-03-25[compiler-rt] FuzzedDataProvider: make linter happy.Max Moroz1-2/+2
2020-03-24[compiler-rt] Refactor FuzzedDataProvider for better readability.Max Moroz1-258/+316
Summary: Separate class definition and actual methods implementation. The main goal is to keep the list of available methods in a concise readable form inside the class definition. Reviewers: hctim, metzman Subscribers: dberris, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D76651
2020-03-23[compiler-rt] Add ConsumeRandomLengthString() version without arguments.Max Moroz1-0/+5
Reviewers: hctim, metzman Subscribers: dberris, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D76448
2020-03-10tsan: tsan_interface.h: make constants staticDmitry Vyukov1-10/+10
Note that in C++ the static keyword is implicit for const objects. In C however it is not, and we get clashes at link time after including the header from more than one C file: lib.a(bar.o):(.rodata+0x0): multiple definition of `__tsan_mutex_linker_init' lib.a(foo.o):(.rodata+0x0): first defined here lib.a(bar.o):(.rodata+0xc): multiple definition of `__tsan_mutex_not_static' lib.a(foo.o):(.rodata+0xc): first defined here <snip> Indeed both foo.o and bar.o define the clashing symbols: $ nm foo.o <snip> 0000000000000000 R __tsan_mutex_linker_init 000000000000000c R __tsan_mutex_not_static <snip> Fix it by explicitly making the constants static. Reviewed-in: https://reviews.llvm.org/D75820 Author: cota (Emilio G. Cota)
2020-02-28Reland: [Coverage] Revise format to reduce binary sizeVedant Kumar1-9/+40
Try again with an up-to-date version of D69471 (99317124 was a stale revision). --- Revise the coverage mapping format to reduce binary size by: 1. Naming function records and marking them `linkonce_odr`, and 2. Compressing filenames. This shrinks the size of llc's coverage segment by 82% (334MB -> 62MB) and speeds up end-to-end single-threaded report generation by 10%. For reference the compressed name data in llc is 81MB (__llvm_prf_names). Rationale for changes to the format: - With the current format, most coverage function records are discarded. E.g., more than 97% of the records in llc are *duplicate* placeholders for functions visible-but-not-used in TUs. Placeholders *are* used to show under-covered functions, but duplicate placeholders waste space. - We reached general consensus about giving (1) a try at the 2017 code coverage BoF [1]. The thinking was that using `linkonce_odr` to merge duplicates is simpler than alternatives like teaching build systems about a coverage-aware database/module/etc on the side. - Revising the format is expensive due to the backwards compatibility requirement, so we might as well compress filenames while we're at it. This shrinks the encoded filenames in llc by 86% (12MB -> 1.6MB). See CoverageMappingFormat.rst for the details on what exactly has changed. Fixes PR34533 [2], hopefully. [1] http://lists.llvm.org/pipermail/llvm-dev/2017-October/118428.html [2] https://bugs.llvm.org/show_bug.cgi?id=34533 Differential Revision: https://reviews.llvm.org/D69471
2020-02-28Revert "[Coverage] Revise format to reduce binary size"Vedant Kumar1-40/+9
This reverts commit 99317124e1c772e9a9de41a0cd56e1db049b4ea4. This is still busted on Windows: http://lab.llvm.org:8011/builders/lld-x86_64-win7/builds/40873 The llvm-cov tests report 'error: Could not load coverage information'.
2020-02-28[Coverage] Revise format to reduce binary sizeVedant Kumar1-9/+40
Revise the coverage mapping format to reduce binary size by: 1. Naming function records and marking them `linkonce_odr`, and 2. Compressing filenames. This shrinks the size of llc's coverage segment by 82% (334MB -> 62MB) and speeds up end-to-end single-threaded report generation by 10%. For reference the compressed name data in llc is 81MB (__llvm_prf_names). Rationale for changes to the format: - With the current format, most coverage function records are discarded. E.g., more than 97% of the records in llc are *duplicate* placeholders for functions visible-but-not-used in TUs. Placeholders *are* used to show under-covered functions, but duplicate placeholders waste space. - We reached general consensus about giving (1) a try at the 2017 code coverage BoF [1]. The thinking was that using `linkonce_odr` to merge duplicates is simpler than alternatives like teaching build systems about a coverage-aware database/module/etc on the side. - Revising the format is expensive due to the backwards compatibility requirement, so we might as well compress filenames while we're at it. This shrinks the encoded filenames in llc by 86% (12MB -> 1.6MB). See CoverageMappingFormat.rst for the details on what exactly has changed. Fixes PR34533 [2], hopefully. [1] http://lists.llvm.org/pipermail/llvm-dev/2017-October/118428.html [2] https://bugs.llvm.org/show_bug.cgi?id=34533 Differential Revision: https://reviews.llvm.org/D69471
2020-02-25[compiler-rt] Fix a typo in a comment in FuzzedDataProvider.h.Max Moroz1-1/+1
2020-02-11[compiler-rt] FuzzedDataProvider: add ConsumeData and method.Max Moroz1-4/+20
Reviewers: metzman Subscribers: dberris, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D74359
2020-02-04[sanitizer] Add missing declarations for sigaltstack syscall wrappers.Evgenii Stepanov1-0/+2
Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D73987
2020-02-03[compiler-rt] implement sigaltstack interceptionEvgenii Stepanov1-2/+4
Summary: An implementation for `sigaltstack` to make its side effect be visible to MSAN. ``` ninja check-msan ``` Reviewers: vitalybuka, eugenis Reviewed By: eugenis Subscribers: dberris, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D73816 Patch by Igor Sugak.
2019-12-24[compiler-rt] Adapt for ptrace(2) changes in NetBSD-9.99.30Kamil Rytarowski1-1/+1
Enable compat support for now legacy PT_LWPINFO. Support PT_LWPSTATUS and PT_LWPNEXT.
2019-12-04[compiler-rt] FuzzedDataProvider: do not call memcpy on empty vector.Max Moroz1-0/+6
Summary: Some versions of memcpy mark pointer arguments as __nonnull, that triggers UBSan errors even when the length passed is 0. Reviewers: manojgupta, metzman Subscribers: dberris, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71031 [compiler-rt] FDP: assert that num_bytes_to_consume == 0 when size == 0.
2019-12-04Revert "[Coverage] Revise format to reduce binary size"Vedant Kumar1-40/+9
This reverts commit e18531595bba495946aa52c0a16b9f9238cff8bc. On Windows, there is an error: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/54963/steps/stage%201%20check/logs/stdio error: C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\profile\Profile-x86_64\Output\instrprof-merging.cpp.tmp.v1.o: Failed to load coverage: Malformed coverage data
2019-12-04[Coverage] Revise format to reduce binary sizeVedant Kumar1-9/+40
Revise the coverage mapping format to reduce binary size by: 1. Naming function records and marking them `linkonce_odr`, and 2. Compressing filenames. This shrinks the size of llc's coverage segment by 82% (334MB -> 62MB) and speeds up end-to-end single-threaded report generation by 10%. For reference the compressed name data in llc is 81MB (__llvm_prf_names). Rationale for changes to the format: - With the current format, most coverage function records are discarded. E.g., more than 97% of the records in llc are *duplicate* placeholders for functions visible-but-not-used in TUs. Placeholders *are* used to show under-covered functions, but duplicate placeholders waste space. - We reached general consensus about giving (1) a try at the 2017 code coverage BoF [1]. The thinking was that using `linkonce_odr` to merge duplicates is simpler than alternatives like teaching build systems about a coverage-aware database/module/etc on the side. - Revising the format is expensive due to the backwards compatibility requirement, so we might as well compress filenames while we're at it. This shrinks the encoded filenames in llc by 86% (12MB -> 1.6MB). See CoverageMappingFormat.rst for the details on what exactly has changed. Fixes PR34533 [2], hopefully. [1] http://lists.llvm.org/pipermail/llvm-dev/2017-October/118428.html [2] https://bugs.llvm.org/show_bug.cgi?id=34533 Differential Revision: https://reviews.llvm.org/D69471
2019-11-22Reland "[CMake] Support installation of InstrProfData.inc"Petr Hosek2-1/+767
This header fragment is useful on its own for any consumer that wants to use custom instruction profile runtime with the LLVM instrumentation. The concrete use case is in Fuchsia's kernel where we want to use instruction profile instrumentation, but we cannot use the compiler-rt runtime because it's not designed for use in the kernel environment. This change allows installing this header as part of compiler-rt. Differential Revision: https://reviews.llvm.org/D64532
2019-11-22Revert "[CMake] Support installation of InstrProfData.inc"Petr Hosek2-767/+1
This reverts commit f11bc1776fd2815b60e0b1ed97be00b517348162 since it's failing to build on some bots.
2019-11-22[CMake] Support installation of InstrProfData.incPetr Hosek2-1/+767
This header fragment is useful on its own for any consumer that wants to use custom instruction profile runtime with the LLVM instrumentation. The concrete use case is in Fuchsia's kernel where we want to use instruction profile instrumentation, but we cannot use the compiler-rt runtime because it's not designed for use in the kernel environment. This change allows installing this header as part of compiler-rt. Differential Revision: https://reviews.llvm.org/D64532
2019-11-03[compiler-rt] Sync NetBSD syscall hooks with 9.99.17Kamil Rytarowski1-42/+123
Document the minimal version supported as 9.0 and add compat code for renamed syscalls after 9.0.
2019-10-31[asan] Provide an interface to update an allocation stack trace.Evgenii Stepanov1-0/+4
Summary: Sometimes an allocation stack trace is not very informative. Provide a way to replace it with a stack trace of the user's choice. Reviewers: pcc, kcc Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69208
2019-09-13[compiler-rt] Add ubsan interface header.Pierre Gousseau2-0/+33
This is to document __ubsan_default_options(). Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D67503 llvm-svn: 371822
2019-09-12[compiler-rt] Remove some cpplint filtersVitaly Buka1-2/+2
llvm-svn: 371704
2019-09-11[dfsan] Revert dfsan_set_label removalVitaly Buka1-0/+5
It's part of interface, maybe it is used in external code. llvm-svn: 371691
2019-09-11Remove NOLINTs from compiler-rtVitaly Buka2-9/+4
llvm-svn: 371687
2019-09-11Update compiler-rt cpplint.pyVitaly Buka1-1/+1
https://github.com/cpplint/cpplint/commit/adb3500107f409ac5491188ae652ac3f4d03d9d3 llvm-svn: 371675
2019-08-09[compiler-rt] FuzzedDataProvider: use C++ headers only instead of a C/C++ mix.Max Moroz1-4/+3
Reviewers: Dor1s Reviewed By: Dor1s Subscribers: dberris, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D66017 llvm-svn: 368448
2019-08-08[compiler-rt] Add ConsumeProbability and ConsumeFloatingPoint methods to FDP.Max Moroz2-6/+61
Summary: Also slightly cleaned up the comments and changed the header's extension back to `.h` as per comments on https://reviews.llvm.org/D65812. New methods added: * `ConsumeProbability` returns [0.0, 1.0] by consuming an unsigned integer value from the input data and dividing that value by the integer's max value. * `ConsumeFloatingPointInRange` returns a floating point value in the given range. Relies on `ConsumeProbability` method. This method does not have the limitation of `std::uniform_real_distribution` that requires the given range to be <= the floating point type's max. If the range is too large, this implementation will additionally call `ConsumeBool` to decide whether the result will be in the first or the second half of the range. * `ConsumeFloatingPoint` returns a floating point value in the range `[std::numeric_limits<T>::lowest(), std::numeric_limits<T>::min()]`. Tested on Linux, Mac, Windows. Reviewers: morehouse Reviewed By: morehouse Subscribers: kubamracek, mgorny, dberris, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D65905 llvm-svn: 368331
2019-08-06[compiler-rt] Rename FuzzedDataProvider.h to .hpp and other minor changes.Max Moroz2-2/+2
Summary: .hpp makes more sense for this header as it's C++ only, plus it contains the actual implementation. Reviewers: Dor1s Reviewed By: Dor1s Subscribers: kubamracek, dberris, mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D65812 llvm-svn: 368054
2019-08-05[compiler-rt] Move FDP to include/fuzzer/FuzzedDataProvider.h for easier use.Max Moroz2-0/+254
Summary: FuzzedDataProvider is a helper class for writing fuzz targets that fuzz multple inputs simultaneously. The header is supposed to be used for fuzzing engine agnostic fuzz targets (i.e. the same target can be used with libFuzzer, AFL, honggfuzz, and other engines). The common thing though is that fuzz targets are typically compiled with clang, as it provides all sanitizers as well as different coverage instrumentation modes. Therefore, making this FDP class a part of the compiler-rt installation package would make it easier to develop and distribute fuzz targets across different projects, build systems, etc. Some context also available in https://github.com/google/oss-fuzz/pull/2547. This CL does not delete the header from `lib/fuzzer/utils` directory in order to provide the downstream users some time for a smooth migration to the new header location. Reviewers: kcc, morehouse Reviewed By: morehouse Subscribers: lebedev.ri, kubamracek, dberris, mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D65661 llvm-svn: 367917
2019-06-13[dfsan] Introduce dfsan_flush().Kostya Serebryany1-0/+6
Summary: dfsan_flush() allows to restart tain tracking from scratch in the same process. The primary purpose right now is to allow more efficient data flow tracing for DFT fuzzing: https://github.com/google/oss-fuzz/issues/1632 Reviewers: pcc Reviewed By: pcc Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63037 llvm-svn: 363321
2019-06-11[compiler-rt] Update comments in asan header to doxygen format; NFC.Pierre Gousseau2-295/+609
Add description to undocumented functions. Improve spelling, grammar and formatting. Patch by: Craig Flores, Filipe Cabecinhas, Pierre Gousseau Reviewed By: Johannes Doerfert Differential Revision: https://reviews.llvm.org/D62245 llvm-svn: 363038