Skip to content

Commit

Permalink
[3.12] gh-89640: harden float word ordering (#125571 and #126387) (#1…
Browse files Browse the repository at this point in the history
…26430)

Properly detect float word ordering on Linux (gh-125571)

autoconf-archive patch by Dan Amelang.

(cherry picked from commit 26d6277)

Hardcode WASM float word ordering to little endian (gh-126387)

(cherry picked from commit 532fc08)
  • Loading branch information
erlend-aasland authored Nov 5, 2024
1 parent 786886a commit b00887d
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve detection of float word ordering on Linux when link-time optimizations
are enabled.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hard-code float word ordering as little endian on WASM.
2 changes: 1 addition & 1 deletion Tools/build/regen-configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.06.11200919239"
IMAGE="ghcr.io/python/autoconf:2024.10.16.11360930377"
AUTORECONF="autoreconf -ivf -Werror"

WORK_DIR="/src"
Expand Down
61 changes: 55 additions & 6 deletions aclocal.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 34 additions & 32 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 20 additions & 22 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -5679,28 +5679,26 @@ AS_VAR_IF([ac_cv_gcc_asm_for_x64], [yes], [
# * Check for various properties of floating point *
# **************************************************

AX_C_FLOAT_WORDS_BIGENDIAN
if test "$ax_cv_c_float_words_bigendian" = "yes"
then
AC_DEFINE([DOUBLE_IS_BIG_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format, stored
with the most significant byte first])
elif test "$ax_cv_c_float_words_bigendian" = "no"
then
AC_DEFINE([DOUBLE_IS_LITTLE_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format, stored
with the least significant byte first])
else
# Some ARM platforms use a mixed-endian representation for doubles.
# While Python doesn't currently have full support for these platforms
# (see e.g., issue 1762561), we can at least make sure that float <-> string
# conversions work.
# FLOAT_WORDS_BIGENDIAN doesn't actually detect this case, but if it's not big
# or little, then it must be this?
AC_DEFINE([DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format, stored
in ARM mixed-endian order (byte order 45670123)])
fi
AX_C_FLOAT_WORDS_BIGENDIAN(
[AC_DEFINE([DOUBLE_IS_BIG_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format,
stored with the most significant byte first])],
[AC_DEFINE([DOUBLE_IS_LITTLE_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format,
stored with the least significant byte first])],
[AS_CASE([$host_cpu],
[*arm*], [# Some ARM platforms use a mixed-endian representation for
# doubles. While Python doesn't currently have full support
# for these platforms (see e.g., issue 1762561), we can at
# least make sure that float <-> string conversions work.
# FLOAT_WORDS_BIGENDIAN doesn't actually detect this case,
# but if it's not big or little, then it must be this?
AC_DEFINE([DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format,
stored in ARM mixed-endian order (byte order 45670123)])],
[wasm*], [AC_DEFINE([DOUBLE_IS_LITTLE_ENDIAN_IEEE754], [1],
[Define if C doubles are 64-bit IEEE 754 binary format,
stored with the least significant byte first])])])

# The short float repr introduced in Python 3.1 requires the
# correctly-rounded string <-> double conversion functions from
Expand Down
4 changes: 0 additions & 4 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
/* Define if --enable-ipv6 is specified */
#undef ENABLE_IPV6

/* Define to 1 if your system stores words within floats with the most
significant word first */
#undef FLOAT_WORDS_BIGENDIAN

/* Define if getpgrp() must be called as getpgrp(0). */
#undef GETPGRP_HAVE_ARG

Expand Down

0 comments on commit b00887d

Please sign in to comment.