http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60221
Bug ID: 60221 Summary: gcc -fexceptions generates unnecessary cleanup code Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: redlizard at redlizard dot nl > gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/tmp/gcc-4.8.2/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.8.2/configure --prefix=/tmp/gcc-4.8.2 --enable-languages=c,c++ Thread model: posix gcc version 4.8.2 (GCC) > cat test.c void bar(void); void foo(void) { struct { int x; } y; bar(); } When compiled with `gcc -fexceptions -O0 -c test.c`, the above code generates cleanup code for stack unwinding purposes, referencing __gcc_personality_v0; this necessitates linking with shared-libgcc. I am not sure this is really a bug, but versions of gcc older than 4.7 do not generate cleanup code for this example; neither does gcc 4.8 when the local variable is replaced by `int y;`. Moreover, according to the gcc documentation, there are "several situations" (I have been unable to find more a detailed specification) in which linking with shared-libgcc is necessary, which includes code throwing or catching exceptions, but should -- as far as I can see -- *not* include c code just passing through exceptions. Tested on x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu -m32, and i386-pc-solaris2.11, using gcc 4.7.1, 4.7.3, and 4.8.2. gcc 4.6.4 and earlier tested versions are not affected. I have been unable to test gcc 4.7.0.