lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

diffutils: Fix gnulib test failure on ppc64

authored by

OPNA2608 and committed by
Alyssa Ross
9c17e440 20abd8e5

+237
+7
pkgs/tools/text/diffutils/default.nix
··· 26 26 "info" 27 27 ]; 28 28 29 + patches = [ 30 + # Fixes test-float-h failure on ppc64 with C23 31 + # https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00021.html 32 + # Multiple upstream commits squashed with adjustments, see header 33 + ./gnulib-float-h-tests-port-to-C23-PowerPC-GCC.patch 34 + ]; 35 + 29 36 nativeBuildInputs = [ 30 37 updateAutotoolsGnuConfigScriptsHook 31 38 (lib.getBin xz)
+230
pkgs/tools/text/diffutils/gnulib-float-h-tests-port-to-C23-PowerPC-GCC.patch
··· 1 + Applies the following incremental gnulib commits: 2 + 3 + - 55a366a06fbd98bf13adc531579e3513cee97a32 4 + - 65ed9d3b24ad09fd61d326c83e7f1b05f6e9d65f 5 + - ce8e9de0bf34bc63dffc67ab384334c509175f64 6 + - 6164b4cb0887b5331a4e64449107decd37d32735 7 + 8 + With adjustments specific to the structure & differences in diffutils: 9 + 10 + - gnulib code is completely contained in gnulib-tests (flat, no separate lib directory) 11 + - A Makefile.in is used for the test flags instead of the fancy automake modules 12 + in the upstream gnulib project, so we add -lm to the float test there. 13 + Surrounding texts in this file are slightly different in every project. 14 + --- 15 + diff '--color=auto' -ruN a/gnulib-tests/float.c b/gnulib-tests/float.c 16 + --- a/gnulib-tests/float.c 2025-01-02 03:33:12.000000000 +0100 17 + +++ b/gnulib-tests/float.c 2025-07-09 21:20:34.116794411 +0200 18 + @@ -23,7 +23,7 @@ 19 + #if GNULIB_defined_long_double_union 20 + # if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ 21 + const union gl_long_double_union gl_LDBL_MAX = 22 + - { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } }; 23 + + { { DBL_MAX, DBL_MAX / 0x1p53 } }; 24 + # elif defined __i386__ 25 + const union gl_long_double_union gl_LDBL_MAX = 26 + { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; 27 + diff '--color=auto' -ruN a/gnulib-tests/float.in.h b/gnulib-tests/float.in.h 28 + --- a/gnulib-tests/float.in.h 2025-01-02 03:33:12.000000000 +0100 29 + +++ b/gnulib-tests/float.in.h 2025-07-09 21:20:34.117010190 +0200 30 + @@ -113,44 +113,38 @@ 31 + # define LDBL_MAX_10_EXP 4932 32 + #endif 33 + 34 + -/* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are 35 + - wrong. 36 + - On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */ 37 + -#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ 38 + +/* On PowerPC with gcc 15 when using __ibm128 long double, the value of 39 + + LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX, and LDBL_NORM_MAX are wrong. */ 40 + +#if ((defined _ARCH_PPC || defined _POWER) && LDBL_MANT_DIG == 106 \ 41 + + && defined __GNUC__) 42 + # undef LDBL_MIN_EXP 43 + # define LDBL_MIN_EXP DBL_MIN_EXP 44 + # undef LDBL_MIN_10_EXP 45 + # define LDBL_MIN_10_EXP DBL_MIN_10_EXP 46 + # undef LDBL_MIN 47 + # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */ 48 + -#endif 49 + -#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ 50 + # undef LDBL_MAX 51 + -/* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }. 52 + - It is not easy to define: 53 + - #define LDBL_MAX 1.79769313486231580793728971405302307166e308L 54 + - is too small, whereas 55 + - #define LDBL_MAX 1.79769313486231580793728971405302307167e308L 56 + - is too large. Apparently a bug in GCC decimal-to-binary conversion. 57 + - Also, I can't get values larger than 58 + - #define LDBL63 ((long double) (1ULL << 63)) 59 + - #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 60 + - #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 61 + - #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 62 + - #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL) 63 + - which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }. 64 + - So, define it like this through a reference to an external variable 65 + +/* LDBL_MAX is 2**1024 - 2**918, represented as: { 0x7FEFFFFF, 0xFFFFFFFF, 66 + + 0x7C9FFFFF, 0xFFFFFFFF }. 67 + + 68 + + Do not write it as a constant expression, as GCC would likely treat 69 + + that as infinity due to the vagaries of this platform's funky arithmetic. 70 + + Instead, define it through a reference to an external variable. 71 + + Like the following, but using a union to avoid type mismatches: 72 + 73 + - const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }; 74 + + const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / 0x1p53 }; 75 + extern const long double LDBL_MAX; 76 + 77 + - or through a pointer cast 78 + + The following alternative would not work as well when GCC is optimizing: 79 + + 80 + + #define LDBL_MAX (*(long double const *) (double[]) 81 + + { DBL_MAX, DBL_MAX / 0x1p53 }) 82 + 83 + - #define LDBL_MAX \ 84 + - (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }) 85 + + The following alternative would require GCC 6 or later: 86 + 87 + - Unfortunately, this is not a constant expression, and the latter expression 88 + - does not work well when GCC is optimizing.. */ 89 + + #define LDBL_MAX __builtin_pack_longdouble (DBL_MAX, DBL_MAX / 0x1p53) 90 + + 91 + + Unfortunately none of the alternatives are constant expressions. */ 92 + # if !GNULIB_defined_long_double_union 93 + union gl_long_double_union 94 + { 95 + @@ -161,6 +155,8 @@ 96 + # endif 97 + extern const union gl_long_double_union gl_LDBL_MAX; 98 + # define LDBL_MAX (gl_LDBL_MAX.ld) 99 + +# undef LDBL_NORM_MAX 100 + +# define LDBL_NORM_MAX LDBL_MAX 101 + #endif 102 + 103 + /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong. 104 + @@ -181,6 +177,21 @@ 105 + # endif 106 + #endif 107 + 108 + +/* On PowerPC platforms, 'long double' has a double-double representation. 109 + + Up to ISO C 17, this was outside the scope of ISO C because it can represent 110 + + numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits>, such as 111 + + 1.0L + 4.94065645841246544176568792868221e-324L = 1 + 2^-1074; see 112 + + ISO C 17 § 5.2.4.2.2.(3). 113 + + In ISO C 23, wording has been included that makes this 'long double' 114 + + representation compliant; see ISO C 23 § 5.2.5.3.3.(8)-(9). In this setting, 115 + + numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits> are 116 + + called "unnormalized". And since LDBL_EPSILON must be normalized (per 117 + + ISO C 23 § 5.2.5.3.3.(33)), it must be 2^-105. */ 118 + +#if defined __powerpc__ && LDBL_MANT_DIG == 106 119 + +# undef LDBL_EPSILON 120 + +# define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */ 121 + +#endif 122 + + 123 + /* ============================ ISO C11 support ============================ */ 124 + 125 + /* 'float' properties */ 126 + @@ -309,7 +320,11 @@ 127 + # endif 128 + #endif 129 + #ifndef LDBL_NORM_MAX 130 + -# define LDBL_NORM_MAX LDBL_MAX 131 + +# ifdef __LDBL_NORM_MAX__ 132 + +# define LDBL_NORM_MAX __LDBL_NORM_MAX__ 133 + +# else 134 + +# define LDBL_NORM_MAX LDBL_MAX 135 + +# endif 136 + #endif 137 + #ifndef LDBL_SNAN 138 + /* For sh, beware of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111814>. */ 139 + diff '--color=auto' -ruN a/gnulib-tests/Makefile.in b/gnulib-tests/Makefile.in 140 + --- a/gnulib-tests/Makefile.in 2025-04-09 04:36:30.000000000 +0200 141 + +++ b/gnulib-tests/Makefile.in 2025-07-09 21:20:45.260378342 +0200 142 + @@ -1059,7 +1059,7 @@ 143 + test_filenamecat_DEPENDENCIES = $(am__DEPENDENCIES_2) 144 + test_float_h_SOURCES = test-float-h.c 145 + test_float_h_OBJECTS = test-float-h.$(OBJEXT) 146 + -test_float_h_LDADD = $(LDADD) 147 + +test_float_h_LDADD = $(LDADD) -lm 148 + test_float_h_DEPENDENCIES = libtests.a ../lib/libdiffutils.a \ 149 + libtests.a ../lib/libdiffutils.a libtests.a \ 150 + $(am__DEPENDENCIES_1) 151 + diff '--color=auto' -ruN a/gnulib-tests/test-float-h.c b/gnulib-tests/test-float-h.c 152 + --- a/gnulib-tests/test-float-h.c 2025-01-02 03:33:12.000000000 +0100 153 + +++ b/gnulib-tests/test-float-h.c 2025-07-09 21:20:34.117248712 +0200 154 + @@ -101,6 +101,8 @@ 155 + 156 + /* ------------------------------------------------------------------------- */ 157 + 158 + +#include <math.h> 159 + + 160 + #include "fpucw.h" 161 + #include "isnanf-nolibm.h" 162 + #include "isnand-nolibm.h" 163 + @@ -396,6 +398,44 @@ 164 + 165 + /* -------------------- Check macros for 'long double' -------------------- */ 166 + 167 + +static int 168 + +test_isfinitel (long double volatile x) 169 + +{ 170 + + if (x != x) 171 + + return 0; 172 + + long double volatile zero = x * 0; 173 + + return zero == 0; 174 + +} 175 + + 176 + +/* Return X after normalization. This makes a difference on platforms 177 + + where long double can represent unnormalized values. For example, 178 + + suppose x = 1 + 2**-106 on PowerPC with IBM long double where 179 + + FLT_RADIX = 2, LDBL_MANT_DIG = 106, and LDBL_EPSILON = 2**-105. 180 + + Then 1 < x < 1 + LDBL_EPSILON, and normalize_long_double (x) returns 1. */ 181 + +static long double 182 + +normalize_long_double (long double volatile x) 183 + +{ 184 + + if (FLT_RADIX == 2 && test_isfinitel (x)) 185 + + { 186 + + int xexp; 187 + + long double volatile 188 + + frac = frexpl (x, &xexp), 189 + + significand = frac * pow2l (LDBL_MANT_DIG), 190 + + normalized_significand = truncl (significand), 191 + + normalized_x = normalized_significand * pow2l (xexp - LDBL_MANT_DIG); 192 + + 193 + + /* The test_isfinitel defends against PowerPC with IBM long double, 194 + + which fritzes out near LDBL_MAX. */ 195 + + if (test_isfinitel (normalized_x)) 196 + + x = normalized_x; 197 + + } 198 + + else 199 + + { 200 + + /* Hope that X is already normalized. */ 201 + + } 202 + + return x; 203 + +} 204 + + 205 + static void 206 + test_long_double (void) 207 + { 208 + @@ -455,7 +495,7 @@ 209 + for (n = 0; n <= 2 * LDBL_MANT_DIG; n++) 210 + { 211 + volatile long double half_n = pow2l (- n); /* 2^-n */ 212 + - volatile long double x = me - half_n; 213 + + volatile long double x = normalize_long_double (me - half_n); 214 + if (x < me) 215 + ASSERT (x <= 1.0L); 216 + } 217 + @@ -483,8 +523,12 @@ 218 + ASSERT (!LDBL_IS_IEC_60559); 219 + #endif 220 + 221 + + printf("LDBL_NORM_MAX: %LF\n", LDBL_NORM_MAX); 222 + + printf("LDBL_MAX: %LF\n", LDBL_MAX); 223 + + printf("normalize_long_double(LDBL_MAX): %LF\n", normalize_long_double(LDBL_MAX)); 224 + + 225 + /* Check the value of LDBL_NORM_MAX. */ 226 + - ASSERT (LDBL_NORM_MAX == LDBL_MAX); 227 + + ASSERT (LDBL_NORM_MAX == normalize_long_double (LDBL_MAX)); 228 + 229 + /* Check the value of LDBL_SNAN. */ 230 + ASSERT (isnanl (LDBL_SNAN));