Skip to content

Commit 8bb40d5

Browse files
author
MarcoFalke
committed
Merge #20560: fuzz: Link all targets once
fa13e1b build: Add option --enable-danger-fuzz-link-all (MarcoFalke) 44444ba fuzz: Link all targets once (MarcoFalke) Pull request description: Currently the linker is invoked more than 150 times when compiling with `--enable-fuzz`. This is problematic for several reasons: * It wastes disk space north of 20 GB, as all libraries and sanitizers are linked more than 150 times * It wastes CPU time, as the link step can practically not be cached (similar to ccache for object files) * It makes it a blocker to compile the fuzz tests by default for non-fuzz builds #19388, for the aforementioned reasons * The build file is several thousand lines of code, without doing anything meaningful except listing each fuzz target in a highly verbose manner * It makes writing new fuzz tests unnecessarily hard, as build system knowledge is required; Compare that to boost unit tests, which can be added by simply editing an existing cpp file * It encourages fuzz tests that re-use the `buffer` or assume the `buffer` to be concatenations of seeds, which increases complexity of seeds and complexity for the fuzz engine to explore; Thus reducing the effectiveness of the affected fuzz targets Fixes #20088 ACKs for top commit: practicalswift: Tested ACK fa13e1b sipa: ACK fa13e1b. Reviewed the code changes, and tested the 3 different test_runner.py modes (run once, merge, generate). I also tested building with the new --enable-danger-fuzz-link-all Tree-SHA512: 962ab33269ebd51810924c51266ecc62edd6ddf2fcd9a8c359ed906766f58c3f73c223f8d3cc49f2c60f0053f65e8bdd86ce9c19e673f8c2b3cd676e913f2642
2 parents a35a346 + fa13e1b commit 8bb40d5

File tree

100 files changed

+476
-1307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+476
-1307
lines changed

.fuzzbuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ setup:
77
- sudo apt-get update
88
- sudo apt-get install -y autoconf bsdmainutils clang git libboost-all-dev libboost-program-options-dev libc++1 libc++abi1 libc++abi-dev libc++-dev libclang1 libclang-dev libdb5.3++ libevent-dev libllvm-ocaml-dev libomp5 libomp-dev libprotobuf-dev libqt5core5a libqt5dbus5 libqt5gui5 libssl-dev libtool llvm llvm-dev llvm-runtime pkg-config protobuf-compiler qttools5-dev qttools5-dev-tools software-properties-common
99
- ./autogen.sh
10-
- CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined
10+
- CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined --enable-danger-fuzz-link-all
1111
- make
1212
- git clone https://github.com/bitcoin-core/qa-assets
1313
auto_targets:

configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ AC_ARG_ENABLE([fuzz],
170170
[enable_fuzz=$enableval],
171171
[enable_fuzz=no])
172172

173+
AC_ARG_ENABLE([danger_fuzz_link_all],
174+
AS_HELP_STRING([--enable-danger-fuzz-link-all],
175+
[Danger! Modifies source code. Needs git and gnu sed installed. Link each fuzz target (default no).]),
176+
[enable_danger_fuzz_link_all=$enableval],
177+
[enable_danger_fuzz_link_all=no])
178+
173179
AC_ARG_WITH([qrencode],
174180
[AS_HELP_STRING([--with-qrencode],
175181
[enable QR code support (default is yes if qt is enabled and libqrencode is found)])],
@@ -1624,6 +1630,7 @@ AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
16241630
AM_CONDITIONAL([USE_BDB], [test "x$use_bdb" = "xyes"])
16251631
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
16261632
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
1633+
AM_CONDITIONAL([ENABLE_FUZZ_LINK_ALL],[test x$enable_danger_fuzz_link_all = xyes])
16271634
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
16281635
AM_CONDITIONAL([ENABLE_QT_TESTS],[test x$BUILD_TEST_QT = xyes])
16291636
AM_CONDITIONAL([ENABLE_BENCH],[test x$use_bench = xyes])

doc/fuzzing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $ CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzze
1212
# macOS users: If you have problem with this step then make sure to read "macOS hints for
1313
# libFuzzer" on https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md#macos-hints-for-libfuzzer
1414
$ make
15-
$ src/test/fuzz/process_message
15+
$ FUZZ=process_message src/test/fuzz/fuzz
1616
# abort fuzzing using ctrl-c
1717
```
1818

@@ -26,7 +26,7 @@ If you specify a corpus directory then any new coverage increasing inputs will b
2626

2727
```sh
2828
$ mkdir -p process_message-seeded-from-thin-air/
29-
$ src/test/fuzz/process_message process_message-seeded-from-thin-air/
29+
$ FUZZ=process_message src/test/fuzz/fuzz process_message-seeded-from-thin-air/
3030
INFO: Seed: 840522292
3131
INFO: Loaded 1 modules (424174 inline 8-bit counters): 424174 [0x55e121ef9ab8, 0x55e121f613a6),
3232
INFO: Loaded 1 PC tables (424174 PCs): 424174 [0x55e121f613a8,0x55e1225da288),
@@ -70,7 +70,7 @@ To fuzz `process_message` using the [`bitcoin-core/qa-assets`](https://github.co
7070
7171
```sh
7272
$ git clone https://github.com/bitcoin-core/qa-assets
73-
$ src/test/fuzz/process_message qa-assets/fuzz_seed_corpus/process_message/
73+
$ FUZZ=process_message src/test/fuzz/fuzz qa-assets/fuzz_seed_corpus/process_message/
7474
INFO: Seed: 1346407872
7575
INFO: Loaded 1 modules (424174 inline 8-bit counters): 424174 [0x55d8a9004ab8, 0x55d8a906c3a6),
7676
INFO: Loaded 1 PC tables (424174 PCs): 424174 [0x55d8a906c3a8,0x55d8a96e5288),
@@ -129,7 +129,7 @@ $ make
129129
# try compiling using: AFL_NO_X86=1 make
130130
$ mkdir -p inputs/ outputs/
131131
$ echo A > inputs/thin-air-input
132-
$ afl/afl-fuzz -i inputs/ -o outputs/ -- src/test/fuzz/bech32
132+
$ FUZZ=bech32 afl/afl-fuzz -i inputs/ -o outputs/ -- src/test/fuzz/fuzz
133133
# You may have to change a few kernel parameters to test optimally - afl-fuzz
134134
# will print an error and suggestion if so.
135135
```
@@ -153,7 +153,7 @@ $ cd ..
153153
$ CC=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang CXX=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ ./configure --enable-fuzz --with-sanitizers=address,undefined
154154
$ make
155155
$ mkdir -p inputs/
156-
$ honggfuzz/honggfuzz -i inputs/ -- src/test/fuzz/process_message
156+
$ FUZZ=process_message honggfuzz/honggfuzz -i inputs/ -- src/test/fuzz/fuzz
157157
```
158158
159159
Read the [Honggfuzz documentation](https://github.com/google/honggfuzz/blob/master/docs/USAGE.md) for more information.

0 commit comments

Comments
 (0)