From 69c6a41ffb878ef98c9378ed4b1634a404cfaa7f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 02:53:35 +0200 Subject: Adding upstream version 2.7.6. Signed-off-by: Daniel Baumann --- m4/sanitizer.m4 | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 m4/sanitizer.m4 (limited to 'm4/sanitizer.m4') diff --git a/m4/sanitizer.m4 b/m4/sanitizer.m4 new file mode 100644 index 0000000..276f032 --- /dev/null +++ b/m4/sanitizer.m4 @@ -0,0 +1,83 @@ +# Copyright (C) 2018 CZ.NIC, z.s.p.o. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +# +# Processes --with-sanitizer, --with-fuzzer, and --with-oss-fuzz flags, checks +# if the options are supported by the compiler, and sets the following +# variables accordingly: +# +# - sanitizer_CFLAGS -fsanitize=... +# - fuzzer_CLAGS -fsanitize=... +# - fuzzer_LDLAGS -fsanitize=... +# + +AC_DEFUN([AX_SANITIZER], [ + + # Configure options + AC_ARG_WITH([sanitizer], + [AS_HELP_STRING([--with-sanitizer], [Compile with sanitizer [default=no]])], + [], + [with_sanitizer=no] + ) + AC_ARG_WITH([fuzzer], + [AS_HELP_STRING([--with-fuzzer], [Compile with libfuzzer [default=no]])], + [], + [with_fuzzer=no] + ) + AC_ARG_WITH([oss-fuzz], + [AS_HELP_STRING([--with-oss-fuzz], [Link for oss-fuzz environment [default=no]])], + [], + [with_oss_fuzz=no] + ) + + # Using -fsanitize=fuzzer requires clang >= 6.0 + AS_IF([test "$with_fuzzer" != "no"],[ + # Get clang version if empty + AS_IF([test -z "$CC_CLANG_VERSION"],[AX_CC_CLANG]) + AX_COMPARE_VERSION([$CC_CLANG_VERSION],ge,[6.0],[],[ + AC_MSG_ERROR([clang >= 6.0 required for fuzzer])])]) + + # Default values + AS_IF([test "$with_sanitizer" = "yes"], [ with_sanitizer=address ]) + AS_IF([test "$with_fuzzer" = "yes"], [ with_fuzzer=fuzzer ]) + + # Construct output variables + sanitizer_CFLAGS= + fuzzer_CFLAGS= + fuzzer_LDFLAGS= + AS_IF([test "$with_sanitizer" != "no"], [ + sanitizer_CFLAGS="-fsanitize=${with_sanitizer}" + ]) + AS_IF([test "$with_fuzzer" != "no"], [ + fuzzer_CFLAGS="-fsanitize=${with_fuzzer}" + fuzzer_LDFLAGS="-fsanitize=${with_fuzzer}" + ]) + AC_SUBST(fuzzer_CFLAGS) + AC_SUBST(fuzzer_LDFLAGS) + + # Test compiler support + AS_IF([test -n "$sanitizer_CFLAGS" -o -n "$fuzzer_CFLAGS"], [ + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $sanitizer_CFLAGS $fuzzer_CFLAGS" + AC_MSG_CHECKING([whether compiler accepts '${sanitizer_CFLAGS} ${fuzzer_CFLAGS}']) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + AC_MSG_ERROR([Options are not supported.]) + ]) + CFLAGS="$save_CFLAGS" + ]) + +]) # AX_SANITIZER -- cgit v1.2.3