Division by zero in _exit of libnosys
Jie Zhang
jzhang918@gmail.com
Sun Feb 11 19:19:00 GMT 2007
On 2/10/07, Jie Zhang <jzhang918@gmail.com> wrote:
> 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
>
Paolo suggested using an asm to prevent gcc from optimizing away the
division by zero:
http://gcc.gnu.org/ml/gcc/2007-02/msg00200.html
So the above code snippet now looks like:
#ifdef __BFIN__
asm ("excpt 0;");
#else
/* Default stub just causes a divide by 0 exception. */
int x = rc / INT_MAX;
x = 4 / x;
asm volatile ("" : : "r" (x));
#endif
Jie
More information about the Newlib
mailing list