diff options
author | Ross Burton <ross.burton@intel.com> | 2018-10-12 14:44:03 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-14 09:20:56 +0100 |
commit | cd9b883f960c7a654b80ef68481fb6dc2f23d64a (patch) | |
tree | 91cb0ce8bc01117e57d6e83fee3cb3c3688a509a /meta | |
parent | 64ff0a5e6c76803e76256d941acbe574ad2a33d8 (diff) | |
download | poky-cd9b883f960c7a654b80ef68481fb6dc2f23d64a.tar.gz |
python: don't use runtime checks to identify float endianism
Python uses AC_RUN_IFELSE to determine the byte order for floats and doubles,
and falls back onto "I don't know" if it can't run code. This results in
crippled floating point numbers in Python, and the regression tests fail.
Instead of running code, take a macro from autoconf-archive which compiles C
with a special double in which has an ASCII representation, and then greps the
binary to identify the format.
This is essentially a backport of the Python 3 patch in oe-core 1781b87.
(From OE-Core rev: 94cea72a23a374eb616d5642977b45172537beac)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/recipes-devtools/python/python/float-endian.patch | 216 | ||||
-rw-r--r-- | meta/recipes-devtools/python/python_2.7.15.bb | 1 |
2 files changed, 217 insertions, 0 deletions
diff --git a/meta/recipes-devtools/python/python/float-endian.patch b/meta/recipes-devtools/python/python/float-endian.patch new file mode 100644 index 0000000000..8a5c90aec4 --- /dev/null +++ b/meta/recipes-devtools/python/python/float-endian.patch | |||
@@ -0,0 +1,216 @@ | |||
1 | Python uses AC_RUN_IFELSE to determine the byte order for floats and doubles, | ||
2 | and falls back onto "I don't know" if it can't run code. This results in | ||
3 | crippled floating point numbers in Python, and the regression tests fail. | ||
4 | |||
5 | Instead of running code, take a macro from autoconf-archive which compiles C | ||
6 | with a special double in which has an ASCII representation, and then greps the | ||
7 | binary to identify the format. | ||
8 | |||
9 | Upstream-Status: Backport | ||
10 | Signed-off-by: Ross Burton <ross.burton@intel.com> | ||
11 | |||
12 | From 253f47b28120c42cfe53a4e2f5ed0ab0ed469deb Mon Sep 17 00:00:00 2001 | ||
13 | From: Ross Burton <ross@burtonini.com> | ||
14 | Date: Wed, 19 Sep 2018 07:25:48 +0100 | ||
15 | Subject: [PATCH] closes bpo-34585: Don't do runtime test to get float byte | ||
16 | order. (GH-9085) | ||
17 | |||
18 | Currently configure.ac uses AC_RUN_IFELSE to determine the byte order of doubles, but this silently fails under cross compilation and Python doesn't do floats properly. | ||
19 | |||
20 | Instead, steal a macro from autoconf-archive which compiles code using magic doubles (which encode to ASCII) and grep for the representation in the binary. | ||
21 | |||
22 | RFC because this doesn't yet handle the weird ancient ARMv4 OABI 'mixed-endian' encoding properly. This encoding is ancient and I don't believe the union of "Python 3.8 users" and "OABI users" has anything in. Should the support for this just be dropped too? Alternatively, someone will need to find an OABI toolchain to verify the encoding of the magic double. | ||
23 | |||
24 | Signed-off-by: Ross Burton <ross.burton@intel.com> | ||
25 | --- | ||
26 | .../Build/2018-09-18-16-28-31.bpo-34585.CGMu0h.rst | 3 + | ||
27 | configure.ac | 76 ++++---------------- | ||
28 | m4/ax_c_float_words_bigendian.m4 | 83 ++++++++++++++++++++++ | ||
29 | 3 files changed, 99 insertions(+), 63 deletions(-) | ||
30 | create mode 100644 Misc/NEWS.d/next/Build/2018-09-18-16-28-31.bpo-34585.CGMu0h.rst | ||
31 | create mode 100644 m4/ax_c_float_words_bigendian.m4 | ||
32 | |||
33 | diff --git a/configure.ac b/configure.ac | ||
34 | index 913d5469d0..7672735396 100644 | ||
35 | --- a/configure.ac | ||
36 | +++ b/configure.ac | ||
37 | @@ -3835,74 +3835,24 @@ fi], | ||
38 | # * Check for various properties of floating point * | ||
39 | # ************************************************** | ||
40 | |||
41 | -AC_MSG_CHECKING(whether C doubles are little-endian IEEE 754 binary64) | ||
42 | -AC_CACHE_VAL(ac_cv_little_endian_double, [ | ||
43 | -AC_RUN_IFELSE([AC_LANG_SOURCE([[ | ||
44 | -#include <string.h> | ||
45 | -int main() { | ||
46 | - double x = 9006104071832581.0; | ||
47 | - if (memcmp(&x, "\x05\x04\x03\x02\x01\xff\x3f\x43", 8) == 0) | ||
48 | - return 0; | ||
49 | - else | ||
50 | - return 1; | ||
51 | -} | ||
52 | -]])], | ||
53 | -[ac_cv_little_endian_double=yes], | ||
54 | -[ac_cv_little_endian_double=no], | ||
55 | -[ac_cv_little_endian_double=no])]) | ||
56 | -AC_MSG_RESULT($ac_cv_little_endian_double) | ||
57 | -if test "$ac_cv_little_endian_double" = yes | ||
58 | -then | ||
59 | - AC_DEFINE(DOUBLE_IS_LITTLE_ENDIAN_IEEE754, 1, | ||
60 | - [Define if C doubles are 64-bit IEEE 754 binary format, stored | ||
61 | - with the least significant byte first]) | ||
62 | -fi | ||
63 | - | ||
64 | -AC_MSG_CHECKING(whether C doubles are big-endian IEEE 754 binary64) | ||
65 | -AC_CACHE_VAL(ac_cv_big_endian_double, [ | ||
66 | -AC_RUN_IFELSE([AC_LANG_SOURCE([[ | ||
67 | -#include <string.h> | ||
68 | -int main() { | ||
69 | - double x = 9006104071832581.0; | ||
70 | - if (memcmp(&x, "\x43\x3f\xff\x01\x02\x03\x04\x05", 8) == 0) | ||
71 | - return 0; | ||
72 | - else | ||
73 | - return 1; | ||
74 | -} | ||
75 | -]])], | ||
76 | -[ac_cv_big_endian_double=yes], | ||
77 | -[ac_cv_big_endian_double=no], | ||
78 | -[ac_cv_big_endian_double=no])]) | ||
79 | -AC_MSG_RESULT($ac_cv_big_endian_double) | ||
80 | -if test "$ac_cv_big_endian_double" = yes | ||
81 | +AX_C_FLOAT_WORDS_BIGENDIAN | ||
82 | +if test "$ax_cv_c_float_words_bigendian" = "yes" | ||
83 | then | ||
84 | AC_DEFINE(DOUBLE_IS_BIG_ENDIAN_IEEE754, 1, | ||
85 | [Define if C doubles are 64-bit IEEE 754 binary format, stored | ||
86 | with the most significant byte first]) | ||
87 | -fi | ||
88 | - | ||
89 | -# Some ARM platforms use a mixed-endian representation for doubles. | ||
90 | -# While Python doesn't currently have full support for these platforms | ||
91 | -# (see e.g., issue 1762561), we can at least make sure that float <-> string | ||
92 | -# conversions work. | ||
93 | -AC_MSG_CHECKING(whether C doubles are ARM mixed-endian IEEE 754 binary64) | ||
94 | -AC_CACHE_VAL(ac_cv_mixed_endian_double, [ | ||
95 | -AC_RUN_IFELSE([AC_LANG_SOURCE([[ | ||
96 | -#include <string.h> | ||
97 | -int main() { | ||
98 | - double x = 9006104071832581.0; | ||
99 | - if (memcmp(&x, "\x01\xff\x3f\x43\x05\x04\x03\x02", 8) == 0) | ||
100 | - return 0; | ||
101 | - else | ||
102 | - return 1; | ||
103 | -} | ||
104 | -]])], | ||
105 | -[ac_cv_mixed_endian_double=yes], | ||
106 | -[ac_cv_mixed_endian_double=no], | ||
107 | -[ac_cv_mixed_endian_double=no])]) | ||
108 | -AC_MSG_RESULT($ac_cv_mixed_endian_double) | ||
109 | -if test "$ac_cv_mixed_endian_double" = yes | ||
110 | +elif test "$ax_cv_c_float_words_bigendian" = "no" | ||
111 | then | ||
112 | + AC_DEFINE(DOUBLE_IS_LITTLE_ENDIAN_IEEE754, 1, | ||
113 | + [Define if C doubles are 64-bit IEEE 754 binary format, stored | ||
114 | + with the least significant byte first]) | ||
115 | +else | ||
116 | + # Some ARM platforms use a mixed-endian representation for doubles. | ||
117 | + # While Python doesn't currently have full support for these platforms | ||
118 | + # (see e.g., issue 1762561), we can at least make sure that float <-> string | ||
119 | + # conversions work. | ||
120 | + # FLOAT_WORDS_BIGENDIAN doesnt actually detect this case, but if it's not big | ||
121 | + # or little, then it must be this? | ||
122 | AC_DEFINE(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754, 1, | ||
123 | [Define if C doubles are 64-bit IEEE 754 binary format, stored | ||
124 | in ARM mixed-endian order (byte order 45670123)]) | ||
125 | diff --git a/m4/ax_c_float_words_bigendian.m4 b/m4/ax_c_float_words_bigendian.m4 | ||
126 | new file mode 100644 | ||
127 | index 0000000000..216b90d803 | ||
128 | --- /dev/null | ||
129 | +++ b/m4/ax_c_float_words_bigendian.m4 | ||
130 | @@ -0,0 +1,83 @@ | ||
131 | +# =============================================================================== | ||
132 | +# https://www.gnu.org/software/autoconf-archive/ax_c_float_words_bigendian.html | ||
133 | +# =============================================================================== | ||
134 | +# | ||
135 | +# SYNOPSIS | ||
136 | +# | ||
137 | +# AX_C_FLOAT_WORDS_BIGENDIAN([ACTION-IF-TRUE], [ACTION-IF-FALSE], [ACTION-IF-UNKNOWN]) | ||
138 | +# | ||
139 | +# DESCRIPTION | ||
140 | +# | ||
141 | +# Checks the ordering of words within a multi-word float. This check is | ||
142 | +# necessary because on some systems (e.g. certain ARM systems), the float | ||
143 | +# word ordering can be different from the byte ordering. In a multi-word | ||
144 | +# float context, "big-endian" implies that the word containing the sign | ||
145 | +# bit is found in the memory location with the lowest address. This | ||
146 | +# implementation was inspired by the AC_C_BIGENDIAN macro in autoconf. | ||
147 | +# | ||
148 | +# The endianness is detected by first compiling C code that contains a | ||
149 | +# special double float value, then grepping the resulting object file for | ||
150 | +# certain strings of ASCII values. The double is specially crafted to have | ||
151 | +# a binary representation that corresponds with a simple string. In this | ||
152 | +# implementation, the string "noonsees" was selected because the | ||
153 | +# individual word values ("noon" and "sees") are palindromes, thus making | ||
154 | +# this test byte-order agnostic. If grep finds the string "noonsees" in | ||
155 | +# the object file, the target platform stores float words in big-endian | ||
156 | +# order. If grep finds "seesnoon", float words are in little-endian order. | ||
157 | +# If neither value is found, the user is instructed to specify the | ||
158 | +# ordering. | ||
159 | +# | ||
160 | +# LICENSE | ||
161 | +# | ||
162 | +# Copyright (c) 2008 Daniel Amelang <dan@amelang.net> | ||
163 | +# | ||
164 | +# Copying and distribution of this file, with or without modification, are | ||
165 | +# permitted in any medium without royalty provided the copyright notice | ||
166 | +# and this notice are preserved. This file is offered as-is, without any | ||
167 | +# warranty. | ||
168 | + | ||
169 | +#serial 11 | ||
170 | + | ||
171 | +AC_DEFUN([AX_C_FLOAT_WORDS_BIGENDIAN], | ||
172 | + [AC_CACHE_CHECK(whether float word ordering is bigendian, | ||
173 | + ax_cv_c_float_words_bigendian, [ | ||
174 | + | ||
175 | +ax_cv_c_float_words_bigendian=unknown | ||
176 | +AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ | ||
177 | + | ||
178 | +double d = 90904234967036810337470478905505011476211692735615632014797120844053488865816695273723469097858056257517020191247487429516932130503560650002327564517570778480236724525140520121371739201496540132640109977779420565776568942592.0; | ||
179 | + | ||
180 | +]])], [ | ||
181 | + | ||
182 | +if grep noonsees conftest.$ac_objext >/dev/null ; then | ||
183 | + ax_cv_c_float_words_bigendian=yes | ||
184 | +fi | ||
185 | +if grep seesnoon conftest.$ac_objext >/dev/null ; then | ||
186 | + if test "$ax_cv_c_float_words_bigendian" = unknown; then | ||
187 | + ax_cv_c_float_words_bigendian=no | ||
188 | + else | ||
189 | + ax_cv_c_float_words_bigendian=unknown | ||
190 | + fi | ||
191 | +fi | ||
192 | + | ||
193 | +])]) | ||
194 | + | ||
195 | +case $ax_cv_c_float_words_bigendian in | ||
196 | + yes) | ||
197 | + m4_default([$1], | ||
198 | + [AC_DEFINE([FLOAT_WORDS_BIGENDIAN], 1, | ||
199 | + [Define to 1 if your system stores words within floats | ||
200 | + with the most significant word first])]) ;; | ||
201 | + no) | ||
202 | + $2 ;; | ||
203 | + *) | ||
204 | + m4_default([$3], | ||
205 | + [AC_MSG_ERROR([ | ||
206 | + | ||
207 | +Unknown float word ordering. You need to manually preset | ||
208 | +ax_cv_c_float_words_bigendian=no (or yes) according to your system. | ||
209 | + | ||
210 | + ])]) ;; | ||
211 | +esac | ||
212 | + | ||
213 | +])# AX_C_FLOAT_WORDS_BIGENDIAN | ||
214 | -- | ||
215 | 2.11.0 | ||
216 | |||
diff --git a/meta/recipes-devtools/python/python_2.7.15.bb b/meta/recipes-devtools/python/python_2.7.15.bb index e7010bb689..e3a4ddb327 100644 --- a/meta/recipes-devtools/python/python_2.7.15.bb +++ b/meta/recipes-devtools/python/python_2.7.15.bb | |||
@@ -30,6 +30,7 @@ SRC_URI += "\ | |||
30 | file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \ | 30 | file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \ |
31 | file://pass-missing-libraries-to-Extension-for-mul.patch \ | 31 | file://pass-missing-libraries-to-Extension-for-mul.patch \ |
32 | file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \ | 32 | file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \ |
33 | file://float-endian.patch \ | ||
33 | " | 34 | " |
34 | 35 | ||
35 | S = "${WORKDIR}/Python-${PV}" | 36 | S = "${WORKDIR}/Python-${PV}" |