From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5258 invoked by alias); 18 Oct 2012 01:44:34 -0000 Received: (qmail 5249 invoked by uid 22791); 18 Oct 2012 01:44:33 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Oct 2012 01:44:21 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9I1iLpn014727 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 17 Oct 2012 21:44:21 -0400 Received: from zebedee.pink ([10.3.113.9]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9I1iJbl013779; Wed, 17 Oct 2012 21:44:20 -0400 Message-ID: <507F5EF2.1040509@redhat.com> Date: Thu, 18 Oct 2012 18:06:00 -0000 From: Andrew Haley User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: Deepthi Bokka CC: "gcc-help@gcc.gnu.org" Subject: Re: Divide by Zero segment fault References: <9843D313A3D30048BAAC430B437718BE5CDB9BE8@ADC.in.autorobinc.com> In-Reply-To: <9843D313A3D30048BAAC430B437718BE5CDB9BE8@ADC.in.autorobinc.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-10/txt/msg00112.txt.bz2 On 10/16/2012 10:58 PM, Deepthi Bokka wrote: > I am new to this group and I am working on a project where I am > porting the Diab build ECU software to GCC 3.4.4 version. This > software actually works on MPC555 series of processor but I am > removing all the hardware dependencies and creating the exe and dll > so that it can run on Windows XP system. The dll will run on a > proprietary tool to simulate the results. > > But when I am running exe or dll, I am getting a segmentation fault > because of divide by zero. To check for divide by zero in the > software, code is very huge with many files and there are multiple > places where this can occur. So checking for zero and skipping that > is ruled out for my case. > > But when the diab build software is running on MPC555 we are not > getting this issue as there the compiler is handled differently. For > example: x = a/b where b=0 then this is processed as x=0 rather than > giving error. So something by zero is treated as simply zero. > > I want similar functionality even in GCC build code, is there any > option for doing this. I tried the flag -mno-check-zero-division in > make file but I was getting make file error that this is not a valid > flag. I tried using the signal handling "sigaction" but could not > get the exact functionality as x/0 should be treated as 0. > > Please can any one help me how to handle this scenario, I can > upgrade the GCC compiler version if higher versions can handle this > issue. Someone could probably figure out how to write a signal handler that would do what you want, but it would be tricky and nonportable and probably is not a good idea in any case. Any division by zero is almost certainly a bug that you should fix, and I would urge you to do so. Andrew.