Commit 3d4f3485 authored by 李澍非 's avatar 李澍非
Browse files

fuzz: add configure flag --enable-fuzzing

parent 6879a405
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -499,6 +499,7 @@ docker="no"
debug_mutex="no"
libpmem=""
default_devices="yes"
fuzzing="no"

# cross compilers defaults, can be overridden with --cross-cc-ARCH
cross_cc_aarch64="aarch64-linux-gnu-gcc"
@@ -641,6 +642,15 @@ int main(void) { return 0; }
EOF
}

write_c_fuzzer_skeleton() {
    cat > $TMPC <<EOF
#include <stdint.h>
#include <sys/types.h>
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
EOF
}

if check_define __linux__ ; then
  targetos="Linux"
elif check_define _WIN32 ; then
@@ -1543,6 +1553,10 @@ for opt do
  ;;
  --disable-libpmem) libpmem=no
  ;;
  --enable-fuzzing) fuzzing=yes
  ;;
  --disable-fuzzing) fuzzing=no
  ;;
  *)
      echo "ERROR: unknown option $opt"
      echo "Try '$0 --help' for more information"
@@ -5904,6 +5918,15 @@ if has "docker"; then
    docker=$($python $source_path/tests/docker/docker.py probe)
fi

##########################################
# checks for fuzzer
if test "$fuzzing" = "yes" ; then
  write_c_fuzzer_skeleton
  if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address,fuzzer" ""; then
      have_fuzzer=yes
  fi
fi

##########################################
# check for libpmem

@@ -6481,6 +6504,7 @@ echo "docker $docker"
echo "libpmem support   $libpmem"
echo "libudev           $libudev"
echo "default devices   $default_devices"
echo "fuzzing support   $fuzzing"

if test "$supported_cpu" = "no"; then
    echo
@@ -7306,6 +7330,16 @@ fi
if test "$sheepdog" = "yes" ; then
  echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
fi
if test "$fuzzing" = "yes" ; then
  if test "$have_fuzzer" = "yes"; then
    FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
    FUZZ_CFLAGS=" -fsanitize=address,fuzzer"
    CFLAGS=" -fsanitize=address,fuzzer-no-link"
  else
    error_exit "Your compiler doesn't support -fsanitize=address,fuzzer"
    exit 1
  fi
fi

if test "$tcg_interpreter" = "yes"; then
  QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES"
@@ -7396,6 +7430,11 @@ if test "$libudev" != "no"; then
    echo "CONFIG_LIBUDEV=y" >> $config_host_mak
    echo "LIBUDEV_LIBS=$libudev_libs" >> $config_host_mak
fi
if test "$fuzzing" != "no"; then
    echo "CONFIG_FUZZ=y" >> $config_host_mak
    echo "FUZZ_CFLAGS=$FUZZ_CFLAGS" >> $config_host_mak
    echo "FUZZ_LDFLAGS=$FUZZ_LDFLAGS" >> $config_host_mak
fi

# use included Linux headers
if test "$linux" = "yes" ; then