From owner-freebsd-hackers Tue Sep 26 08:05:04 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id IAA08336 for hackers-outgoing; Tue, 26 Sep 1995 08:05:04 -0700 Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.34]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id IAA08325 for ; Tue, 26 Sep 1995 08:04:57 -0700 Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id AAA08392; Wed, 27 Sep 1995 00:47:34 +1000 Date: Wed, 27 Sep 1995 00:47:34 +1000 From: Bruce Evans Message-Id: <199509261447.AAA08392@godzilla.zeta.org.au> To: cracauer@wavehh.hanse.de, cstruble@vt.edu Subject: Re: Objective C Cc: freebsd-hackers@freebsd.org Sender: owner-hackers@freebsd.org Precedence: bulk >>I compiled gcc 2.7.0 and everything seemed to compile fine. I then >>tried to build libobjects-0.1.14 and the test programs. All the >>test programs fail with a core dump (floating point exception) in >>libobjc.a, the Objective C runtime library. It seems to be a problem >>with __builtin_return(), but my compiler knowledge is a bit lacking >>so I can't figure out exactly what is wrong. >... >The problem is that FreeBSD does not use IEEE exceptions. Division >by zero etc. (that result in NaN or other special IEEE numbers on >other machines) will raise the SIGFPE signal, which by default causes >a core dump. I remember reading something about the problem being that invalid code is generated for __builtin_return() when the value being returned is floating point, essentially the same as for the well known bug of not declaring atof(): #include #forget-to-include ... foo = atof("12.34"); /* * Get a SIGFPE near here if you're lucky. The value of `foo' * is garbage and there is one operand full of junk on the * floating point stack. If the compiler attempts to use all * of the 8 operands that are supposed to be free on the FP * stack, then pushing the 8th one will cause an invalid * operand exception and a stack exception. If invalid * operand exceptions are not masked, then a SIGFPE will be * generated on the next non-control FP instruction after * the one that causes the exceptions. */ >Linux has the same problem. You can solve it at Linux using >-lieee. NetBSD uses full IEEE semantic as does any workstation I >have. This works by hiding the bug. There is unfortunately no way to trap stack exceptions except to trap the invalid operand exceptions that occur together with stack exceptions, so masking all IEEE exceptions breaks trapping for stack exceptions (invalid operand exceptions are IEEE but stack exceptions aren't). >I don't know the correct FreeBSD solution, since nothing like -lieee >seems to exist. Maybe I overlooked the right way to solve this in >FreeBSD. See fpsetmask(3). >At the beginning of the program, before any ObjC message call: >#ifdef __FreeBSD__ >signal(SIGFPE,signal_dummy); >#endif /* __FreeBSD__ */ This probably won't work on FreeBSD-2.0.5. It works in FreeBSD 2.0 and in Linux because the trap handler reinitializes the FPU state after saving parts of the old state in (respectively) broken and nonstandard places where debuggers can't find it. FreeBSD-2.0.5 preserves all of the state except for the exception bits. In particular it preserves the stack, so junk on the stack won't go away. Bruce