Commit Graph

483 Commits

Author SHA1 Message Date
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
Petr Hosek
df90d22704 [CMake] Option to select C++ library for runtimes that use it
We currently have an option to select C++ ABI and C++ library for tests
but there are runtimes that use C++ library, specifically ORC and XRay,
which aren't covered by existing options. This change introduces a new
option to control the use of C++ libray for these runtimes.

Ideally, this option should become the default way to select C++ library
for all of compiler-rt replacing the existing options (the C++ ABI
option could remain as a hidden internal option).

Differential Revision: https://reviews.llvm.org/D128036
2022-07-08 22:10:24 +00:00
Kostya Serebryany
92fb310151 [libFuzzer] Extend the fuzz target intarface to allow -1 return value.
With this change, fuzz targets may choose to return -1
to indicate that the input should not be added to the corpus
regardless of the coverage it generated.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D128749
2022-06-30 13:21:27 -07:00
Petr Hosek
f3caa98e49 Revert "[CMake][compiler-rt] Clean up the use of libcxx and libcxxabi"
This reverts commit 4164cfa537 since
it broke the clang-x86_64-debian-fast builder:

  https://lab.llvm.org/buildbot/#/builders/109/builds/41339
2022-06-25 03:10:55 +00:00
Petr Hosek
4164cfa537 [CMake][compiler-rt] Clean up the use of libcxx and libcxxabi
We no longer support the use of LLVM_ENABLE_PROJECTS for libcxx and
libcxxabi. We don't use paths to libcxx and libcxxabi in compiler-rt.

Differential Revision: https://reviews.llvm.org/D126905
2022-06-25 02:53:43 +00:00
Petr Hosek
72ec31afad [CMake] Use set rather than list PREPEND
list PREPEND is only supported since CMake 3.15.

Differential Revision: https://reviews.llvm.org/D128548
2022-06-25 02:19:55 +00:00
Petr Hosek
048e6bb46b [CMake][compiler-rt] Treat target cflags as list rather than string
This is need after 30dfe016d4.

Differential Revision: https://reviews.llvm.org/D128548
2022-06-24 22:37:00 +00:00
Petr Hosek
8bee6e52f8 Revert "[CMake][compiler-rt] Clean up the use of libcxx and libcxxabi"
This reverts commit c0d4f2282d which
broke clang-x86_64-debian-fast:

  https://lab.llvm.org/buildbot/#/builders/109/builds/41268
2022-06-24 08:24:45 +00:00
Petr Hosek
c0d4f2282d [CMake][compiler-rt] Clean up the use of libcxx and libcxxabi
We no longer support the use of LLVM_ENABLE_PROJECTS for libcxx and
libcxxabi. We don't use paths to libcxx and libcxxabi in compiler-rt.

Differential Revision: https://reviews.llvm.org/D126905
2022-06-24 08:11:37 +00:00