throw causes segfault (with small demo program)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I found that when I link my program statically on SuSE 9.0 (gcc 3.3.1), it
gets segfault whenever throw is used. The program works fine under earlier
SuSE versions or when linked dynamically. I tested also gcc 3.3.3 and the
latest gcc 3.4 prerelease, but the result was the same.

The following piece of code demonstrates the problem:

#include <cstdio>
#include <exception>

#include <syslog.h>

using namespace std;

bool call_syslog = false;

void xxx()
  {
    if(call_syslog)
      {
        syslog(LOG_ERR, "%s", "xxx");
      }

    throw exception();
  }

int main()
  {
    printf("before try\n");
    fflush(stdout);

    try
      {
        xxx();
      }
    catch(exception &e)
      {
        printf("in catch\n");
        fflush(stdout);
      }

    return 0;
  }

Note that when I comment out the syslog() line, the problem disappears! 
Since syslog() is not called, it can only affect linking (perhaps the 
size of binary exceeds some critical limit!?).

Here is what I get:

$ g++ -g2 -Wall gcc_test.cc -o gcc_test

$ ./gcc_test 
before try
in catch

$ g++ -g2 -Wall -static gcc_test.cc -o gcc_test

$ ./gcc_test 
before try
Segmentation fault

$ strace ./gcc_test 
execve("./gcc_test", ["./gcc_test"], [/* 78 vars */]) = 0
uname({sys="Linux", node="st55", ...})  = 0
brk(0)                                  = 0x80bed14
brk(0x80dfd14)                          = 0x80dfd14
brk(0x80e0000)                          = 0x80e0000
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 17), ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0x40000000
write(1, "before try\n", 11before try
)            = 11
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

$ gdb ./gcc_test 
GNU gdb 5.3.92
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...
(gdb) run
Starting program: 
/home/andres/gcc_test 
before try

Program received signal SIGSEGV, Segmentation fault.
get_cie_encoding (cie=0x79b94b6) at unwind-dw2-fde.c:271
271     unwind-dw2-fde.c: No such file or directory.
        in unwind-dw2-fde.c
Current language:  auto; currently c
(gdb) bt
#0  get_cie_encoding (cie=0x79b94b6) at unwind-dw2-fde.c:271
#1  0x0804ca3a in classify_object_over_fdes (ob=0x80b9fe4, this_fde=0x80b94b2)
    at unwind-dw2-fde.c:623
#2  0x0804d8a9 in init_object (ob=0x80b9fe4) at unwind-dw2-fde.c:734
#3  0x0804cfe8 in search_object (ob=0x80b9fe4, pc=0x804b8c7)
    at unwind-dw2-fde.c:936
#4  0x0804d098 in _Unwind_Find_registered_FDE (pc=0x804b8c7, bases=0xbfffed34)
    at unwind-dw2-fde.c:1000
#5  0x0804d59c in _Unwind_Find_FDE (pc=0x804b8c7, bases=0xbfffed34)
    at ../../gcc-3.3-20040405/gcc/unwind-dw2-fde-glibc.c:273
#6  0x0804b115 in uw_frame_state_for (context=0xbfffece0, fs=0xbfffeaa0)
    at ../../gcc-3.3-20040405/gcc/unwind-dw2.c:935
#7  0x0804b63f in uw_init_context_1 (context=0xbfffece0, outer_cfa=0x79b94b6, 
    outer_ra=0x79b94b6) at ../../gcc-3.3-20040405/gcc/unwind-dw2.c:1176
#8  0x0804b8c8 in _Unwind_RaiseException (exc=0x80bf078) at unwind.inc:84
#9  0x08049363 in __cxa_throw (obj=0x80bf078, tinfo=0x80be004, 
    dest=0x80be004 <globals_static>)
    at ../../../../gcc-3.3-20040405/libstdc++-v3/libsupc++/eh_throw.cc:75
#10 0x0804826e in xxx() () at gcc_test.cc:17
(gdb) 


What could be wrong?


Thanks,

Andres.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux