|
1 |
| -# Niave Fuzzing of File Parsing Code |
| 1 | +# Naive Fuzzing of File Parsing Code |
2 | 2 |
|
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) |
5 | 7 |
|
| 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 |
6 | 12 | ```bash
|
7 | 13 | brew install llvm
|
| 14 | +``` |
8 | 15 |
|
| 16 | +### Step 2: Set up environment variables |
| 17 | +```bash |
9 | 18 | unset CMAKE_OSX_DEPLOYMENT_TARGET
|
10 | 19 |
|
11 | 20 | # 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" |
13 | 22 |
|
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 | +``` |
16 | 26 |
|
| 27 | +### Step 3: Create build directory and configure |
| 28 | +```bash |
17 | 29 | 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 | +``` |
21 | 48 |
|
| 49 | +### Step 4: Build the project |
| 50 | +```bash |
22 | 51 | cmake --build . --config RelWithDebInfo -j8
|
23 | 52 | ```
|
24 | 53 |
|
| 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 | + |
25 | 60 | You then need to create a `CORPUS_DIR` that contains a wide variety of sample spectrum files.
|
26 | 61 | Once you do this, you can run a fuzz job, use a command like:
|
27 | 62 | ```bash
|
|
0 commit comments