diff --git a/configure b/configure index b7055a8f74f5c4..c64e41a5bd6a66 100755 --- a/configure +++ b/configure @@ -9664,6 +9664,8 @@ UNIVERSAL_ARCH_FLAGS= + + # tweak BASECFLAGS based on compiler and platform if test "x$with_strict_overflow" = xyes then : @@ -9695,16 +9697,18 @@ printf "%s\n" "$enable_safety" >&6; } if test "$enable_safety" = "yes" then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fstack-protector-strong" >&5 -printf %s "checking whether C compiler accepts -fstack-protector-strong... " >&6; } -if test ${ax_cv_check_cflags__Werror__fstack_protector_strong+y} + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can add -fstack-protector-strong" >&5 +printf %s "checking if we can add -fstack-protector-strong... " >&6; } +if test ${ac_cv_enable_stack_protector_strong_flag+y} then : printf %s "(cached) " >&6 else $as_nop - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -Werror -fstack-protector-strong" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + py_cflags=$CFLAGS + as_fn_append CFLAGS " -fstack-protector-strong -Werror" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int @@ -9715,18 +9719,22 @@ main (void) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO" +if ac_fn_c_try_link "$LINENO" then : - ax_cv_check_cflags__Werror__fstack_protector_strong=yes + ac_cv_enable_stack_protector_strong_flag=yes else $as_nop - ax_cv_check_cflags__Werror__fstack_protector_strong=no + ac_cv_enable_stack_protector_strong_flag=no fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS=$py_cflags + fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__fstack_protector_strong" >&5 -printf "%s\n" "$ax_cv_check_cflags__Werror__fstack_protector_strong" >&6; } -if test "x$ax_cv_check_cflags__Werror__fstack_protector_strong" = xyes +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_enable_stack_protector_strong_flag" >&5 +printf "%s\n" "$ac_cv_enable_stack_protector_strong_flag" >&6; } + + + if test "x$ac_cv_enable_stack_protector_strong_flag" = xyes then : CFLAGS_NODIST="$CFLAGS_NODIST -fstack-protector-strong" else $as_nop diff --git a/configure.ac b/configure.ac index ab6233a1341422..64dc3e0a5ec792 100644 --- a/configure.ac +++ b/configure.ac @@ -2496,6 +2496,20 @@ AC_DEFUN([PY_CHECK_CC_WARNING], [ AS_VAR_POPDEF([py_var]) ]) +dnl PY_CHECK_CC_CFLAG(ENABLE, CFLAG, [MSG]) +AC_DEFUN([PY_CHECK_CC_CFLAG], [ + AS_VAR_PUSHDEF([py_var], [ac_cv_$1_]m4_normalize($2)[_flag]) + AC_CACHE_CHECK([m4_ifblank([$3], [if we can $1 $CC $2 flag], [$3])], [py_var], [ + AS_VAR_COPY([py_cflags], [CFLAGS]) + AS_VAR_APPEND([CFLAGS], [" -f$2 -Werror"]) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], + [AS_VAR_SET([py_var], [yes])], + [AS_VAR_SET([py_var], [no])]) + AS_VAR_COPY([CFLAGS], [py_cflags]) + ]) + AS_VAR_POPDEF([py_var]) +]) + # tweak BASECFLAGS based on compiler and platform AS_VAR_IF([with_strict_overflow], [yes], [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"], @@ -2512,7 +2526,10 @@ AC_MSG_RESULT([$enable_safety]) if test "$enable_safety" = "yes" then - AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [CFLAGS_NODIST="$CFLAGS_NODIST -fstack-protector-strong"], [AC_MSG_WARN([-fstack-protector-strong not supported])], [-Werror]) + PY_CHECK_CC_CFLAG([enable], [stack-protector-strong], [if we can add -fstack-protector-strong]) + AS_VAR_IF([ac_cv_enable_stack_protector_strong_flag], [yes], + [CFLAGS_NODIST="$CFLAGS_NODIST -fstack-protector-strong"], AC_MSG_WARN([-fstack-protector-strong not supported])) + AX_CHECK_COMPILE_FLAG([-Wtrampolines], [CFLAGS_NODIST="$CFLAGS_NODIST -Wtrampolines"], [AC_MSG_WARN([-Wtrampolines not supported])], [-Werror]) AX_CHECK_COMPILE_FLAG([-Wconversion], [CFLAGS_NODIST="$CFLAGS_NODIST -Wconversion"], [AC_MSG_WARN([-Wconversion not supported])], [-Werror]) AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [CFLAGS_NODIST="$CFLAGS_NODIST -Wimplicit-fallthrough"], [AC_MSG_WARN([-Wimplicit-fallthrough not supported])], [-Werror])