Commit Graph

491 Commits

Author SHA1 Message Date
Alexander Richardson
55b90b5140 [compiler-rt] Remove llvm_gtest dependency from unit tests
All these unit tests already include ${COMPILER_RT_GTEST_SOURCE} as an
input source file and the target llvm_gtest does not exist for
standalone builds. Currently the DEPS argument is ignored for standalone
builds so the missing target is not a problem, but as part of fixing a
build race for standalone builds I am planning to include those
dependencies in COMPILER_RT_TEST_STANDALONE_BUILD_LIBS configurations.

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/83649
2024-03-13 11:28:44 -07:00
David CARLIER
e371ada409 [compiler-rt] reimplements GetMemoryProfile for netbsd. (#84841)
The actual solution relies on the premise /proc/self/smaps existence.
instead relying on native api like freebsd.
fixing fuzzer build too.
2024-03-13 09:25:43 +00:00
David CARLIER
e932fe880b [compiler-rt][Fuzzer] fix windows typo (#84407) 2024-03-08 00:15:22 +00:00
David CARLIER
8bf8d36f8e [compiler-rt][fuzzer] Reland "SetThreadName windows implementation" (#83562)
Following-up on GH-76761.
2024-03-07 23:53:27 +00:00
David CARLIER
d1538c15f9 Revert fuzzer windows changes (#83551) 2024-03-01 10:32:10 +00:00
David CARLIER
062d78ef58 [compiler-rt][fuzzer] windows build unbreak proposal. (#83538)
shuffling the order of its includes.
2024-03-01 09:13:11 +00:00
David CARLIER
2cdf611c02 [compiler-rt][Fuzzer] SetThreadName windows implementation new try. (#76761)
SetThreadDescription symbol needs to be dynamically loaded before usage.
Then using a wide string buffer, since we re using a null terminated
string, we can use MultiByteToWideChar -1 as 4th argument to finally set
the thread name.

Previously `SetThreadDescription` was called directly causing crash.
It was reverted in dd3aa26fc8
2024-02-29 17:47:05 -08:00
James Robinson
7f3980a7b2 [Fuzzer] Use user signal to coordinate handler shutdown (#82067)
This updates the signal handle thread coordinating to use a user signal
bit on the SignalHandlerEvent to coordinate shutdown instead of closing
the event handle. Closing the event handle is racy as the handle may be
closed before the signal handler thread resolves the handle value in
_zx_object_wait_many() and we would like to make this an explicit error.
Using the user signal bit 1 instead and then closing the event object
after the signal handler thread is joined cannot race as the wait will
terminate whether the signal is raised before or after the wait begins.
2024-02-20 09:49:20 -08:00
Ryan Prichard
3747cde5e8 [Fuzzer] Enable custom libc++ for Android (#70407)
The Android LLVM build system builds the arm64 fuzzer lib without
HWASan, but then applications that enable HWASan can generated an object
file with a HWASan-ified version of some libc++ symbols (e.g.
`std::__1::piecewise_construct`). The linker can choose the HWASan-ified
definition, but then it cannot resolve the relocation from
libclang_rt.fuzzer-aarch64-android.a to this symbol because the high
bits of the address are unexpectedly set. This produces an error:

```
relocation R_AARCH64_ADR_PREL_PG_HI21 out of range
```

Fix this problem by linking a custom isolated libc++ into Android's
fuzzer library.

We need to pass through ANDROID_NATIVE_API_LEVEL so that the libc++ for
32-bit Android (API < 24) uses LLVM_FORCE_SMALLFILE_FOR_ANDROID.
2023-11-02 14:07:39 -07:00
Kazu Hirata
747e0d9f0a [compiler-rt] Use std::clamp (NFC) 2023-10-22 12:32:20 -07:00
Arseny Kapoulkine
bede46f57e [Fuzzer] Optimize UpdateFeatureFrequency (#65288)
Instead of a linear scan, use a bitset to track rarity of features. This
improves fuzzer throughput rather dramatically (close to 2x) in early
exploratory phases; in steady state this seems to improve fuzzing
throughput by ~15% according to perf.

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

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

Also remove 'u' from ar command to fix this warning: ar: `u' modifier
ignored since `D' is the default (see `U')
2023-09-07 16:38:28 -07:00
Vitaly Buka
dd3aa26fc8 Revert "[Fuzzer] SetThreadName implementation for Windows"
Fails with "The procedure entry point SetThreadDescription could not be located in the dynamic link library..."

This reverts commit cf76ddcbeb.
2023-08-28 12:27:00 -07:00
Vitaly Buka
151e33c768 [NFC][fuzzer] Cleanup SetThreadName after D156317 2023-08-28 10:59:39 -07:00
Vitaly Buka
45eb6026d9 [fuzzer] Try to fix windows build after D156317 2023-08-28 10:55:16 -07:00
Vitaly Buka
e0e8695a60 Revert "[fuzzer] Try to fix windows build after D156317"
Will not work, string::data() returns const char*;

This reverts commit d364597f8a.
2023-08-28 10:50:51 -07:00
Vitaly Buka
d364597f8a [fuzzer] Try to fix windows build after D156317 2023-08-28 10:47:38 -07:00
David CARLIER
cf76ddcbeb [Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revison: https://reviews.llvm.org/D156317
2023-08-28 13:14:47 +01:00
MarcoFalke
52526065bc [NFC][compiler-rt] Add missing space in libfuzzer -help docs 2023-07-28 09:59:32 +02:00
David Carlier
cb924ddca5 Revert "[Fuzzer] SetThreadName implementation for Windows"
This reverts commit 885275bff2.
2023-07-28 06:00:42 +01:00
David CARLIER
885275bff2 [Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156317
2023-07-27 18:10:17 -07:00
Vitaly Buka
f4aa7b5b8d Revert "[Fuzzer] SetThreadName implementation for Windows"
Breaks window bot.

This reverts commit e3f935c7f8.
2023-07-27 09:08:56 -07:00
David CARLIER
e3f935c7f8 [Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607.

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156317
2023-07-27 06:55:00 +01:00
David CARLIER
b2a253855f [Fuzzer] Assign names to workers
Allow to have a name for workers in case the fuzzed code is itself using threads.

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D155754
2023-07-26 05:49:35 +01:00
Youling Tang
9c2f792dce [fuzzer] Enable loongarch64
Enable fuzzer on loongarch64.

Reviewed By: SixWeining, xen0n, MaskRay

Differential Revision: https://reviews.llvm.org/D140601
2023-07-18 09:40:25 +08:00
Roland McGrath
42564f97e8 [fuzzer][fuchsia] Support RISC-V
Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D153082
2023-06-16 11:39:32 -07:00
Vitaly Buka
facf22b8b0 [fuzzer] Platfom specific version of PageSize 2023-05-25 21:00:14 -07:00
zhanglimin
baa1488c16 [fuzzer] Don't hard-code page size in FuzzerUtil.h
Don't hard code the page in FuzzerUtil.h, this breaks on
e.g. LoongArch which defaults to a 16KiB page size.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140607
2023-05-25 20:24:24 -07:00
Jason Molenda
cb9f2de2e8 Revert "[fuzzer] Don't hard-code page size in FuzzerUtil.h"
This reverts commit a2b677e815.

reverting

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

because <sys/auxv.h> and getauxval() are not available on macOS;
this change is breaking the mac CI bots.
2023-05-25 18:05:10 -07:00
zhanglimin
a2b677e815 [fuzzer] Don't hard-code page size in FuzzerUtil.h
Don't hard code the page in FuzzerUtil.h, this breaks on
e.g. LoongArch which defaults to a 16KiB page size.

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D140607
2023-05-25 16:35:08 -07:00
Tobias Hieta
f98ee40f4b [NFC][Py Reformat] Reformat python files in the rest of the dirs
This is an ongoing series of commits that are reformatting our
Python code. This catches the last of the python files to
reformat. Since they where so few I bunched them together.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, #libc, Mordante, sivachandra

Differential Revision: https://reviews.llvm.org/D150784
2023-05-25 11:17:05 +02:00
Wu, Yingcong
cdfcf1aa38 [libfuzzer] avoid unneccessary auto-copy
Avoid an unneccessary auto-copy

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D148902
2023-04-26 19:06:40 -07:00
Nico Weber
8a986abe98 [fuzzer] Fix -Wunreachable-code-aggressive warning in FuzzerDriver.cpp
Differential Revision: https://reviews.llvm.org/D148008
2023-04-11 20:31:08 -04:00
Martin Storsjö
f2c9d24e8c [compiler-rt] [test] [fuzzer] Don't pass msvc/clang-cl specific flags to mingw tools
This fixes building the tests so that the tests can start
executing (even if there still are lots of failures).

Differential Revision: https://reviews.llvm.org/D147648
2023-04-06 11:07:42 +03:00
Roy Sundahl
90b4d1bcb2 [fuzzer] Use puts() rather than printf() in CopyFileToErr()
CopyFileToErr() uses Printf("%s", ...) which fails with a negative size on
files >2Gb (Its path is through var-args wrappers to an unnecessary "%s"
expansion and subject to int overflows) Using puts() in place of printf()
bypasses this path and writes the string directly to stderr. This avoids the
present loss of data when a crashed worker has generated >2Gb of output.

rdar://99384640

Reviewed By: yln, rsundahl

Differential Revision: https://reviews.llvm.org/D146189
2023-03-28 14:19:35 -07:00
Wu, Yingcong
c2df1d8a6d [libfuzzer] add test of cov file-id in control file
There is test for ft file-id in control file, but no test for cov line.
Without the test, a invalid cov file-id would cause crash.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D145672
2023-03-22 22:55:48 -07:00
Matthew Voss
d02ff3d578 Revert "[fuzzer] Use puts() rather than printf() in CopyFileToErr()"
This reverts commit 03aa02adb0.

Reverting due to bot failures:
https://lab.llvm.org/buildbot/#/builders/247/builds/2653
2023-03-17 16:00:56 -07:00
Roy Sundahl
03aa02adb0 [fuzzer] Use puts() rather than printf() in CopyFileToErr()
CopyFileToErr() uses Printf("%s", ...) which fails with a negative size on
files >2Gb (Its path is through var-args wrappers to an unnecessary "%s"
expansion and subject to int overflows) Using puts() in place of printf()
bypasses this path and writes the string directly to stderr. This avoids the
present loss of data when a crashed worker has generated >2Gb of output.

rdar://99384640

Reviewed By: yln

Differential Revision: https://reviews.llvm.org/D146189
2023-03-17 09:08:40 -07:00
Jie Fu
0b327814d8 [libfuzzer] Fix build error due to out-of-line definition of 'Fuzzer' does not match any declaration in 'fuzzer::Fuzzer' (NFC)
/data/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:138:9: error: out-of-line definition of 'Fuzzer' does not match any declaration in 'fuzzer::Fuzzer'
Fuzzer::Fuzzer(UserCallback CB, InputCorpus &Corpus, MutationDispatcher &MD,
        ^~~~~~
/data/llvm-project/compiler-rt/lib/fuzzer/FuzzerInternal.h:35:10: note: type of 4th parameter of member declaration does not match definition ('fuzzer::FuzzingOptions &' vs 'const fuzzer::FuzzingOptions &')
         FuzzingOptions &Options);
         ^
1 error generated.
2023-03-10 14:52:28 +08:00
Wu, Yingcong
513d9b9f3d [libfuzzer] avoid unneccessary copy
Avoid some unneccessary copy

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D145758
2023-03-09 22:11:48 -08:00
Vitaly Buka
e09b3be411 [fuzzer] Make sure we never delete Fuzzer 2023-03-07 22:26:07 -08:00
Wu, Yingcong
67f5b05cdc Add test for Flags.data_flow_trace
`CollectDataFlow()` uses `Flags.collect_data_flow` and
`Flags.data_flow_trace` at the same time. But in the null check before
the invocation, only `Flags.collect_data_flow` is checked, and there is
no other method to make sure `Flags.data_flow_trace` is not null, so
adding a null check for `Flags.data_flow_trace`.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D145040
2023-03-07 22:18:29 -08:00
Wu, Yingcong
91985c2ee3 Use the right printf format specifiers
Some printf format strings in libfuzzer are using the wrong specifizers, fix in this commit.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D145033
2023-03-07 21:59:09 -08:00
Advenam Tacet
6c485409de Adding missing colon
Simple typo fix.
The absence of this colon may be confusing and result in misinterpretation of the result.

In normal libfuzzer mode, that colon is present.

You can compare with:
aa0e9046c1/compiler-rt/lib/fuzzer/FuzzerLoop.cpp (L356)

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D142171
2023-01-19 20:57:12 -08:00
Haowei Wu
beb3fa2d2e Revert "Reland "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests""
This reverts commit 255c3e3dcb, which
breaks Msan-x86_64-Test.
2022-12-13 16:38:12 -08:00
Rainer Orth
255c3e3dcb Reland "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests"
When trying to debug some `compiler-rt` unittests, I initially had a hard
time because

- even in a `Debug` build one needs to set `COMPILER_RT_DEBUG` to get
  debugging info for some of the code and
- even so the unittests used a hardcoded `-O2` which often makes debugging
  impossible.

This patch addresses this by instead using `-O0` if `COMPILER_RT_DEBUG`.

Changes relative to the previous commit:

- Use `string(APPEND)` for `COMPILER_RT_TEST_COMPILER_CFLAGS`.
- Omit `-O3` from `COMPILER_RT_TEST_COMPILER_CFLAGS` in non-debug builds for now.
- Provide `__sanitizer::integral_constant<bool, true>::value` instantiation
  for `sanitizer_type_traits_test.cpp` in debug builds.
- Disable subtests of `tsan/tests/unit/tsan_trace_test.cpp` that deadlock
  in debug builds.
- `XFAIL` `tsan/Linux/check_memcpy.c` in debug builds.

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

Differential Revision: https://reviews.llvm.org/D91620
2022-12-13 10:58:58 +01:00
Vitaly Buka
68f4ceaf9b Revert "[compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests"
Breaks some bots, details in https://reviews.llvm.org/D91620

This reverts commit 93b1256e38.
2022-10-05 09:59:25 -07:00
Rainer Orth
93b1256e38 [compiler-rt][test] Heed COMPILER_RT_DEBUG when compiling unittests
When trying to debug some `compiler-rt` unittests, I initially had a hard
time because

- even in a `Debug` build one needs to set `COMPILER_RT_DEBUG` to get
  debugging info for some of the code and
- even so the unittests used a hardcoded `-O2` which often makes debugging
  impossible.

This patch addresses this by instead using `-O0` if `COMPILER_RT_DEBUG`.
Two tests in `sanitizer_type_traits_test.cpp` need to be disabled since
they have undefined references to `__sanitizer::integral_constant<bool,
true>::value`.

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

Differential Revision: https://reviews.llvm.org/D91620
2022-10-05 09:53:26 +02: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
Maxim Schessler
aa0e9046c1 Libfuzzer fix for Ctrl + c not working with -fork and -ignore_crashes=1
In some cases running Libfuzzer in fork mode with -ignore_crashes=1 counts ctrl+c as crash and restarts.

Thread: https://github.com/google/oss-fuzz/issues/4547

Credit: Marcel Boehme <marcel.boehme@acm.org>

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D130990
2022-08-16 16:45:39 -07:00