- Remove or consolidate macOS notes sprinkled throughout the doc into dedicated section
- Note that support for fuzzing on macOS is not maintained
Closes #33731
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33921.
See the guideline for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | darosior, brunoerg, frankomosh, rkrux, ismaelsadeeq |
| Concept NACK | l0rinc |
| Concept ACK | janb84 |
If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
7@@ -8,8 +8,6 @@ To quickly get started fuzzing Bitcoin Core using [libFuzzer](https://llvm.org/d
8 $ git clone https://github.com/bitcoin/bitcoin
9 $ cd bitcoin/
10 $ cmake --preset=libfuzzer
11-# macOS users: If you have problem with this step then make sure to read "macOS hints for
224-# Also, it might be required to run "afl-system-config" to adjust the shared
225-# memory parameters.
226 $ mkdir -p inputs/ outputs/
227 $ echo A > inputs/thin-air-input
228 $ FUZZ=bech32 ./AFLplusplus/afl-fuzz -i inputs/ -o outputs/ -- build_fuzz/bin/fuzz
229-# You may have to change a few kernel parameters to test optimally - afl-fuzz
197+Reproducing and debugging fuzz testcases on macOS is supported, by building the
198+fuzz binary without support for any specific fuzzing engine.
199
200-Using `lld` is required due to issues with Apple's `ld` and `LLVM`.
201+You may still be able to fuzz on macOS using the following steps (provided on
202+best effort basis, only aimed at the latest macOS version, may be outdated):
provided on best effort basis -> provided on a best-effort basis [missing article "a" and standard phrasing uses "best-effort" as a compound adjective]
208 $ brew install llvm lld
209-$ cmake --preset=libfuzzer \
210+$ cmake --preset=libfuzzer-nosan \
211 -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
212 -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
213 -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld"
since this is an alternative to the above linux one and since the build directory is changed now, should we add
0 cmake --build build_fuzz_nosan -j$(nproc)
1 FUZZ=coins_view_db build_fuzz_nosan/bin/fuzz
after this?
205-
206-```sh
207+```
208 $ brew install llvm lld
209-$ cmake --preset=libfuzzer \
210+$ cmake --preset=libfuzzer-nosan \
As described in #32084 (comment) this doesn’t seem to be enough for me, I’m getting a lot of failures locally on my non-intel-based Mac.
It needs a few more parameters to avoid being tangled with local AppleClang:
0cmake --preset=libfuzzer-nosan \
1 -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
2 -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
3 -DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)" \
4 -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L$(brew --prefix llvm)/lib/c++"
This comment led me to remove the steps entirely
Hmmm, so what happened to “best effort”?
which is partly what we’re trying to avoid with this effort in the first place
I thought we were aiming to provide Mac users a way to have at least basic fuzzing support.
This works on my mac M3:
0cmake -B fuzzbuild \
1 -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
2 -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
3 -DCMAKE_BUILD_TYPE=Debug \
4 -DBUILD_FOR_FUZZING=ON \
5 -DSANITIZERS=fuzzer \
6 -DAPPEND_LDFLAGS=-Wl,-no_warn_duplicate_libraries
I remember copying this from the original documentation when we transitioned to cmake (before the presets). It seems like everyone has their own way to make it work, so whatever we put here likely won’t work for somebody. I’m fine with removing them completely or just documenting some “basic” command to get people started. Whoever really needs to fuzz on mac will figure it out.
Although, I thought the point was to reduce the number of issues that were constantly being opened wrt to mac fuzzing
Wasn’t the point to actually do a best effort of solving their problem instead of just silencing the issues?
This works on my mac M3:
Can you show the exact command because this is missing at least a backslash. As mentioned, having the latest dependencies and running:
0cmake -B fuzzbuild \
1 -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
2 -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
3 -DCMAKE_BUILD_TYPE=Debug \
4 -DBUILD_FOR_FUZZING=ON \
5 -DSANITIZERS=fuzzer \
6 -DAPPEND_LDFLAGS=-Wl,-no_warn_duplicate_libraries && \
7 cmake --build fuzzbuild -j$(nproc)
Fails with:
0In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/_malloc.h:44:
1/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/_malloc_type.h:93:52: error: unknown type name 'size_t';
2 did you mean 'std::size_t'?
3 93 | void * __sized_by_or_null(size) malloc_type_malloc(size_t size, malloc_type_id_t type_id) __result_use_check __alloc_size(1);
4 | ^
5/opt/homebrew/Cellar/llvm/21.1.5/bin/../include/c++/v1/__cstddef/size_t.h:20:7: note: 'std::size_t' declared here
6 20 | using size_t = decltype(sizeof(int));
7 | ^
But adding the mentioned
0-DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)" \
1-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L$(brew --prefix llvm)/lib/c++"
0rm -rfd fuzzbuild && \
1cmake -B fuzzbuild \
2 -DCMAKE_C_COMPILER="$(brew --prefix llvm)/bin/clang" \
3 -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
4 -DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)" \
5 -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L$(brew --prefix llvm)/lib/c++" \
6 -DCMAKE_BUILD_TYPE=Debug \
7 -DBUILD_FOR_FUZZING=ON \
8 -DSANITIZERS=fuzzer \
9 -DAPPEND_LDFLAGS=-Wl,-no_warn_duplicate_libraries && \
10cmake --build fuzzbuild -j$(nproc) && \
11FUZZ=coins_view_db fuzzbuild/bin/fuzz
Makes it work again. It’s not pretty, but it’s how I understand “best-effort”.
Can you please try if you can reproduce the above with latest xcode?
softwareupdate –install Xcode
Sure, lgtm
Thanks, let me know if you can reproduce the results above.
I’m fine with including or not including a command for mac in the docs.
I do feel strongly about having some kind of support for Macs, otherwise fuzzing will be even more of a black box as it is currently.
it depends on macOS version, brew version etc
What if we documented a solution that would work with latest xcode and clang and whatever else is needed? That shouldn’t be too difficult and shouldn’t involve “bike shedding” (I don’t think it’s the correct term here since it’s not a “minor, easily understandable issues” at the expense of “neglecting more complex, important matters”).
As mentioned, I strongly think we should have guidance for at least basic fuzzing support for Mac as well!
ACK 6e37b3b4861733ca97ec5d27d0bf52d187b6a2c9
nit: i think it would be good to have a sentence that fuzzing support is only maintained for Linux platforms as the first line of the document, so readers know what to expect. It’s fine if it’s also repeated in the “MacOS notes” section.
ACK 6e37b3b4861733ca97ec5d27d0bf52d187b6a2c9
I do remember facing issues on Mac some time back that prompted me to create issue #33667.
Like mentioned in earlier couple comments, it’d be helpful to mention that Linux is recommended in the beginning “Quickstart guide” section.
206- -DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \
207- -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld"
208-```
209+Support for fuzzing on macOS is not officially maintained by this project. If
210+you are running into issues on macOS, we recommend fuzzing on Linux instead for
211+best results. On macOS this can be done within Docker or a virtual machine.
NIT: non-blocking, maybe add nix-shell as an alternative because of native speed alternative.
0best results. On macOS this can be done within Docker, a virtual machine or a nix-shell.
I’m running the fuzzer just fine on MacOS, Apple silicon in a nix-shell to the point that I’m actually questioning myself “am I doing it right?” seeing all the responses here and in #33731. ( Results are the same as a linux run, so i’m ok )
Concept ACK c34bc01b2ff2fc91ed4020288c5fa15f0c5b075e
PR Changes fuzzng readme to nudge MacOS users to fuzz under linux.
Given the number of issues I think it’s best to change the fuzzing.md to suggest the MacOS users to fuzz under Linux.
Have added small NIT given my personal experiences by using nix-shell to run the Fuzzing without trouble. (Not expecting that it will be added)
Concept ACK, I agree that we should clarify usage of fuzzing on a Mac.
However, approach NACK, as described in #33921 (review) (which was marked as resolved for some reason, so reposting here for visibility)
reACK c34bc01b2ff2fc91ed4020288c5fa15f0c5b075e
I think recommending to fuzz using docker is a good idea.