Bug 211916 - segfault from common c++ code with exceptions compiled with gcc
segfault from common c++ code with exceptions compiled with gcc
Status: CLOSED CURRENTRELEASE
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
rawhide
i686 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-10-23 16:37 EDT by cdewey
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version: 4.1.1-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-10-23 18:09:26 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
GNU Compiler Collection 29432 None None None Never

  None (edit)
Description cdewey 2006-10-23 16:37:28 EDT
The following code, when compiled using gcc and optimization (-O1, at least), produces
a segfault after several iterations of the loop. I have reproduced the bug on
two machines running the same OS (CentOS 4) and version of gcc:

$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)

The code was compiled as:
$ g++ -O1 -o bug bug.cc

And run as:
$ ./bug
Segmentation fault

#include <stdexcept>

int main() {
        while (true) {
                try {
                        throw std::runtime_error("foo");
                } catch (const std::runtime_error& e) {
                }
        }
        return 0;
}
Comment 1 Jakub Jelinek 2006-10-23 18:09:26 EDT
This is fixed in FC5/FC6 GCC, most probably by the
http://gcc.gnu.org/PR9350
http://gcc.gnu.org/PR24374
The problem is only in the main function realignment on i?86, if you put
the body of main into a separate routine and just call it from main it will
work fine.  Doing something like this in main is certainly not common and
there is an easy workaround.  Another possible workaround is to use g++4
rather than g++.  Closing as fixed in FC5.

Note You need to log in before you can comment on or make changes to this bug.