This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Division by zero in _exit of libnosys
- From: "Jie Zhang" <jzhang918 at gmail dot com>
- To: newlib at sources dot redhat dot com
- Date: Sat, 10 Feb 2007 21:41:39 +0800
- Subject: Division by zero in _exit of libnosys
Hi,
In libnosys of libgloss, the default stub of _exit ():
_VOID
_DEFUN (_exit, (rc),
int rc)
{
/* Default stub just causes a divide by 0 exception. */
int x = rc / INT_MAX;
x = 4 / x;
/* Convince GCC that this function never returns. */
for (;;)
;
}
tries to cause a divide-by-zero exception. Division by 0 is an
undefined behavior in C. It's not guaranteed to generate the
exception. For this piece of code, gcc will optimize away the
dividsions, leaving only the empty loop.
We have to find another way to do that. How about the below method?
#ifdef __BFIN__
asm ("excpt 0;");
#else
/* Default stub just causes a divide by 0 exception. */
int x = rc / INT_MAX;
x = 4 / x;
#endif
Or is there an easy way to define a real _exit for each port to
override the stub?
Jie