Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Sep 1995 00:47:34 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        cracauer@wavehh.hanse.de, cstruble@vt.edu
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Objective C
Message-ID:  <199509261447.AAA08392@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>>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 <math.h>
#forget-to-include <stdlib.h>
...
	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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509261447.AAA08392>