Skip to content

Commit 72c8b9c

Browse files
committed
Update fuzz testing build instructions
1 parent 0074e1a commit 72c8b9c

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

fuzz_test/README.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,62 @@
1-
# Niave Fuzzing of File Parsing Code
1+
# Naive Fuzzing of File Parsing Code
22

3-
## Compiling on macOS
4-
The default Apple compiler doesnt seem to dome with the clang fuzzing library, so you need to install `llvm` and use it to compile the code. The commands to do this that work for me are:
3+
## Prerequisites
4+
- macOS with Homebrew installed
5+
- Boost library compiled and installed (see main SpecUtils README for Boost setup)
6+
- Wt library (optional, for URI spectra support)
57

8+
## Compiling on macOS (ARM64/Intel)
9+
The default Apple compiler doesn't support the clang fuzzing library, so you need to install LLVM via Homebrew and use specific linking flags to resolve ARM64 compatibility issues.
10+
11+
### Step 1: Install LLVM via Homebrew
612
```bash
713
brew install llvm
14+
```
815

16+
### Step 2: Set up environment variables
17+
```bash
918
unset CMAKE_OSX_DEPLOYMENT_TARGET
1019

1120
# Since Big Sur v11.1, we need to fix up the LIBRARY_PATH variable
12-
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
21+
export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
1322

14-
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib" #maybe not necassary
15-
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include" #maybe not necassary
23+
# Required for ARM64 fuzzer linking
24+
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -lc++abi"
25+
```
1626

27+
### Step 3: Create build directory and configure
28+
```bash
1729
cd /path/to/SpecUtils
18-
mkdir build_fuzz
19-
20-
cmake -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_IGNORE_PATH="/Applications/Xcode.app" -DCMAKE_PREFIX_PATH="/opt/homebrew/opt/llvm;/path/to/compiled/boost/" -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" -DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES="/opt/homebrew/opt/llvm/include/c++/v1" -DSpecUtils_BUILD_FUZZING_TESTS=ON ..
30+
mkdir build_fuzzing
31+
cd build_fuzzing
32+
33+
# Replace /path/to/your/boost/install with your actual Boost installation path
34+
cmake -DCMAKE_BUILD_TYPE="RelWithDebInfo" \
35+
-DCMAKE_IGNORE_PATH="/Applications/Xcode.app" \
36+
-DCMAKE_PREFIX_PATH="/opt/homebrew/opt/llvm;/path/to/your/boost/install" \
37+
-DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" \
38+
-DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" \
39+
-DCMAKE_CXX_FLAGS="-stdlib=libc++" \
40+
-DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++ -L/opt/homebrew/opt/llvm/lib/c++ -lc++abi" \
41+
-DSpecUtils_BUILD_FUZZING_TESTS=ON \
42+
-DSpecUtils_BUILD_REGRESSION_TEST=OFF \
43+
-DSpecUtils_ENABLE_EQUALITY_CHECKS=ON \
44+
-DSpecUtils_ENABLE_URI_SPECTRA=ON \
45+
-DSpecUtils_FLT_PARSE_METHOD=boost \
46+
..
47+
```
2148

49+
### Step 4: Build the project
50+
```bash
2251
cmake --build . --config RelWithDebInfo -j8
2352
```
2453

54+
### Troubleshooting
55+
If you encounter linking errors with `std::__1::__hash_memory` symbols, ensure you have:
56+
1. LLVM installed via Homebrew (not just Xcode command line tools)
57+
2. The correct LDFLAGS and CMAKE_EXE_LINKER_FLAGS set as shown above
58+
3. Both `-stdlib=libc++` and `-lc++abi` linking flags specified
59+
2560
You then need to create a `CORPUS_DIR` that contains a wide variety of sample spectrum files.
2661
Once you do this, you can run a fuzz job, use a command like:
2762
```bash

0 commit comments

Comments
 (0)