This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]