xref: /PHP-8.3/sapi/fuzzer/config.m4 (revision 1584352e)
1AC_MSG_CHECKING(for clang fuzzer SAPI)
2
3PHP_ARG_ENABLE([fuzzer],,
4  [AS_HELP_STRING([--enable-fuzzer],
5    [Build PHP as clang fuzzing test module (for developers)])],
6  [no],
7  [no])
8
9dnl For newer clang versions see https://llvm.org/docs/LibFuzzer.html#fuzzer-usage
10dnl for relevant flags.
11
12dnl Macro to define fuzzing target
13dnl PHP_FUZZER_TARGET(name, target-var)
14dnl
15AC_DEFUN([PHP_FUZZER_TARGET], [
16  PHP_FUZZER_BINARIES="$PHP_FUZZER_BINARIES $SAPI_FUZZER_PATH/php-fuzz-$1"
17  PHP_SUBST($2)
18  PHP_ADD_SOURCES_X([sapi/fuzzer],[fuzzer-$1.c],[],$2)
19  $2="[$]$2 $FUZZER_COMMON_OBJS"
20])
21
22if test "$PHP_FUZZER" != "no"; then
23  AC_MSG_RESULT([yes])
24  dnl Don't use PHP_REQUIRE_CXX() to avoid unnecessarily pulling in -lstdc++
25  AC_PROG_CXX
26  AC_PROG_CXXCPP
27  PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/sapi/fuzzer/Makefile.frag)
28  SAPI_FUZZER_PATH=sapi/fuzzer
29  PHP_SUBST(SAPI_FUZZER_PATH)
30  if test -z "$LIB_FUZZING_ENGINE"; then
31    FUZZING_LIB="-fsanitize=fuzzer"
32    FUZZING_CC="$CC"
33    AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer-no-link], [
34      CFLAGS="$CFLAGS -fsanitize=fuzzer-no-link"
35      CXXFLAGS="$CXXFLAGS -fsanitize=fuzzer-no-link"
36    ],[
37      AC_MSG_ERROR(Compiler doesn't support -fsanitize=fuzzer-no-link)
38    ])
39  else
40    FUZZING_LIB="$LIB_FUZZING_ENGINE"
41    FUZZING_CC="$CXX -stdlib=libc++"
42  fi
43  PHP_SUBST(FUZZING_LIB)
44  PHP_SUBST(FUZZING_CC)
45
46  dnl PHP_SELECT_SAPI(fuzzer-parser, program, $FUZZER_SOURCES, , '$(SAPI_FUZZER_PATH)')
47
48  PHP_ADD_BUILD_DIR([sapi/fuzzer])
49  PHP_FUZZER_BINARIES=""
50  PHP_BINARIES="$PHP_BINARIES fuzzer"
51  PHP_INSTALLED_SAPIS="$PHP_INSTALLED_SAPIS fuzzer"
52
53  PHP_ADD_SOURCES_X([sapi/fuzzer], [fuzzer-sapi.c], [], FUZZER_COMMON_OBJS)
54
55  PHP_FUZZER_TARGET([parser], PHP_FUZZER_PARSER_OBJS)
56  PHP_FUZZER_TARGET([execute], PHP_FUZZER_EXECUTE_OBJS)
57  PHP_FUZZER_TARGET([function-jit], PHP_FUZZER_FUNCTION_JIT_OBJS)
58  PHP_FUZZER_TARGET([tracing-jit], PHP_FUZZER_TRACING_JIT_OBJS)
59  PHP_FUZZER_TARGET([unserialize], PHP_FUZZER_UNSERIALIZE_OBJS)
60  PHP_FUZZER_TARGET([unserializehash], PHP_FUZZER_UNSERIALIZEHASH_OBJS)
61  PHP_FUZZER_TARGET([json], PHP_FUZZER_JSON_OBJS)
62
63  if test -n "$enable_exif" && test "$enable_exif" != "no"; then
64    PHP_FUZZER_TARGET([exif], PHP_FUZZER_EXIF_OBJS)
65  fi
66  if test -n "$enable_mbstring" && test "$enable_mbstring" != "no"; then
67    PHP_FUZZER_TARGET([mbstring], PHP_FUZZER_MBSTRING_OBJS)
68    if test -n "$enable_mbregex" && test "$enable_mbregex" != "no"; then
69      PHP_FUZZER_TARGET([mbregex], PHP_FUZZER_MBREGEX_OBJS)
70    fi
71  fi
72
73  PHP_SUBST(PHP_FUZZER_BINARIES)
74fi
75
76AC_MSG_RESULT($PHP_FUZZER)
77