From bd20441a24ea1f72d476441d8bddfbcda5373e3e Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 09:30:42 +0200 Subject: [PATCH 1/9] gh-89640: properly detect float word ordering on Linux Prerequisite: python/cpython-devcontainers#23 autoconf-archive patch by Dan Amelang. --- aclocal.m4 | 61 ++++++++++++++++++++++++++++++++++++++++++++++++------ configure | 19 ++++++++++++----- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 832aec19f48f17..b082a5b1bc5e07 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -41,32 +41,81 @@ m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun # If neither value is found, the user is instructed to specify the # ordering. # +# Early versions of this macro (i.e., before serial 12) would not work +# when interprocedural optimization (via link-time optimization) was +# enabled. This would happen when, say, the GCC/clang "-flto" flag, or the +# ICC "-ipo" flag was used, for example. The problem was that under +# these conditions, the compiler did not allocate for and write the special +# float value in the data segment of the object file, since doing so might +# not prove optimal once more context was available. Thus, the special value +# (in platform-dependent binary form) could not be found in the object file, +# and the macro would fail. +# +# The solution to the above problem was to: +# +# 1) Compile and link a whole test program rather than just compile an +# object file. This ensures that we reach the point where even an +# interprocedural optimizing compiler writes values to the data segment. +# +# 2) Add code that requires the compiler to write the special value to +# the data segment, as opposed to "optimizing away" the variable's +# allocation. This could be done via compiler keywords or options, but +# it's tricky to make this work for all versions of all compilers with +# all optimization settings. The chosen solution was to make the exit +# code of the test program depend on the storing of the special value +# in memory (in the data segment). Because the exit code can be +# verified, any compiler that aspires to be correct will produce a +# program binary that contains the value, which the macro can then find. +# +# How does the exit code depend on the special value residing in memory? +# Memory, unlike variables and registers, can be addressed indirectly at run +# time. The exit code of this test program is a result of indirectly reading +# and writing to the memory region where the special value is supposed to +# reside. The actual memory addresses used and the values to be written are +# derived from the the program input ("argv") and are therefore not known at +# compile or link time. The compiler has no choice but to defer the +# computation to run time, and to prepare by allocating and populating the +# data segment with the special value. For further details, refer to the +# source code of the test program. +# +# Note that the test program is never meant to be run. It only exists to host +# a double float value in a given platform's binary format. Thus, error +# handling is not included. +# # LICENSE # -# Copyright (c) 2008 Daniel Amelang +# Copyright (c) 2008, 2023 Daniel Amelang # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice # and this notice are preserved. This file is offered as-is, without any # warranty. -#serial 11 +#serial 12 AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN], [AC_CACHE_CHECK(whether float word ordering is bigendian, ax_cv_c_float_words_bigendian, [ ax_cv_c_float_words_bigendian=unknown -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + +#include + +static double m[] = {9.090423496703681e+223, 0.0}; -double d = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0; +int main (int argc, char *argv[]) +{ + m[atoi (argv[1])] += atof (argv[2]); + return m[atoi (argv[3])] > 0.0; +} ]])], [ -if grep noonsees conftest.$ac_objext >/dev/null ; then +if grep noonsees conftest$EXEEXT >/dev/null ; then ax_cv_c_float_words_bigendian=yes fi -if grep seesnoon conftest.$ac_objext >/dev/null ; then +if grep seesnoon conftest$EXEEXT >/dev/null ; then if test "$ax_cv_c_float_words_bigendian" = unknown; then ax_cv_c_float_words_bigendian=no else diff --git a/configure b/configure index 17c70d25f9e70c..79bc717eea2f7c 100755 --- a/configure +++ b/configure @@ -24123,18 +24123,26 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -double d = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0; +#include + +static double m[] = {9.090423496703681e+223, 0.0}; + +int main (int argc, char *argv[]) +{ + m[atoi (argv[1])] += atof (argv[2]); + return m[atoi (argv[3])] > 0.0; +} _ACEOF -if ac_fn_c_try_compile "$LINENO" +if ac_fn_c_try_link "$LINENO" then : -if grep noonsees conftest.$ac_objext >/dev/null ; then +if grep noonsees conftest$EXEEXT >/dev/null ; then ax_cv_c_float_words_bigendian=yes fi -if grep seesnoon conftest.$ac_objext >/dev/null ; then +if grep seesnoon conftest$EXEEXT >/dev/null ; then if test "$ax_cv_c_float_words_bigendian" = unknown; then ax_cv_c_float_words_bigendian=no else @@ -24144,7 +24152,8 @@ fi fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_c_float_words_bigendian" >&5 printf "%s\n" "$ax_cv_c_float_words_bigendian" >&6; } From f99e2db95275d38c853a4c32c411c04afc3e5306 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 09:38:00 +0200 Subject: [PATCH 2/9] NEWS --- .../next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst diff --git a/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst b/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst new file mode 100644 index 00000000000000..1ff910b4f04bbd --- /dev/null +++ b/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst @@ -0,0 +1 @@ +Improved detection of float word ordering on Linux. From 7edf34204161e756b45e958e58c304a6daf0f071 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 09:40:01 +0200 Subject: [PATCH 3/9] Also update regen-configure --- Tools/build/regen-configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/build/regen-configure.sh b/Tools/build/regen-configure.sh index 1a24b07c3ff707..c3df291745a09e 100755 --- a/Tools/build/regen-configure.sh +++ b/Tools/build/regen-configure.sh @@ -5,7 +5,7 @@ set -e -x # The check_generated_files job of .github/workflows/build.yml must kept in # sync with this script. Use the same container image than the job so the job # doesn't need to run autoreconf in a container. -IMAGE="ghcr.io/python/autoconf:2024.10.11.11293396815" +IMAGE="ghcr.io/python/autoconf:2024.10.16.11360930377" AUTORECONF="autoreconf -ivf -Werror" WORK_DIR="/src" From d55555c8b9af88bee8c397ee470783e0c9bdaf43 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 11:20:59 +0200 Subject: [PATCH 4/9] Improve NEWS wording --- .../next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst b/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst index 1ff910b4f04bbd..5aba2c789b6842 100644 --- a/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst +++ b/Misc/NEWS.d/next/Build/2024-10-16-09-37-51.gh-issue-89640.UDsW-j.rst @@ -1 +1,2 @@ -Improved detection of float word ordering on Linux. +Improve detection of float word ordering on Linux when link-time optimizations +are enabled. From 246553547b73b8e7477427c17df61e5c23bb3b87 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 12:23:13 +0200 Subject: [PATCH 5/9] Fix bug in damelang's patch --- aclocal.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index b082a5b1bc5e07..1420867e13d9eb 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -112,10 +112,10 @@ int main (int argc, char *argv[]) ]])], [ -if grep noonsees conftest$EXEEXT >/dev/null ; then +if grep noonsees conftest.$ac_objext >/dev/null ; then ax_cv_c_float_words_bigendian=yes fi -if grep seesnoon conftest$EXEEXT >/dev/null ; then +if grep seesnoon conftest.$ac_objext >/dev/null ; then if test "$ax_cv_c_float_words_bigendian" = unknown; then ax_cv_c_float_words_bigendian=no else From cfe8fd9130ed25e688a4dd93dcf6c0dad150bdcf Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 16 Oct 2024 12:27:27 +0200 Subject: [PATCH 6/9] Revert commit 246553547 --- aclocal.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 1420867e13d9eb..b082a5b1bc5e07 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -112,10 +112,10 @@ int main (int argc, char *argv[]) ]])], [ -if grep noonsees conftest.$ac_objext >/dev/null ; then +if grep noonsees conftest$EXEEXT >/dev/null ; then ax_cv_c_float_words_bigendian=yes fi -if grep seesnoon conftest.$ac_objext >/dev/null ; then +if grep seesnoon conftest$EXEEXT >/dev/null ; then if test "$ax_cv_c_float_words_bigendian" = unknown; then ax_cv_c_float_words_bigendian=no else From c51c2b4db63d0639a80d5ac7e0cc4851d6a9ef7c Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 21 Oct 2024 10:49:23 +0200 Subject: [PATCH 7/9] gh-125698: Autoconf: Sync EXEEXT and ac_exeext --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index d5bc739c34c90f..1534144bab3400 100644 --- a/configure.ac +++ b/configure.ac @@ -1339,6 +1339,9 @@ AC_ARG_WITH([suffix], ]) AC_MSG_RESULT([$EXEEXT]) +# Make sure we keep EXEEXT and ac_exeext sync'ed. +AS_VAR_SET([ac_exeext], [$EXEEXT]) + # Test whether we're running on a non-case-sensitive system, in which # case we give a warning if no ext is given AC_SUBST([BUILDEXEEXT]) From 08cb8a9437daf3ee2f45957fa3e161bddf5161ab Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 25 Oct 2024 23:52:09 +0200 Subject: [PATCH 8/9] Regen configure --- configure | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure b/configure index a95c6cc3371f76..97113f1fd967fe 100755 --- a/configure +++ b/configure @@ -7323,6 +7323,9 @@ fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $EXEEXT" >&5 printf "%s\n" "$EXEEXT" >&6; } +# Make sure we keep EXEEXT and ac_exeext sync'ed. +ac_exeext=$EXEEXT + # Test whether we're running on a non-case-sensitive system, in which # case we give a warning if no ext is given From 52d630c06c4d1cac28b1595c901d9069df55b38b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 26 Oct 2024 00:00:47 +0200 Subject: [PATCH 9/9] Also update CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88898895d15ad0..09b8858d09f712 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: # reproducible: to get the same tools versions (autoconf, aclocal, ...) runs-on: ubuntu-24.04 container: - image: ghcr.io/python/autoconf:2024.10.11.11293396815 + image: ghcr.io/python/autoconf:2024.10.16.11360930377 timeout-minutes: 60 needs: check_source if: needs.check_source.outputs.run_tests == 'true'