Offhand, I'm not sure what the story is here
Go to
http://ptolemy.eecs.berkeley.edu/search/main.htm
and search for SIGFPE
One of the hits is:
--start--
Subject: Ptolemy on Linux - report #2
To: ptolemy-hackers <[EMAIL PROTECTED]>
Message-id: <[EMAIL PROTECTED]>
X-Envelope-to: [EMAIL PROTECTED]
Status: RO
Hello.
1) I continued tracing the statistics demo which caused the SIGFPE
exception. It's not a division by zero, but an integer conversion
overflow. When the constructor is activated it calls LocalInit
with parameters (0,2,1.0,HUGE_VAL).
Thus n = (int)(1.0/HUGE_VAL), which the Intel FPU doesn't like,
at least with the standard Linux initialization.
** line 120 of src/domains/de/kernel/CalendarQueue.cc:
--------------------------------------------------------------
// set up initial position in queue
cq_lastTime = lastTime; <-- lastTime = HUGE_VAL
n = (int) (lastTime/cq_interval); <-- *** n overflows ***
cq_lastBucket = n % cq_bucketNum;
cq_bucketTop = (n+1.5)*cq_interval;
--------------------------------------------------------------
There are two possible solutions:
- test and check it locally (setting n to MIN_INT on condition)
- change the FPU control word for all the program. This is what I
did, looking at the include file <i386/fpu_control.h>.
I modified the main program (src/pigiRpc/pigiMain.cc) this way:
** line 33:
--------------------------------------------------------------
********************************************************************/
#include <string.h>
+#ifdef linux
+#include <fpu_control.h>
+#endif
extern ptkConsoleWindow();
--------------------------------------------------------------
** line 55:
--------------------------------------------------------------
KcInitLog("pigiLog.pt");
+#ifdef linux
+ __setfpucw(_FPU_DEFAULT | _FPU_MASK_IM);
+#endif
CompileInit();
KcCatchSignals();
/* Strip off end of argv, not front */
--end--
-Christopher
--------
As I have seen that more people have problems with a missing __fsetfpucw wh
en compiling/linking software with glibc-2.1.1 here is my hack to solve this
problem.
Before glibc-2.1.1 the function __setfpucw() was declared global in /usr/in
clude/fpu_control.h at the end of this file
.
.
.
__BEGIN_DECLS
/* Called at startup. It can be used to manipulate fpu control register.
*/
extern void __setfpucw __P ((fpu_control_t));
__END_DECLS
#endif /* fpu_control.h */
The suggestion, given in the comment above it, was applied in a lot of prog
rams out there which don't compile and link anymore because as of glibc-2.1.
1 this declaration is simply missing. Not even one notification is left behi
nd to say something about it's elimination. From bug report
http://www-gnats.gnu.org:8080/cgi-bin/wwwgnats.pl/full/1105
I understand that the function from now on is local to libc as it was alway
s mentioned to be. (Despite the comment above the global function declaratio
n, I should say)
I ran into problems when compiling Ptolemy 0.7.1 from http://ptolemy.eecs.
berkeley.edu on SuSE Linux 6.2. They used __setfpucw() in two files with an
interesting comment which says nothing to me (maybe someone can tell (me) mo
re about that):
#ifdef linux
// Fix for DECalendarQueue SIGFPE under linux.
__setfpucw(_FPU_DEFAULT | _FPU_MASK_IM);
#endif
(The Ptolemy files are $PTOLEMY/src/pigiRpc/pigiMain.cc and PTOLEMY/src/ptc
l/ptclInit.cc)
To fix the problem, in the concerning source files I added the following fu
nction definition:
inline void __setfpucw(int cw) { _FPU_SETCW(cw); }
This way __setfpucw symbol is defined as a wrapper which executes _FPU_SETC
W(cw) which is a macro (still?) defined in fpu_control.h. Now, the files com
pile and link again. However, I am not 100% sure if _FPU_SETCW() modifies th
e wanted fpu control register, but the macro name suggests it does (Ptolemy
runs fine). Furthermore, since _FPU_SETCW() is still a declaration with a le
ading underscore (only one this time) and a lot of people were referring to
the FAQ, which seems to say something like don't use stuff from libc with le
ading underscores, I hope this macro will remain defined for a while. Of cou
rse, as a last resort, one can always plug in the corresponding assembler in
struction in your own defined __setfpucw(int cw) to get
inline void __setfpucw(int cw) { __asm__ ("fnstcw %0" : "=m" (*&cw)) ; }
Hope someone can use this,
Dion
---------------------------------------------------------------------------
-
Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: [EMAIL PROTECTED]
--------
----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: [EMAIL PROTECTED]