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