Skip to content

Commit b68bac8

Browse files
author
MarcoFalke
committed
Merge #15047: build: Allow to configure --with-sanitizers=fuzzer
fad058a build: Allow to configure --with-sanitizers=fuzzer (MarcoFalke) Pull request description: Tree-SHA512: 67b775577da03639ee11826dccb14c82e78d239fe3bcbb753082b254cec52ca8bda071a8161f2f3bc284a7cdc303bbf1b649a1854a42973b1d53cd0ffb516214
2 parents 68dddcc + fad058a commit b68bac8

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,14 @@ if test x$use_sanitizers != x; then
295295
AX_CHECK_LINK_FLAG(
296296
[[-fsanitize=$use_sanitizers]],
297297
[[SANITIZER_LDFLAGS=-fsanitize=$use_sanitizers]],
298-
[AC_MSG_ERROR([linker did not accept requested flags, you are missing required libraries])])
298+
[AC_MSG_ERROR([linker did not accept requested flags, you are missing required libraries])],
299+
[],
300+
[AC_LANG_PROGRAM([[
301+
#include <cstdint>
302+
#include <cstddef>
303+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return 0; }
304+
__attribute__((weak)) // allow for libFuzzer linking
305+
]],[[]])])
299306
fi
300307

301308
ERROR_CXXFLAGS=

doc/fuzzing.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ Fuzz-testing Bitcoin Core
33

44
A special test harness `test_bitcoin_fuzzy` is provided to provide an easy
55
entry point for fuzzers and the like. In this document we'll describe how to
6-
use it with AFL.
6+
use it with AFL and libFuzzer.
77

8-
Building AFL
9-
-------------
8+
## AFL
9+
10+
### Building AFL
1011

1112
It is recommended to always use the latest version of afl:
1213
```
@@ -17,8 +18,7 @@ make
1718
export AFLPATH=$PWD
1819
```
1920

20-
Instrumentation
21-
----------------
21+
### Instrumentation
2222

2323
To build Bitcoin Core using AFL instrumentation (this assumes that the
2424
`AFLPATH` was set as above):
@@ -39,8 +39,7 @@ compiling using `afl-clang-fast`/`afl-clang-fast++` the resulting
3939
features "persistent mode" and "deferred forkserver" can be used. See
4040
https://github.com/mcarpenter/afl/tree/master/llvm_mode for details.
4141

42-
Preparing fuzzing
43-
------------------
42+
### Preparing fuzzing
4443

4544
AFL needs an input directory with examples, and an output directory where it
4645
will place examples that it found. These can be anywhere in the file system,
@@ -60,8 +59,7 @@ Example inputs are available from:
6059

6160
Extract these (or other starting inputs) into the `inputs` directory before starting fuzzing.
6261

63-
Fuzzing
64-
--------
62+
### Fuzzing
6563

6664
To start the actual fuzzing use:
6765
```
@@ -70,3 +68,21 @@ $AFLPATH/afl-fuzz -i ${AFLIN} -o ${AFLOUT} -m52 -- test/test_bitcoin_fuzzy
7068

7169
You may have to change a few kernel parameters to test optimally - `afl-fuzz`
7270
will print an error and suggestion if so.
71+
72+
## libFuzzer
73+
74+
A recent version of `clang`, the address sanitizer and libFuzzer is needed (all
75+
found in the `compiler-rt` runtime libraries package).
76+
77+
To build the `test/test_bitcoin_fuzzy` executable run
78+
79+
```
80+
./configure --disable-ccache --with-sanitizers=fuzzer,address CC=clang CXX=clang++
81+
make
82+
```
83+
84+
The fuzzer needs some inputs to work on, but the inputs or seeds can be used
85+
interchangably between libFuzzer and AFL.
86+
87+
See https://llvm.org/docs/LibFuzzer.html#running on how to run the libFuzzer
88+
instrumented executable.

0 commit comments

Comments
 (0)