cygwin 3.5.4-1: signal handling destroys 'long double' values

Christian Franke Christian.Franke@t-online.de
Mon Oct 7 13:11:52 GMT 2024


Recently I used 'stress-ng --class compute ...' which reported the 
failure of the 'logmath clogl' test. It could be reproduced with this 
loop which finishes after some random number of iterations:

$ while stress-ng --logmath 1 --logmath-method clogl -t 1; do echo OK; done
stress-ng: info:  [6190] setting to a 1 sec run per stressor
...
stress-ng: info:  [6190] successful run completed in 1.37 sec
OK
...
OK
stress-ng: info:  [6198] setting to a 1 sec run per stressor
stress-ng: info:  [6198] dispatching hogs: 1 logmath
stress-ng: fail:  [6199] logmath: clogl does not match expected result
stress-ng: error: [6198] logmath: [6199] terminated with an error, exit 
status=2 (stressor failed)
...
stress-ng: info:  [6198] unsuccessful run completed in 1.37 sec

The value mismatch occurs at the very end when the test loop running 
clogl() is hit by the signal indicating timeout.


A closer look shows that the problem could also be reproduced without 
any external math function:

$ uname -r
3.5.4-1.x86_64

$ gcc --version
gcc (GCC) 12.4.0
...

$ cat sigtest.c
#include <signal.h>
#include <stdio.h>

static volatile sig_atomic_t sigcnt;

static void sigint_handler(int sig)
{
   (void)sig;
   sigcnt++;
}

#ifndef WORKS
typedef long double float_type;
#define FMT "La"
#else
typedef double float_type;
#define FMT "a"
#endif

int main()
{
   signal(SIGINT, sigint_handler);
   volatile float_type x = 0x1.23456789p+0;
   while (sigcnt < 42) {
     volatile float_type y = x;
     volatile float_type d = y - x;
     if (d != 0.0)
       printf("x = %" FMT ", y = %" FMT ", d = %" FMT "\n", x, y, d);
   }
}

$ gcc -o sigtest -O2 sigtest.c

$ ./sigtest > out.txt
(press ^C 42x :-)

$ sort out.txt | uniq -c
       3 x = 0x1.23456789p+0, y = -nan, d = -nan
       6 x = 0x1.23456789p+0, y = 0x1.23456789p+0, d = -nan
      33 x = 0x1.23456789p+0, y = 0x1.23456789p+0, d = 0x0p+0

The problem also occurs if compiled without -O2, but less often. No 
problem occurs if compiled with -DWORKS which suggests that only 'long 
double' is affected.

-- 
Regards,
Christian



More information about the Cygwin mailing list