Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha error writing exceptional math value #4349

Closed
p5pRT opened this issue Aug 24, 2001 · 8 comments
Closed

Alpha error writing exceptional math value #4349

p5pRT opened this issue Aug 24, 2001 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 24, 2001

Migrated from rt.perl.org#7585 (status was 'resolved')

Searchable as RT7585$

@p5pRT
Copy link
Author

p5pRT commented Aug 24, 2001

From dalke@pw600a.bioperl.org

There is a problem with Perl 5.005_03 and 5.6.1 when printing
the IEEE 754 NaN exception value.

Here's the reproducible, with the first to show that non-exceptional
values really do work.

===============
[dalke@​pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(0.5), "\n"'
1.0471975511966
[dalke@​pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(3.7), "\n"'
Floating exception (core dumped)
[dalke@​pw600a perl-5.6.1]$ ./perl -version

This is perl, v5.6.1 built for alpha-linux

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http​://www.perl.com/, the Perl Home Page.
  ===============

I recompiled Perl with -g support to get a full stack trace.

[...]
Reading symbols from /tmp/apd/perl-5.6.1/lib/auto/POSIX/POSIX.so...done.
#0 0x12009a4ac in Perl_cast_iv (f=NaN(0x8000000000000)) at util.c​:2828
2828 if (f >= IV_MAX) {
(gdb) where
#0 0x12009a4ac in Perl_cast_iv (f=NaN(0x8000000000000)) at util.c​:2828
#1 0x1200c36d0 in Perl_sv_upgrade (sv=0x120292a00, mt=6) at sv.c​:957
#2 0x1200c8c48 in Perl_sv_2pv (sv=0x120292a00, lp=0x11ffff928) at sv.c​:2209
#3 0x1201416e4 in Perl_do_print (sv=0x120292a00, fp=0x200006a08a8)
  at doio.c​:1155
#4 0x1200b3e90 in Perl_pp_print () at pp_hot.c​:407
#5 0x1200b0a8c in Perl_runops_debug () at run.c​:53
#6 0x12001d0cc in S_run_body (oldscope=1) at perl.c​:1471
#7 0x12001ca70 in perl_run (my_perl=0x120286b30) at perl.c​:1393
#8 0x120017668 in main (argc=4, argv=0x11ffffbc8, env=0x11ffffbf0)
  at perlmain.c​:52

(gdb) print f
$1 = NaN(0x8000000000000)
(gdb) list
2823 }
2824
2825 IV
2826 Perl_cast_iv(pTHX_ NV f)
2827 {
2828 if (f >= IV_MAX) {
2829 UV uv;
2830
2831 if (f >= (NV)UV_MAX)
2832 return (IV) UV_MAX;

I can reproduce this problem in C, as

lke@​pw600a perl-5.6.1]$ cat q.c
#include <stdio.h>
#include <math.h>
#include <stdint.h>

#define IV_MAX INT64_MAX
main() {
  double f = acos(4.7);
  if (f >= IV_MAX) {
  printf("Yep.\n");
  } else {
  printf("Nope.\n");
  }
}
[dalke@​pw600a perl-5.6.1]$ cc q.c -lm -g
[dalke@​pw600a perl-5.6.1]$ ./a.out
Floating exception (core dumped)
[dalke@​pw600a perl-5.6.1]$ gdb a.out core
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "alpha-redhat-linux"...

warning​: "/tmp/apd/perl-5.6.1/core"​: ambiguous core format, 2 handlers match
Core was generated by `./a.out'.
Program terminated with signal 8, Floating point exception.
Reading symbols from /lib/libm.so.6.1...done.
Reading symbols from /lib/libc.so.6.1...done.
Reading symbols from /lib/ld-linux.so.2...done.
#0 0x1200004c8 in main () at q.c​:8
8 if (f >= IV_MAX) {
(gdb)

Here's the assembly dump of that code​:

0x120000480 <main>​: ldah gp,17(t12)
0x120000484 <main+4>​: lda gp,-32296(gp)
0x120000488 <main+8>​: subq sp,0x20,sp
0x12000048c <main+12>​: stq ra,0(sp)
0x120000490 <main+16>​: stq fp,8(sp)
0x120000494 <main+20>​: mov sp,fp
0x120000498 <main+24>​: ldq t0,-32672(gp)
0x12000049c <main+28>​: ldt $f16,0(t0)
0x1200004a0 <main+32>​: ldq t12,-32728(gp)
0x1200004a4 <main+36>​: jsr ra,(t12),0x120000000
0x1200004a8 <main+40>​: ldah gp,17(ra)
0x1200004ac <main+44>​: lda gp,-32336(gp)
0x1200004b0 <main+48>​: fmov $f0,$f10
0x1200004b4 <main+52>​: stt $f10,16(fp)
0x1200004b8 <main+56>​: ldt $f10,16(fp)
0x1200004bc <main+60>​: ldq t0,-32680(gp)
0x1200004c0 <main+64>​: ldt $f11,0(t0)
0x1200004c4 <main+68>​: cmptle $f11,$f10,$f10
0x1200004c8 <main+72>​: fbeq $f10,0x1200004e4 <main+100>
0x1200004cc <main+76>​: ldq a0,-32688(gp)
0x1200004b8 <main+56>​: ldt $f10,16(fp)
0x1200004bc <main+60>​: ldq t0,-32680(gp)
0x1200004c0 <main+64>​: ldt $f11,0(t0)
0x1200004c4 <main+68>​: cmptle $f11,$f10,$f10 <--- SIGFPE occurs here
0x1200004c8 <main+72>​: fbeq $f10,0x1200004e4 <main+100>
0x1200004cc <main+76>​: ldq a0,-32688(gp)
0x1200004d0 <main+80>​: ldq t12,-32744(gp)
0x1200004d4 <main+84>​: jsr ra,(t12),0x12000063c
0x1200004d8 <main+88>​: ldah gp,17(ra)
0x1200004dc <main+92>​: lda gp,-32384(gp)
0x1200004e0 <main+96>​: br 0x1200004f8 <main+120>
0x1200004e4 <main+100>​: ldq a0,-32696(gp)
0x1200004e8 <main+104>​: ldq t12,-32744(gp)
0x1200004ec <main+108>​: jsr ra,(t12),0x12000063c
0x1200004f0 <main+112>​: ldah gp,17(ra)
0x1200004f4 <main+116>​: lda gp,-32408(gp)
0x1200004f8 <main+120>​: mov fp,sp
0x1200004fc <main+124>​: ldq ra,0(sp)
0x120000500 <main+128>​: ldq fp,8(sp)
0x120000504 <main+132>​: addq sp,0x20,sp
0x120000508 <main+136>​: ret zero,(ra),0x1

Whe running it assembly step by assembly step in the debugger​:
(gdb) nexti
0x1200004ac 7 double f = acos(4.7);
(gdb) nexti
0x1200004b0 7 double f = acos(4.7);
(gdb) nexti
0x1200004b4 7 double f = acos(4.7);
(gdb) nexti
8 if (f >= IV_MAX) {
(gdb) nexti
0x1200004bc 8 if (f >= IV_MAX) {
(gdb) nexti
0x1200004c0 8 if (f >= IV_MAX) {
(gdb) nexti
0x1200004c4 8 if (f >= IV_MAX) {
(gdb) nexti

Program received signal SIGFPE, Arithmetic exception.
0x1200004c8 in main () at q.c​:8
8 if (f >= IV_MAX) {

which is this line of the assembly
0x1200004c4 <main+68>​: cmptle $f11,$f10,$f10 <--- SIGFPE occurs here

I don't know enough about the Perl internals, Alphas or 64 bit
programming to aid any more than this.

  Andrew Dalke
  dalke@​dalkescientific.com
P.S.
  This occured because the Perl Cookbook uses acos(3.7) in an
example. This number is out of range and I've informed the authors.
It will be updated to use 0.37 but in the meanwhile my testing for
the PLEAC (see pleac.sf.net) translation of the cookbook to Python
found this problem.

Perl Info

Flags:
    category=library
    severity=low

Site configuration information for perl v5.6.1:

Configured by dalke at Fri Aug 24 12:20:56 EDT 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.2.14-6.0, archname=alpha-linux
    uname='linux pw600a.bioperl.org 2.2.14-6.0 #1 tue mar 28 16:56:56 est 2000 alpha unknown '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/shlib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.1:
    lib
    /usr/local/lib/perl5/5.6.1/alpha-linux
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/alpha-linux
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.6.1:
    HOME=/home/dalke
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/dalke/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/home/biopython/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Aug 26, 2001

From @nwc10

Thanks for the very thorough report.

There is a problem with Perl 5.005_03 and 5.6.1 when printing
the IEEE 754 NaN exception value.

Here's the reproducible, with the first to show that non-exceptional
values really do work.

===============
[dalke@​pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(0.5), "\n"'
1.0471975511966
[dalke@​pw600a perl-5.6.1]$ ./perl -Ilib -e 'use POSIX; print acos(3.7), "\n"'
Floating exception (core dumped)

I asked a friend to run
perl -we 'use POSIX; print acos(3.7), "\n"'

on an alpha running Debian GNU/Linux. He gets NaN rather than a core dump.
He suggests building with -mieee in the cflags, which is what Debian use.

Compiler​:
cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, usemymalloc=n, prototype=define
Linker and Libraries​:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /usr/shlib /lib /usr/lib
libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Debian's Alpha perl gives a -V of

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration​:
  Platform​:
  osname=linux, osvers=2.2.15, archname=alpha-linux
  uname='linux flatline 2.2.15 #8 smp fri jul 12 09​:36​:31 mst 2052 alpha unknown '
  config_args='-Dccflags=-DDEBIAN -mieee -Dcccdlflags=-fPIC -Darchname=alpha-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Dotherlibdirs=/usr/lib/perl5/5.6​:/usr/lib/perl5/5.005 -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
  useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=define use64bitall=define uselongdouble=undef
  Compiler​:
  cc='cc', ccflags ='-DDEBIAN -mieee -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-DDEBIAN -mieee -fno-strict-aliasing -I/usr/local/include'
  ccversion='', gccversion='2.95.4 20010604 (Debian prerelease)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt
  perllibs=-ldl -lm -lc -lcrypt
  libc=, so=so, useshrplib=true, libperl=libperl.so.5.6.1
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Compile-time options​: USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES
  Built under linux
  Compiled at Jun 24 2001 01​:25​:23
  @​INC​:
  /usr/local/lib/perl/5.6.1
  /usr/local/share/perl/5.6.1
  /usr/lib/perl5
  /usr/share/perl5
  /usr/lib/perl/5.6.1
  /usr/share/perl/5.6.1
  /usr/local/lib/site_perl
  /usr/lib/perl5/5.6/alpha-linux
  /usr/lib/perl5/5.6
  /usr/lib/perl5/5.005
  .

Is building with -mieee a sensible idea? If so, should it be on by
default on Alpha linux?

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2001

From [Unknown Contact. See original ticket]

I recompiled the devel version of perl 5.6.1 to use
the -mieee flag. That prevented the SIGFPE.

[perl-5.7.2]$ ./perl -Ilib -e 'use POSIX; print acos(3.7), "\n"'
nan
[perl-5.7.2]$ perl -e 'use POSIX; print acos(3.7), "\n"'
Floating exception (core dumped)
[perl-5.7.2]$

Is building with -mieee a sensible idea? If so, should
it be on by default on Alpha linux?

Frankly, I don't know. If Debian does it and since
it prevents this signal from occuring, then I would
recommend it. I don't know enough of the consequences
for that to be a solid recommendation.

  Andrew
  dalke@​dalkescientific.com

@p5pRT
Copy link
Author

p5pRT commented Aug 27, 2001

From @Tux

Something to add to a hint file? (hint hint)

[perl-5.7.2]$ ./perl -Ilib -e 'use POSIX; print acos(3.7), "\n"'
nan
[perl-5.7.2]$ perl -e 'use POSIX; print acos(3.7), "\n"'
Floating exception (core dumped)
[perl-5.7.2]$

Is building with -mieee a sensible idea? If so, should
it be on by default on Alpha linux?

Frankly, I don't know. If Debian does it and since
it prevents this signal from occuring, then I would
recommend it. I don't know enough of the consequences
for that to be a solid recommendation.

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2012

From @doy

Can this be reproduced on newer versions of perl? Do we have anyone
building on Alpha anymore?

-doy

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

From @doy

11​:43 <@​BinGOs> doy​: #7585 all my non-debian perls on this debian/alpha
linux box produce 'nan'
11​:43 <@​BinGOs> v5.10.1 and upwards
11​:44 <@​BinGOs> for perl -e 'use POSIX; print acos(3.7), "\n"'

None of these perls were built with -mieee, so I think this can probably
be closed.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

From [Unknown Contact. See original ticket]

11​:43 <@​BinGOs> doy​: #7585 all my non-debian perls on this debian/alpha
linux box produce 'nan'
11​:43 <@​BinGOs> v5.10.1 and upwards
11​:44 <@​BinGOs> for perl -e 'use POSIX; print acos(3.7), "\n"'

None of these perls were built with -mieee, so I think this can probably
be closed.

-doy

@p5pRT
Copy link
Author

p5pRT commented Jul 6, 2012

@doy - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant