Skip to content

Commit 0c1e507

Browse files
committed
Merge bitcoin/bitcoin#30871: build: Add more cmake presets
f15e817 build: add more CMake presets (dev-mode, libfuzzer, libfuzzer-nosan) (Pieter Wuille) Pull request description: Add three more cmake presets to the project-wide `CMakePresets.json` file: * `dev-mode`: enables all features and dependencies * `libfuzzer`: builds for fuzzing with libfuzzer and the typical sanitizers (but not the optional ones that require suppressions) enabled. * `libfuzzer-nosan`: builds for fuzzing with libfuzzer and no (other) sanitizers ... and then uses these in some documentation. ACKs for top commit: ryanofsky: Code review ACK f15e817. This change is much needed to simplify my command line. TheCharlatan: ACK f15e817 Tree-SHA512: a5f67bb7119fd36832ca5eb7189db04bfaf88f954aa461bfb2aeb866469057b0d0272835c418bc3a264c30dd8fba6d2e2cc8a6741a889f28f52c1c09b3ba9704
2 parents fcb61bb + f15e817 commit 0c1e507

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

CMakePresets.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,63 @@
3535
"BUILD_GUI": "ON",
3636
"WITH_QRENCODE": "OFF"
3737
}
38+
},
39+
{
40+
"name": "libfuzzer",
41+
"displayName": "Build for fuzzing with libfuzzer, and sanitizers enabled",
42+
"binaryDir": "${sourceDir}/build_fuzz",
43+
"cacheVariables": {
44+
"BUILD_FOR_FUZZING": "ON",
45+
"CMAKE_C_COMPILER": "clang",
46+
"CMAKE_C_FLAGS": "-ftrivial-auto-var-init=pattern",
47+
"CMAKE_CXX_COMPILER": "clang++",
48+
"CMAKE_CXX_FLAGS": "-ftrivial-auto-var-init=pattern",
49+
"SANITIZERS": "undefined,address,fuzzer"
50+
}
51+
},
52+
{
53+
"name": "libfuzzer-nosan",
54+
"displayName": "Build for fuzzing with libfuzzer, and sanitizers disabled",
55+
"binaryDir": "${sourceDir}/build_fuzz_nosan",
56+
"cacheVariables": {
57+
"BUILD_FOR_FUZZING": "ON",
58+
"CMAKE_C_COMPILER": "clang",
59+
"CMAKE_CXX_COMPILER": "clang++",
60+
"SANITIZERS": "fuzzer"
61+
}
62+
},
63+
{
64+
"name": "dev-mode",
65+
"displayName": "Developer mode, with all features/dependencies enabled",
66+
"binaryDir": "${sourceDir}/build_dev_mode",
67+
"cacheVariables": {
68+
"BUILD_BENCH": "ON",
69+
"BUILD_CLI": "ON",
70+
"BUILD_DAEMON": "ON",
71+
"BUILD_FUZZ_BINARY": "ON",
72+
"BUILD_GUI": "ON",
73+
"BUILD_GUI_TESTS": "ON",
74+
"BUILD_KERNEL_LIB": "ON",
75+
"BUILD_SHARED_LIBS": "ON",
76+
"BUILD_TESTING": "ON",
77+
"BUILD_TESTS": "ON",
78+
"BUILD_TX": "ON",
79+
"BUILD_UTIL": "ON",
80+
"BUILD_UTIL_CHAINSTATE": "ON",
81+
"BUILD_WALLET_TOOL": "ON",
82+
"ENABLE_EXTERNAL_SIGNER": "ON",
83+
"ENABLE_HARDENING": "ON",
84+
"ENABLE_WALLET": "ON",
85+
"WARN_INCOMPATIBLE_BDB": "OFF",
86+
"WITH_BDB": "ON",
87+
"WITH_MINIUPNPC": "ON",
88+
"WITH_MULTIPROCESS": "ON",
89+
"WITH_NATPMP": "ON",
90+
"WITH_QRENCODE": "ON",
91+
"WITH_SQLITE": "ON",
92+
"WITH_USDT": "ON",
93+
"WITH_ZMQ": "ON"
94+
}
3895
}
3996
]
4097
}

doc/fuzzing.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ To quickly get started fuzzing Bitcoin Core using [libFuzzer](https://llvm.org/d
77
```sh
88
$ git clone https://github.com/bitcoin/bitcoin
99
$ cd bitcoin/
10-
$ cmake -B build_fuzz \
11-
-DCMAKE_C_COMPILER="clang" \
12-
-DCMAKE_CXX_COMPILER="clang++" \
13-
-DBUILD_FOR_FUZZING=ON \
14-
-DSANITIZERS=undefined,address,fuzzer
10+
$ cmake --preset=libfuzzer
1511
# macOS users: If you have problem with this step then make sure to read "macOS hints for
1612
# libFuzzer" on https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md#macos-hints-for-libfuzzer
1713
$ cmake --build build_fuzz
1814
$ FUZZ=process_message build_fuzz/src/test/fuzz/fuzz
1915
# abort fuzzing using ctrl-c
2016
```
2117

18+
One can use `--prefix=libfuzzer-nosan` to do the same without common sanitizers enabled.
19+
See [further](#run-without-sanitizers-for-increased-throughput) for more information.
20+
2221
There is also a runner script to execute all fuzz targets. Refer to
2322
`./test/fuzz/test_runner.py --help` for more details.
2423

@@ -107,8 +106,8 @@ INFO: seed corpus: files: 991 min: 1b max: 1858b total: 288291b rss: 150Mb
107106
Fuzzing on a harness compiled with `-DSANITIZERS=address,fuzzer,undefined` is
108107
good for finding bugs. However, the very slow execution even under libFuzzer
109108
will limit the ability to find new coverage. A good approach is to perform
110-
occasional long runs without the additional bug-detectors (just
111-
`-DSANITIZERS=fuzzer`) and then merge new inputs into a corpus as described in
109+
occasional long runs without the additional bug-detectors
110+
(`--preset=libfuzzer-nosan`) and then merge new inputs into a corpus as described in
112111
the qa-assets repo
113112
(https://github.com/bitcoin-core/qa-assets/blob/main/.github/PULL_REQUEST_TEMPLATE.md).
114113
Patience is useful; even with improved throughput, libFuzzer may need days and
@@ -145,11 +144,9 @@ You may also need to take care of giving the correct path for `clang` and
145144
Full configuration step that was tested on macOS with `brew` installed `llvm`:
146145
147146
```sh
148-
$ cmake -B build_fuzz \
147+
$ cmake --preset=libfuzzer \
149148
-DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
150149
-DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
151-
-DBUILD_FOR_FUZZING=ON \
152-
-DSANITIZERS=undefined,address,fuzzer \
153150
-DAPPEND_LDFLAGS=-Wl,-no_warn_duplicate_libraries
154151
```
155152

0 commit comments

Comments
 (0)