From 8863e74b86a5d95908353cf429421ecdec6a2911 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 14 Sep 2022 18:05:36 +0800 Subject: [PATCH 01/23] gh-96821: Mark modules that need -fno-strict-overflow --- configure | 8 ++++---- configure.ac | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/configure b/configure index b2024bab2fb065..66c824fb6206e2 100755 --- a/configure +++ b/configure @@ -26049,7 +26049,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__STRUCT_STATE=$py_cv_module__struct$as_nl" if test "x$py_cv_module__struct" = xyes; then : - + as_fn_append MODULE_BLOCK "MODULE__STRUCT_CFLAGS=-fno-strict-overflow$as_nl" fi @@ -26199,7 +26199,7 @@ fi as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_STATE=$py_cv_module_audioop$as_nl" if test "x$py_cv_module_audioop" = xyes; then : - + as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_CFLAGS=-fno-strict-overflow$as_nl" as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_LDFLAGS=$LIBM$as_nl" fi @@ -27149,7 +27149,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__CTYPES_STATE=$py_cv_module__ctypes$as_nl" if test "x$py_cv_module__ctypes" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__CTYPES_CFLAGS=$LIBFFI_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__CTYPES_CFLAGS=-fno-strict-overflow $LIBFFI_CFLAGS$as_nl" as_fn_append MODULE_BLOCK "MODULE__CTYPES_LDFLAGS=$LIBFFI_LIBS$as_nl" fi @@ -27718,7 +27718,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_STATE=$py_cv_module__testcapi$as_nl" if test "x$py_cv_module__testcapi" = xyes; then : - + as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_CFLAGS=-fno-strict-overflow$as_nl" fi diff --git a/configure.ac b/configure.ac index a61adcc817e82f..a6b2b9974e2dab 100644 --- a/configure.ac +++ b/configure.ac @@ -7222,7 +7222,7 @@ PY_STDLIB_MOD_SIMPLE([_posixsubprocess]) PY_STDLIB_MOD_SIMPLE([_queue]) PY_STDLIB_MOD_SIMPLE([_random]) PY_STDLIB_MOD_SIMPLE([select]) -PY_STDLIB_MOD_SIMPLE([_struct]) +PY_STDLIB_MOD_SIMPLE([_struct], [-fno-strict-overflow]) PY_STDLIB_MOD_SIMPLE([_typing]) PY_STDLIB_MOD_SIMPLE([_xxsubinterpreters]) PY_STDLIB_MOD_SIMPLE([_zoneinfo]) @@ -7236,7 +7236,7 @@ PY_STDLIB_MOD([_posixshmem], [$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS]) dnl needs libm -PY_STDLIB_MOD_SIMPLE([audioop], [], [$LIBM]) +PY_STDLIB_MOD_SIMPLE([audioop], [-fno-strict-overflow], [$LIBM]) PY_STDLIB_MOD_SIMPLE([_statistics], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([cmath], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([math], [], [$LIBM]) @@ -7297,7 +7297,7 @@ PY_STDLIB_MOD([_crypt], [$LIBCRYPT_CFLAGS], [$LIBCRYPT_LIBS]) PY_STDLIB_MOD([_ctypes], [], [test "$have_libffi" = yes], - [$LIBFFI_CFLAGS], [$LIBFFI_LIBS]) + [-fno-strict-overflow $LIBFFI_CFLAGS], [$LIBFFI_LIBS]) PY_STDLIB_MOD([_curses], [], [test "$have_curses" != "no"], [$CURSES_CFLAGS], [$CURSES_LIBS] @@ -7347,7 +7347,7 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes], [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS]) dnl test modules -PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes]) +PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes], [], [-fno-strict-overflow]) PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes]) From 0598ea97527f672560d19fa767fdb5dfcd2d5785 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 10:38:16 +0000 Subject: [PATCH 02/23] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst new file mode 100644 index 00000000000000..7e0ea17408ecf5 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -0,0 +1 @@ +Explicitly mark C modules that need defined signed integer overflow. (So that in future we can turn off the blanket `-fwrapv`, and enjoy more C compiler optimizations.) From 50cbb6147166e55ec397f44d578f2f52b4cf7c40 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 14 Sep 2022 18:45:29 +0800 Subject: [PATCH 03/23] Drop fwrapv --- configure | 9 +-------- configure.ac | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/configure b/configure index 66c824fb6206e2..c53fd12356a52f 100755 --- a/configure +++ b/configure @@ -8397,15 +8397,8 @@ if test "${OPT-unset}" = "unset" then case $GCC in yes) - # For gcc 4.x we need to use -fwrapv so lets check if its supported - if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then - WRAP="-fwrapv" - fi - if test -n "${cc_is_clang}" then - # Clang also needs -fwrapv - WRAP="-fwrapv" # bpo-30104: disable strict aliasing to compile correctly dtoa.c, # see Makefile.pre.in for more information CFLAGS_ALIASING="-fno-strict-aliasing" @@ -8416,7 +8409,7 @@ then if test "$Py_DEBUG" = 'true' ; then OPT="-g $PYDEBUG_CFLAGS -Wall" else - OPT="-g $WRAP -O3 -Wall" + OPT="-g -O3 -Wall" fi ;; *) diff --git a/configure.ac b/configure.ac index a6b2b9974e2dab..a466a7bdf929dc 100644 --- a/configure.ac +++ b/configure.ac @@ -2102,15 +2102,8 @@ if test "${OPT-unset}" = "unset" then case $GCC in yes) - # For gcc 4.x we need to use -fwrapv so lets check if its supported - if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then - WRAP="-fwrapv" - fi - if test -n "${cc_is_clang}" then - # Clang also needs -fwrapv - WRAP="-fwrapv" # bpo-30104: disable strict aliasing to compile correctly dtoa.c, # see Makefile.pre.in for more information CFLAGS_ALIASING="-fno-strict-aliasing" @@ -2121,7 +2114,7 @@ then if test "$Py_DEBUG" = 'true' ; then OPT="-g $PYDEBUG_CFLAGS -Wall" else - OPT="-g $WRAP -O3 -Wall" + OPT="-g -O3 -Wall" fi ;; *) From d2a2c82226bc211c802ef4da72591196822471f3 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sat, 17 Sep 2022 16:30:25 +0800 Subject: [PATCH 04/23] Foo --- configure | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--- configure.ac | 42 ++++++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 8 deletions(-) diff --git a/configure b/configure index c53fd12356a52f..ffef37aecb8d29 100755 --- a/configure +++ b/configure @@ -1056,6 +1056,7 @@ with_assertions enable_optimizations with_lto enable_bolt +with_fstrict_overflow with_dsymutil with_address_sanitizer with_memory_sanitizer @@ -1828,6 +1829,9 @@ Optional Packages: --with-lto=[full|thin|no|yes] enable Link-Time-Optimization in any build (default is no) + --with-fstrict-overflow choose between -fstrict-overflow or + -fno-strict-overflow (default is no for backwards + compatibility) --with-dsymutil link debug information into final executable with dsymutil in macOS (default is no) --with-address-sanitizer @@ -8345,6 +8349,60 @@ case $CC in fi esac +# Historically, some of our code assumed that signed integer overflow +# is defined behaviour via twos-complement. Prepare some flags so that +# we can mark the modules that still do so. +save_CFLAGS=$CFLAGS +CFLAGS="-fstrict-overflow -fno-strict-overflow" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -fstrict-overflow and -fno-strict-overflow" >&5 +$as_echo_n "checking if $CC supports -fstrict-overflow and -fno-strict-overflow... " >&6; } +if ${ac_cv_cc_supports_fstrict_overflow+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +int +main () +{ + + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" + NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow" + +else + + STRICT_OVERFLOW_CFLAGS="" + NO_STRICT_OVERFLOW_CFLAGS="" + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cc_supports_fstrict_overflow" >&5 +$as_echo "$ac_cv_cc_supports_fstrict_overflow" >&6; } +CFLAGS=$save_CFLAGS + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-fstrict-overflow" >&5 +$as_echo_n "checking for --with-fstrict-overflow... " >&6; } + +# Check whether --with-fstrict-overflow was given. +if test "${with_fstrict_overflow+set}" = set; then : + withval=$with_fstrict_overflow; +else + with_strict_overflow=no +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_fstrict_overflow" >&5 +$as_echo "$with_fstrict_overflow" >&6; } + # Check if CC supports -Og optimization level save_CFLAGS=$CFLAGS CFLAGS="-Og" @@ -8542,6 +8600,14 @@ UNIVERSAL_ARCH_FLAGS= # tweak BASECFLAGS based on compiler and platform +if test "x$with_strict_overflow" = xno; then : + BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS" +fi + +if test "x$with_strict_overflow" = xyes; then : + BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS" +fi + case $GCC in yes) CFLAGS_NODIST="$CFLAGS_NODIST -std=c11" @@ -26042,7 +26108,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__STRUCT_STATE=$py_cv_module__struct$as_nl" if test "x$py_cv_module__struct" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__STRUCT_CFLAGS=-fno-strict-overflow$as_nl" + as_fn_append MODULE_BLOCK "MODULE__STRUCT_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" fi @@ -26192,7 +26258,7 @@ fi as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_STATE=$py_cv_module_audioop$as_nl" if test "x$py_cv_module_audioop" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_CFLAGS=-fno-strict-overflow$as_nl" + as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_LDFLAGS=$LIBM$as_nl" fi @@ -27142,7 +27208,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__CTYPES_STATE=$py_cv_module__ctypes$as_nl" if test "x$py_cv_module__ctypes" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__CTYPES_CFLAGS=-fno-strict-overflow $LIBFFI_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE__CTYPES_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS $LIBFFI_CFLAGS$as_nl" as_fn_append MODULE_BLOCK "MODULE__CTYPES_LDFLAGS=$LIBFFI_LIBS$as_nl" fi @@ -27711,7 +27777,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_STATE=$py_cv_module__testcapi$as_nl" if test "x$py_cv_module__testcapi" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_CFLAGS=-fno-strict-overflow$as_nl" + as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" fi diff --git a/configure.ac b/configure.ac index a466a7bdf929dc..00a65c44a3b737 100644 --- a/configure.ac +++ b/configure.ac @@ -2072,6 +2072,34 @@ case $CC in fi esac +# Historically, some of our code assumed that signed integer overflow +# is defined behaviour via twos-complement. Prepare some flags so that +# we can mark the modules that still do so. +_SAVE_VAR([CFLAGS]) +CFLAGS="-fstrict-overflow -fno-strict-overflow" +AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], + [ac_cv_cc_supports_fstrict_overflow], + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM([[]], [[]]) + ],[ + STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" + NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow" + ],[ + STRICT_OVERFLOW_CFLAGS="" + NO_STRICT_OVERFLOW_CFLAGS="" + ]) +) +_RESTORE_VAR([CFLAGS]) + +AC_MSG_CHECKING(for --with-fstrict-overflow) +AC_ARG_WITH(fstrict-overflow, + AS_HELP_STRING( + [--with-fstrict-overflow], + [choose between -fstrict-overflow or -fno-strict-overflow (default is no for backwards compatibility)]),, + with_strict_overflow=no) +AC_MSG_RESULT($with_fstrict_overflow) + # Check if CC supports -Og optimization level _SAVE_VAR([CFLAGS]) CFLAGS="-Og" @@ -2229,6 +2257,12 @@ AC_DEFUN([PY_CHECK_CC_WARNING], [ ]) # tweak BASECFLAGS based on compiler and platform +AS_VAR_IF([with_strict_overflow], [no], + [BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"]) + +AS_VAR_IF([with_strict_overflow], [yes], + [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"]) + case $GCC in yes) CFLAGS_NODIST="$CFLAGS_NODIST -std=c11" @@ -7215,7 +7249,7 @@ PY_STDLIB_MOD_SIMPLE([_posixsubprocess]) PY_STDLIB_MOD_SIMPLE([_queue]) PY_STDLIB_MOD_SIMPLE([_random]) PY_STDLIB_MOD_SIMPLE([select]) -PY_STDLIB_MOD_SIMPLE([_struct], [-fno-strict-overflow]) +PY_STDLIB_MOD_SIMPLE([_struct], [$NO_STRICT_OVERFLOW_CFLAGS]) PY_STDLIB_MOD_SIMPLE([_typing]) PY_STDLIB_MOD_SIMPLE([_xxsubinterpreters]) PY_STDLIB_MOD_SIMPLE([_zoneinfo]) @@ -7229,7 +7263,7 @@ PY_STDLIB_MOD([_posixshmem], [$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS]) dnl needs libm -PY_STDLIB_MOD_SIMPLE([audioop], [-fno-strict-overflow], [$LIBM]) +PY_STDLIB_MOD_SIMPLE([audioop], [$NO_STRICT_OVERFLOW_CFLAGS], [$LIBM]) PY_STDLIB_MOD_SIMPLE([_statistics], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([cmath], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([math], [], [$LIBM]) @@ -7290,7 +7324,7 @@ PY_STDLIB_MOD([_crypt], [$LIBCRYPT_CFLAGS], [$LIBCRYPT_LIBS]) PY_STDLIB_MOD([_ctypes], [], [test "$have_libffi" = yes], - [-fno-strict-overflow $LIBFFI_CFLAGS], [$LIBFFI_LIBS]) + [$NO_STRICT_OVERFLOW_CFLAGS $LIBFFI_CFLAGS], [$LIBFFI_LIBS]) PY_STDLIB_MOD([_curses], [], [test "$have_curses" != "no"], [$CURSES_CFLAGS], [$CURSES_LIBS] @@ -7340,7 +7374,7 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes], [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS]) dnl test modules -PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes], [], [-fno-strict-overflow]) +PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes], [], [$NO_STRICT_OVERFLOW_CFLAGS]) PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes]) From 25b15bf232ed7c6236dee1a4125568c5f8213d15 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sat, 17 Sep 2022 16:35:20 +0800 Subject: [PATCH 05/23] fix --- configure | 6 ++---- configure.ac | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/configure b/configure index ffef37aecb8d29..d08d030ac649c2 100755 --- a/configure +++ b/configure @@ -8600,12 +8600,10 @@ UNIVERSAL_ARCH_FLAGS= # tweak BASECFLAGS based on compiler and platform -if test "x$with_strict_overflow" = xno; then : - BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS" -fi - if test "x$with_strict_overflow" = xyes; then : BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS" +else + BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS" fi case $GCC in diff --git a/configure.ac b/configure.ac index 00a65c44a3b737..08848f6015bb60 100644 --- a/configure.ac +++ b/configure.ac @@ -2257,11 +2257,9 @@ AC_DEFUN([PY_CHECK_CC_WARNING], [ ]) # tweak BASECFLAGS based on compiler and platform -AS_VAR_IF([with_strict_overflow], [no], - [BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"]) - AS_VAR_IF([with_strict_overflow], [yes], - [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"]) + [BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"], + [BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"]) case $GCC in yes) From 86d01d64e6f6c6aeafecda9be1355ea07095f7bf Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sat, 17 Sep 2022 16:39:24 +0800 Subject: [PATCH 06/23] Even I can't remember the f --- configure | 20 ++++++++++---------- configure.ac | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/configure b/configure index d08d030ac649c2..e114372d5d3e26 100755 --- a/configure +++ b/configure @@ -1056,7 +1056,7 @@ with_assertions enable_optimizations with_lto enable_bolt -with_fstrict_overflow +with_strict_overflow with_dsymutil with_address_sanitizer with_memory_sanitizer @@ -1829,7 +1829,7 @@ Optional Packages: --with-lto=[full|thin|no|yes] enable Link-Time-Optimization in any build (default is no) - --with-fstrict-overflow choose between -fstrict-overflow or + --with-strict-overflow choose between -fstrict-overflow or -fno-strict-overflow (default is no for backwards compatibility) --with-dsymutil link debug information into final executable with @@ -8390,18 +8390,18 @@ fi $as_echo "$ac_cv_cc_supports_fstrict_overflow" >&6; } CFLAGS=$save_CFLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-fstrict-overflow" >&5 -$as_echo_n "checking for --with-fstrict-overflow... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-strict-overflow" >&5 +$as_echo_n "checking for --with-strict-overflow... " >&6; } -# Check whether --with-fstrict-overflow was given. -if test "${with_fstrict_overflow+set}" = set; then : - withval=$with_fstrict_overflow; +# Check whether --with-strict-overflow was given. +if test "${with_strict_overflow+set}" = set; then : + withval=$with_strict_overflow; else - with_strict_overflow=no + with_fstrict_overflow=no fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_fstrict_overflow" >&5 -$as_echo "$with_fstrict_overflow" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_strict_overflow" >&5 +$as_echo "$with_strict_overflow" >&6; } # Check if CC supports -Og optimization level save_CFLAGS=$CFLAGS diff --git a/configure.ac b/configure.ac index 08848f6015bb60..9d5d65265ddef8 100644 --- a/configure.ac +++ b/configure.ac @@ -2092,13 +2092,13 @@ AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], ) _RESTORE_VAR([CFLAGS]) -AC_MSG_CHECKING(for --with-fstrict-overflow) -AC_ARG_WITH(fstrict-overflow, +AC_MSG_CHECKING(for --with-strict-overflow) +AC_ARG_WITH(strict-overflow, AS_HELP_STRING( - [--with-fstrict-overflow], + [--with-strict-overflow], [choose between -fstrict-overflow or -fno-strict-overflow (default is no for backwards compatibility)]),, - with_strict_overflow=no) -AC_MSG_RESULT($with_fstrict_overflow) + with_fstrict_overflow=no) +AC_MSG_RESULT($with_strict_overflow) # Check if CC supports -Og optimization level _SAVE_VAR([CFLAGS]) From 2b6ade918ca233ae13d943fff879bf8d1cd7622c Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sun, 18 Sep 2022 17:39:10 +0800 Subject: [PATCH 07/23] Fix typo --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index bc70a2fac38a2d..19b24e044440ac 100755 --- a/configure +++ b/configure @@ -8473,7 +8473,7 @@ $as_echo_n "checking for --with-strict-overflow... " >&6; } if test "${with_strict_overflow+set}" = set; then : withval=$with_strict_overflow; else - with_fstrict_overflow=no + with_strict_overflow=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_strict_overflow" >&5 diff --git a/configure.ac b/configure.ac index 03150f7ef74852..f71712271dc1f4 100644 --- a/configure.ac +++ b/configure.ac @@ -2105,7 +2105,7 @@ AC_ARG_WITH(strict-overflow, AS_HELP_STRING( [--with-strict-overflow], [choose between -fstrict-overflow or -fno-strict-overflow (default is no for backwards compatibility)]),, - with_fstrict_overflow=no) + with_strict_overflow=no) AC_MSG_RESULT($with_strict_overflow) # Check if CC supports -Og optimization level From e5cff7b5e72105a25ecdb22216618aecb79989dc Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Sun, 18 Sep 2022 17:43:58 +0800 Subject: [PATCH 08/23] News --- .../next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst index 7e0ea17408ecf5..ffa3b72d2b7165 100644 --- a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -1 +1 @@ -Explicitly mark C modules that need defined signed integer overflow. (So that in future we can turn off the blanket `-fwrapv`, and enjoy more C compiler optimizations.) +Explicitly mark C modules that need defined signed integer overflow, and set up machinery for `-fstrict-overflow`. From a2bb1e96cd0a212a94489ef2b6eec1fc426eb904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Mon, 19 Sep 2022 08:04:05 +0800 Subject: [PATCH 09/23] Update Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst Co-authored-by: C.A.M. Gerlach --- .../next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst index ffa3b72d2b7165..dab5915d038f13 100644 --- a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -1 +1,2 @@ -Explicitly mark C modules that need defined signed integer overflow, and set up machinery for `-fstrict-overflow`. +Explicitly mark C modules that need defined signed integer overflow, +and set up machinery for ``-fstrict-overflow``. From 8538fe6f311d9f8db12eca449bbdaaa632efd607 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 21 Sep 2022 09:52:14 +0800 Subject: [PATCH 10/23] Fix comments and quoting --- configure | 6 +----- configure.ac | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/configure b/configure index 19b24e044440ac..6e53f69163e730 100755 --- a/configure +++ b/configure @@ -1830,8 +1830,7 @@ Optional Packages: enable Link-Time-Optimization in any build (default is no) --with-strict-overflow choose between -fstrict-overflow or - -fno-strict-overflow (default is no for backwards - compatibility) + -fno-strict-overflow (default is no) --with-dsymutil link debug information into final executable with dsymutil in macOS (default is no) --with-address-sanitizer @@ -8425,9 +8424,6 @@ case $CC in fi esac -# Historically, some of our code assumed that signed integer overflow -# is defined behaviour via twos-complement. Prepare some flags so that -# we can mark the modules that still do so. save_CFLAGS=$CFLAGS CFLAGS="-fstrict-overflow -fno-strict-overflow" { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -fstrict-overflow and -fno-strict-overflow" >&5 diff --git a/configure.ac b/configure.ac index f71712271dc1f4..37588d5ae7cd7b 100644 --- a/configure.ac +++ b/configure.ac @@ -2080,9 +2080,9 @@ case $CC in fi esac -# Historically, some of our code assumed that signed integer overflow -# is defined behaviour via twos-complement. Prepare some flags so that -# we can mark the modules that still do so. +dnl Historically, some of our code assumed that signed integer overflow +dnl is defined behaviour via twos-complement. Prepare some flags so that +dnl we can mark the modules that still do so. _SAVE_VAR([CFLAGS]) CFLAGS="-fstrict-overflow -fno-strict-overflow" AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], @@ -2104,9 +2104,9 @@ AC_MSG_CHECKING(for --with-strict-overflow) AC_ARG_WITH(strict-overflow, AS_HELP_STRING( [--with-strict-overflow], - [choose between -fstrict-overflow or -fno-strict-overflow (default is no for backwards compatibility)]),, + [choose between -fstrict-overflow or -fno-strict-overflow (default is no)]),, with_strict_overflow=no) -AC_MSG_RESULT($with_strict_overflow) +AC_MSG_RESULT([$with_strict_overflow]) # Check if CC supports -Og optimization level _SAVE_VAR([CFLAGS]) From 26956f3d36e74b9a67b3f49c188247bff2b2c5c7 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 21 Sep 2022 09:56:36 +0800 Subject: [PATCH 11/23] Fix News --- .../next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst index dab5915d038f13..1b28b4f681e909 100644 --- a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -1,2 +1,2 @@ -Explicitly mark C modules that need defined signed integer overflow, -and set up machinery for ``-fstrict-overflow``. +Explicitly mark C extension modules that need defined signed integer overflow, +and add a configure option ``--with-strict-overflow``. From 88a2c768e8271fa2fa14a527663dfbd3bc683f00 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Wed, 21 Sep 2022 09:58:40 +0800 Subject: [PATCH 12/23] _testcapi is strict-overflow clean now --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 6e53f69163e730..acea9e66cce2bb 100755 --- a/configure +++ b/configure @@ -27847,7 +27847,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_STATE=$py_cv_module__testcapi$as_nl" if test "x$py_cv_module__testcapi" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__TESTCAPI_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" + fi diff --git a/configure.ac b/configure.ac index 37588d5ae7cd7b..0be121139aaa6a 100644 --- a/configure.ac +++ b/configure.ac @@ -7380,7 +7380,7 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes], [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS]) dnl test modules -PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes], [], [$NO_STRICT_OVERFLOW_CFLAGS]) +PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes]) From d45d6ae8acaf3bf1a0f637bcc30a5329b4ee9933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Mon, 3 Oct 2022 18:44:33 +0800 Subject: [PATCH 13/23] Update configure.ac Co-authored-by: Erlend E. Aasland --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 4bddaec133952a..b732c9e693bf35 100644 --- a/configure.ac +++ b/configure.ac @@ -2102,8 +2102,8 @@ AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], ) _RESTORE_VAR([CFLAGS]) -AC_MSG_CHECKING(for --with-strict-overflow) -AC_ARG_WITH(strict-overflow, +AC_MSG_CHECKING([for --with-strict-overflow]) +AC_ARG_WITH([strict-overflow], AS_HELP_STRING( [--with-strict-overflow], [choose between -fstrict-overflow or -fno-strict-overflow (default is no)]),, From f6d3113b8c5d5794f6a8b75c489ae89a97519ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Mon, 3 Oct 2022 18:44:50 +0800 Subject: [PATCH 14/23] Update configure.ac Co-authored-by: Erlend E. Aasland --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index b732c9e693bf35..164f428bd1c895 100644 --- a/configure.ac +++ b/configure.ac @@ -2106,8 +2106,8 @@ AC_MSG_CHECKING([for --with-strict-overflow]) AC_ARG_WITH([strict-overflow], AS_HELP_STRING( [--with-strict-overflow], - [choose between -fstrict-overflow or -fno-strict-overflow (default is no)]),, - with_strict_overflow=no) + [choose between -fstrict-overflow or -fno-strict-overflow (default is no)]),[], + [with_strict_overflow=no]) AC_MSG_RESULT([$with_strict_overflow]) # Check if CC supports -Og optimization level From d6423c7e3f83d58a722f823141a849266d243808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Mon, 3 Oct 2022 18:45:29 +0800 Subject: [PATCH 15/23] Update configure.ac Co-authored-by: Erlend E. Aasland --- configure.ac | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 164f428bd1c895..5b452ebb23920f 100644 --- a/configure.ac +++ b/configure.ac @@ -2083,8 +2083,9 @@ case $CC in esac dnl Historically, some of our code assumed that signed integer overflow -dnl is defined behaviour via twos-complement. Prepare some flags so that -dnl we can mark the modules that still do so. +dnl is defined behaviour via twos-complement. +dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support. +dnl Pass the latter to modules that depend on such behaviour. _SAVE_VAR([CFLAGS]) CFLAGS="-fstrict-overflow -fno-strict-overflow" AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], From 3b4046ffeb6e3f51495fda5970947c981a741666 Mon Sep 17 00:00:00 2001 From: Matthias Goergens Date: Mon, 3 Oct 2022 19:05:21 +0800 Subject: [PATCH 16/23] _struct is already strict-overflow safe --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index e273f41ac3b906..d7152ce841e55e 100755 --- a/configure +++ b/configure @@ -26213,7 +26213,7 @@ fi as_fn_append MODULE_BLOCK "MODULE__STRUCT_STATE=$py_cv_module__struct$as_nl" if test "x$py_cv_module__struct" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE__STRUCT_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" + fi diff --git a/configure.ac b/configure.ac index 5b452ebb23920f..a7d5d483369e21 100644 --- a/configure.ac +++ b/configure.ac @@ -7258,7 +7258,7 @@ PY_STDLIB_MOD_SIMPLE([_posixsubprocess]) PY_STDLIB_MOD_SIMPLE([_queue]) PY_STDLIB_MOD_SIMPLE([_random]) PY_STDLIB_MOD_SIMPLE([select]) -PY_STDLIB_MOD_SIMPLE([_struct], [$NO_STRICT_OVERFLOW_CFLAGS]) +PY_STDLIB_MOD_SIMPLE([_struct]) PY_STDLIB_MOD_SIMPLE([_typing]) PY_STDLIB_MOD_SIMPLE([_xxsubinterpreters]) PY_STDLIB_MOD_SIMPLE([_zoneinfo]) From 2714d619ff06f081e8c114539039d3b862c51c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 11 Oct 2022 19:52:37 +0800 Subject: [PATCH 17/23] We fixed audioop, so remove it from list of exceptions --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index d7152ce841e55e..7b7a65f0905e72 100755 --- a/configure +++ b/configure @@ -26363,7 +26363,7 @@ fi as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_STATE=$py_cv_module_audioop$as_nl" if test "x$py_cv_module_audioop" = xyes; then : - as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_CFLAGS=$NO_STRICT_OVERFLOW_CFLAGS$as_nl" + as_fn_append MODULE_BLOCK "MODULE_AUDIOOP_LDFLAGS=$LIBM$as_nl" fi diff --git a/configure.ac b/configure.ac index a7d5d483369e21..1c4a7189574623 100644 --- a/configure.ac +++ b/configure.ac @@ -7272,7 +7272,7 @@ PY_STDLIB_MOD([_posixshmem], [$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS]) dnl needs libm -PY_STDLIB_MOD_SIMPLE([audioop], [$NO_STRICT_OVERFLOW_CFLAGS], [$LIBM]) +PY_STDLIB_MOD_SIMPLE([audioop], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([_statistics], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([cmath], [], [$LIBM]) PY_STDLIB_MOD_SIMPLE([math], [], [$LIBM]) From 6236fb9659dd44d273d190e625e24169aa3de8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Tue, 11 Oct 2022 19:58:22 +0800 Subject: [PATCH 18/23] Document our --with-strict-overflow --- Doc/using/configure.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index b99d9bdaa3f007..5a340a464ac9f7 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -278,6 +278,11 @@ also be used to improve performance. Enable C-level code profiling with ``gprof`` (disabled by default). +.. cmdoption:: --with-strict-overflow + + Add `-fstrict-overflow` to the C compiler flags (by default we add + `-fno-strict-overflow` instead). + .. _debug-build: From ca6e6ba4d3321f0201d0d3e58c1aa5c1f1bbee76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Wed, 12 Oct 2022 16:31:26 +0800 Subject: [PATCH 19/23] Update Doc/using/configure.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/using/configure.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 5a340a464ac9f7..41f135ab7644c1 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -280,8 +280,8 @@ also be used to improve performance. .. cmdoption:: --with-strict-overflow - Add `-fstrict-overflow` to the C compiler flags (by default we add - `-fno-strict-overflow` instead). + Add ``-fstrict-overflow`` to the C compiler flags (by default we add + ``-fno-strict-overflow`` instead). .. _debug-build: From fa147636d746e9ab14942341ffd40779edc2614b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=B6rgens?= Date: Wed, 12 Oct 2022 16:31:36 +0800 Subject: [PATCH 20/23] Update Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- .../next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst index 1b28b4f681e909..cd30dd90a29463 100644 --- a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -1,2 +1,2 @@ Explicitly mark C extension modules that need defined signed integer overflow, -and add a configure option ``--with-strict-overflow``. +and add a configure option :option:`--with-strict-overflow`. From 9f34477fdce5200106a179a6734632dd102dbccc Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Thu, 19 Jan 2023 22:33:44 -0800 Subject: [PATCH 21/23] improve help message --- configure | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 7b7a65f0905e72..0df6acb5ff70d5 100755 --- a/configure +++ b/configure @@ -1829,7 +1829,7 @@ Optional Packages: --with-lto=[full|thin|no|yes] enable Link-Time-Optimization in any build (default is no) - --with-strict-overflow choose between -fstrict-overflow or + --with-strict-overflow if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no) --with-dsymutil link debug information into final executable with dsymutil in macOS (default is no) diff --git a/configure.ac b/configure.ac index 1c4a7189574623..d8435a8eacc3fb 100644 --- a/configure.ac +++ b/configure.ac @@ -2107,7 +2107,7 @@ AC_MSG_CHECKING([for --with-strict-overflow]) AC_ARG_WITH([strict-overflow], AS_HELP_STRING( [--with-strict-overflow], - [choose between -fstrict-overflow or -fno-strict-overflow (default is no)]),[], + [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]),[], [with_strict_overflow=no]) AC_MSG_RESULT([$with_strict_overflow]) From e526f6ef79a7eeafcdef62879c437e2e45a2269e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 22 Jan 2023 18:13:31 -0800 Subject: [PATCH 22/23] fix cache, add warning --- ...2-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst | 1 + configure | 24 ++++++++------ configure.ac | 32 ++++++++++++------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst index cd30dd90a29463..865cfde8b06359 100644 --- a/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst +++ b/Misc/NEWS.d/next/Build/2022-09-14-10-38-15.gh-issue-96821.Zk2a9c.rst @@ -1,2 +1,3 @@ Explicitly mark C extension modules that need defined signed integer overflow, and add a configure option :option:`--with-strict-overflow`. +Patch by Matthias Görgens and Shantanu Jain. diff --git a/configure b/configure index 1aac08af48604a..4c16e0f1e76109 100755 --- a/configure +++ b/configure @@ -8355,7 +8355,6 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - int main () { @@ -8363,17 +8362,11 @@ main () ; return 0; } - _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - - STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" - NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow" - + ac_cv_cc_supports_fstrict_overflow=yes else - - STRICT_OVERFLOW_CFLAGS="" - NO_STRICT_OVERFLOW_CFLAGS="" + ac_cv_cc_supports_fstrict_overflow=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext @@ -8383,14 +8376,27 @@ fi $as_echo "$ac_cv_cc_supports_fstrict_overflow" >&6; } CFLAGS=$save_CFLAGS +if test "x$ac_cv_cc_supports_fstrict_overflow" = xyes; then : + STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" + NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow" +else + STRICT_OVERFLOW_CFLAGS="" + NO_STRICT_OVERFLOW_CFLAGS="" +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-strict-overflow" >&5 $as_echo_n "checking for --with-strict-overflow... " >&6; } # Check whether --with-strict-overflow was given. if test "${with_strict_overflow+set}" = set; then : withval=$with_strict_overflow; + if test "x$ac_cv_cc_supports_fstrict_overflow" = xno; then : + as_fn_error $? "--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow" "$LINENO" 5 +fi + else with_strict_overflow=no + fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_strict_overflow" >&5 diff --git a/configure.ac b/configure.ac index 101b0fec343e0c..8c595265af3c96 100644 --- a/configure.ac +++ b/configure.ac @@ -2080,24 +2080,34 @@ CFLAGS="-fstrict-overflow -fno-strict-overflow" AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow], [ac_cv_cc_supports_fstrict_overflow], AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM([[]], [[]]) - ],[ - STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" - NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow" - ],[ - STRICT_OVERFLOW_CFLAGS="" - NO_STRICT_OVERFLOW_CFLAGS="" - ]) + [AC_LANG_PROGRAM([[]], [[]])], + [ac_cv_cc_supports_fstrict_overflow=yes], + [ac_cv_cc_supports_fstrict_overflow=no] + ) ) _RESTORE_VAR([CFLAGS]) +AS_VAR_IF([ac_cv_cc_supports_fstrict_overflow], [yes], + [STRICT_OVERFLOW_CFLAGS="-fstrict-overflow" + NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow"], + [STRICT_OVERFLOW_CFLAGS="" + NO_STRICT_OVERFLOW_CFLAGS=""]) + AC_MSG_CHECKING([for --with-strict-overflow]) AC_ARG_WITH([strict-overflow], AS_HELP_STRING( [--with-strict-overflow], - [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]),[], - [with_strict_overflow=no]) + [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)] + ), + [ + AS_VAR_IF( + [ac_cv_cc_supports_fstrict_overflow], [no], + [AC_MSG_ERROR([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])], + [] + ) + ], + [with_strict_overflow=no] +) AC_MSG_RESULT([$with_strict_overflow]) # Check if CC supports -Og optimization level From db665abd419e20c49aedfd84c6837bdcaffb7b7d Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 22 Jan 2023 18:18:55 -0800 Subject: [PATCH 23/23] use warn, not error --- configure | 3 ++- configure.ac | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 4c16e0f1e76109..06a6d58dbcdee1 100755 --- a/configure +++ b/configure @@ -8391,7 +8391,8 @@ $as_echo_n "checking for --with-strict-overflow... " >&6; } if test "${with_strict_overflow+set}" = set; then : withval=$with_strict_overflow; if test "x$ac_cv_cc_supports_fstrict_overflow" = xno; then : - as_fn_error $? "--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow" "$LINENO" 5 + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-strict-overflow=yes requires a compiler that supports -fstrict-overflow" >&5 +$as_echo "$as_me: WARNING: --with-strict-overflow=yes requires a compiler that supports -fstrict-overflow" >&2;} fi else diff --git a/configure.ac b/configure.ac index 8c595265af3c96..0be030a2bf77df 100644 --- a/configure.ac +++ b/configure.ac @@ -2102,7 +2102,7 @@ AC_ARG_WITH([strict-overflow], [ AS_VAR_IF( [ac_cv_cc_supports_fstrict_overflow], [no], - [AC_MSG_ERROR([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])], + [AC_MSG_WARN([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])], [] ) ],