genfuzz-asan.sh 1.6 KB

1234567891011121314151617181920
  1. #!/usr/bin/env bash
  2. # Builds tools/genfuzz.cpp (the generators' fuzzer, round 170i2) with AddressSanitizer + UBSan (g++) and runs it:
  3. # scripts/genfuzz-asan.sh [genfuzz options...] e.g. --rounds 2, --fl "<FL Studio>/Data", --dir <folder>, --only <name>
  4. # Objects go to build-asan/ (shared with scripts/fxfuzz-asan.sh). The C decoders come from build-local/.
  5. set -euo pipefail
  6. cd "$(dirname "$0")/.."
  7. O=build-asan; mkdir -p "$O"
  8. CORE=$(bash -c 'source <(grep -E "^CORE=" scripts/build-local.sh); echo $CORE')
  9. FL="-std=c++20 -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined -Isrc -Ithird_party/wavpack/include -Ithird_party/vorbis/include -Ithird_party/lame/include -Ithird_party/sse2neon -Ithird_party/pocketpy -Ithird_party/monocypher -w"
  10. NEWEST_H=$(ls -t $(find src -name "*.h" -o -name "*.inc") | head -1)
  11. objs=()
  12. for f in $CORE tools/genfuzz.cpp; do objs+=("$O/$(echo "$f" | tr / _).o"); done
  13. for f in $CORE tools/genfuzz.cpp; do
  14. o="$O/$(echo "$f" | tr / _).o"
  15. extra=""; [[ $f == src/core/Slayer.cpp ]] && extra="-fno-inline" # (GCC 15 miscompiles Slayer's x87 engine when inlining: CMakeLists.txt)
  16. [[ -f $o && $o -nt $f && $o -nt $NEWEST_H ]] || echo "g++ $FL $extra -c $f -o $o"
  17. done | xargs -P "${JOBS:-8}" -I{} sh -c '{}'
  18. [[ -d build-local/wavpack ]] || { echo "run scripts/build-local.sh first (C decoders)"; exit 1; }
  19. g++ -fsanitize=address,undefined "${objs[@]}" build-local/wavpack/*.o build-local/vorbis/*.o build-local/lame/*.o build-local/pocketpy/*.o build-local/monocypher/*.o -o "$O/genfuzz"
  20. ASAN_OPTIONS=${ASAN_OPTIONS:-detect_leaks=0} "$O/genfuzz" "$@"