build.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. #
  3. # Creates fuzzer builds of various kinds
  4. # - oss-fuzz emulated mode (makes sure a simulated invocation by oss-fuzz works)
  5. # - libFuzzer build (you will need clang)
  6. # - afl build (you will need afl)
  7. #
  8. #
  9. # Copyright (c) 2019 Paul Dreik
  10. #
  11. # For the license information refer to format.h.
  12. set -e
  13. me=$(basename $0)
  14. root=$(readlink -f "$(dirname "$0")/../..")
  15. echo $me: root=$root
  16. here=$(pwd)
  17. CXXFLAGSALL="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g"
  18. CMAKEFLAGSALL="$root -GNinja -DCMAKE_BUILD_TYPE=Debug -DFMT_DOC=Off -DFMT_TEST=Off -DFMT_FUZZ=On -DCMAKE_CXX_STANDARD=17"
  19. CLANG=clang++-11
  20. # For performance analysis of the fuzzers.
  21. builddir=$here/build-fuzzers-perfanalysis
  22. mkdir -p $builddir
  23. cd $builddir
  24. CXX="ccache g++" CXXFLAGS="$CXXFLAGSALL -g" cmake \
  25. $CMAKEFLAGSALL \
  26. -DFMT_FUZZ_LINKMAIN=On \
  27. -DCMAKE_BUILD_TYPE=Release
  28. cmake --build $builddir
  29. # Builds the fuzzers as oss-fuzz does.
  30. builddir=$here/build-fuzzers-ossfuzz
  31. mkdir -p $builddir
  32. cd $builddir
  33. CXX=$CLANG \
  34. CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link" cmake \
  35. cmake $CMAKEFLAGSALL \
  36. -DFMT_FUZZ_LINKMAIN=Off \
  37. -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
  38. cmake --build $builddir
  39. # Builds fuzzers for local fuzzing with libfuzzer with asan+usan.
  40. builddir=$here/build-fuzzers-libfuzzer
  41. mkdir -p $builddir
  42. cd $builddir
  43. CXX=$CLANG \
  44. CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link,address,undefined" cmake \
  45. cmake $CMAKEFLAGSALL \
  46. -DFMT_FUZZ_LINKMAIN=Off \
  47. -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
  48. cmake --build $builddir
  49. # Builds a fast fuzzer for making coverage fast.
  50. builddir=$here/build-fuzzers-fast
  51. mkdir -p $builddir
  52. cd $builddir
  53. CXX=$CLANG \
  54. CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link -O3" cmake \
  55. cmake $CMAKEFLAGSALL \
  56. -DFMT_FUZZ_LINKMAIN=Off \
  57. -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" \
  58. -DCMAKE_BUILD_TYPE=Release
  59. cmake --build $builddir
  60. # Builds fuzzers for local fuzzing with afl.
  61. builddir=$here/build-fuzzers-afl
  62. mkdir -p $builddir
  63. cd $builddir
  64. CXX="afl-g++" \
  65. CXXFLAGS="$CXXFLAGSALL -fsanitize=address,undefined" \
  66. cmake $CMAKEFLAGSALL \
  67. -DFMT_FUZZ_LINKMAIN=On
  68. cmake --build $builddir
  69. echo $me: all good