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]

Re: Division by zero in _exit of libnosys


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



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