[erlang-patches] Per-thread FPE pointer not being initialized

Mikael Pettersson mikpe@REDACTED
Wed Jul 1 12:03:04 CEST 2009


David Reiss writes:
 > The per-thread last floating point exception pointer is not initialized to
 > NULL when it is allocated.  As a result, spurious floating point
 > exceptions are reported.
 > 
 > This is 100% reproducible for me on CentOS 5.1 for x86-64, with Erlang/OTP
 > R13B built from source with gcc 2.5 and gcc 4.1.2.  It doesn't happen with
 > R13B01, but, based on the nature of the bug, I think that is most likely
 > due to chance.
 > 
 > Steps to reproduce:
 > 
 > 1/ Start up a node with
 >   dreiss@REDACTED:~$ erl -noshell -name bob@`hostname`
 > 
 > 2/ Build and compile test program
 >   dreiss@REDACTED:~$ cat test.erl
 >   -module(test).
 >   -export([start/1]).
 >   start([Remote]) ->
 >     rpc:call(Remote, erlang, is_float, [750.0]).
 >   dreiss@REDACTED:~$ erlc test.erl
 > 
 > 3/ Run test program
 >   dreiss@REDACTED:~$ erl -noshell -name alice@`hostname` -pz . -s test
 > start bob@`hostname` -s init stop
 > 
 > The "alice" node exits with no output.  After running the "alice" command,
 > the "bob" node prints the following
 > 
 >   ERTS_FP_CHECK_INIT at 0x4aaded: detected unhandled FPE at 0x2
 > 
 > Patch:
 > 
 > diff otp_src_R13B/erts/emulator/sys/unix/sys_float.c
 > otp_src_R13B/sys/unix/sys_float.c/sys/unix/sys_float.c
 > --- otp_src_R13B/erts/emulator/sys/unix/sys_float.c	2009-06-30
 > 17:53:31.000000000 -0700
 > +++ otp_src_R13B/erts/emulator/sys/unix/sys_float.c	2009-06-30
 > 17:53:31.000000000 -0700
 > @@ -57,7 +57,8 @@
 >  void erts_thread_init_fp_exception(void)
 >  {
 >      unsigned long *fpe = erts_alloc(ERTS_ALC_T_FP_EXCEPTION, sizeof(*fpe));
 > +    *fpe = 0;
 >      erts_tsd_set(fpe_key, fpe);
 >  }

Thanks, that bug was mine :-( Your fix is correct.

I believe the initialisation here wasn't needed originally,
but became necessary as a side effect of some FP exn machinery
redesign I did late last year.

Where did the spurious FP exception get detected, i.e.,
what runtime system procedure does 0x4aaded correspond to?

/Mikael


More information about the erlang-patches mailing list