[Bug c++/56747] New: throw segfaults on 64bit Cygwin if -O2 (-freorder-blocks) is used with g++ 4.8.0

franke at computer dot org gcc-bugzilla@gcc.gnu.org
Tue Mar 26 19:50:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56747

             Bug #: 56747
           Summary: throw segfaults on 64bit Cygwin if -O2
                    (-freorder-blocks) is used with g++ 4.8.0
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: franke@computer.org


The test program below segfaults during __cxa_throw if -O2 is used. The problem
is possibly related to generation of unwinding-information in conjunction with
-freorder-blocks optimization.

Testcase:

$ uname -srvmo
CYGWIN_NT-6.1 1.7.18(0.263/5/3) 2013-03-26 14:56 x86_64 Cygwin

$ g++ --version
g++ (GCC) 4.8.0

$ cat throw.cc
#include <string>

static int main_worker(int argc)
{
  std::string s[32];
  if (argc < 2)
    throw 42;
  return argc;
}

int main(int argc, char **argv)
{
  try {
    return main_worker(argc);
  }
  catch (int i) {
    return i;
  }
}

$ g++ -O1 -o throw throw.cc

$ ./throw; echo $?
42

$ g++ -O2 -o throw throw.cc

$ ./throw; echo $?
Segmentation fault
139

$ g++ -O2 -fno-reorder-blocks -o throw throw.cc

$ ./throw; echo $?
42

$ g++ -O1 -freorder-blocks -g -o throw throw.cc

$ ./throw; echo $?
Segmentation fault
139

$ gdb throw
...
(gdb) r
Starting program: /tmp/throw/throw
[New Thread 4164.0xe58]
[New Thread 4164.0x7e8]
gdb: unknown target exception 0x20474343 at 0x7fefd7c9e5d
Program received signal ?, Unknown signal.
0x000007fefd7c9e5d in RaiseException () from
/cygdrive/c/Windows/system32/KERNELBASE.dll



More information about the Gcc-bugs mailing list