The Bitcoin Core fuzzing docs contain some hints for getting fuzz testing working on MacOS. But if I have access to a Linux machine/VM should I stick to doing all fuzzing on Linux? I'm assuming there is no little benefit to the project as a whole that people are fuzzing on different operating systems (other than expanding the number of people fuzzing Bitcoin Core).
If you have access to a Linux machine/VM you should probably do fuzzing on that rather than MacOS. It is likely you will need to do more troubleshooting getting set up on MacOS. However, people have got fuzzing working on MacOS e.g. robot-dreams during this Bitcoin Core PR review club session on fuzz testing:
I was able to get things work by following the "macOS hints for libFuzzer", but I had to remove the
--disable-asmflag when running
In addition brakmic has some additional guidance for those trying to get set up on MacOS:
- Take care of having an LLVM/Clang environment that contains fuzzing libraries. The default one from Apple is not enough, so that you will have to install it with brew, if not already done.
- When executing ./configure you should put --disable-asm to avoid errors with certain assembly code from Bitcoin Core's code. There's an entry about it here and it seems to have something to do with sanitizers you have to compile for fuzzing.
- Take care of giving the correct path for clang and clang++, like CC=/path/to/clang CXX=/path/to/clang++
- If you run into problems with "boost sleep" or some of boost's libraries can't be found, like boost.thread or boost.filesystem, add this to your configure:
Notice: I am using Catalina 10.15.1, so your SDK might be different and you should adapt the path accordingly. Here's my complete configure, just in case.
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address,undefined --with-boost CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" CXXFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk" CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS="-L/usr/local/lib/darwin/" --disable-asm
On the benefit to the Bitcoin Core project overall, I would say the greatest benefit would be onboarding fuzz testers and reviewers of the various fuzzing PRs as quickly as possible. Unit tests and functional tests need to pass on various operating systems but the ultimate aim of fuzz testing is examining for edge cases, the majority of which won't be dependent on the operating system. So whatever will get you up and running the quickest is the optimal approach.