On Sat, Nov 23, 2013 at 1:10 AM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > On Thu, Nov 21, 2013 at 1:20 AM, vijay nag <vijunag@xxxxxxxxx> wrote: >> >> I tried creating a small binary to demonstrate the problem that I had >> been facing with my gcc-4.7.2 tool chain and glibc-2.17. The library >> and binaries were created using exact CFLAGS, CXXFLAGS et al. >> Strangely, the problem doesn't manifest in my example program :(. On >> further hacking and debugging libgcc, I found that >> _Unwind_RaiseException() was always "returning" in failure case with >> return code _URC_END_OF_STACK. Does it mean that FDE is missing for >> the function which is suppose to catch the exception ? How do I check >> if an FDE exists for a particular function or not ? > > You can use readelf --debug=frames to examine the unwind information > in an executable or object file. > > Ian Ok I found the problem. There seems to exist stack similar stack unwind definition in glibc as well and linker was picking definitions from libc rather than from libgcc_s.so since libc was first in the default link order although I don't understand why linker is not throwing multiple definition error. Back-trace at libgcc/unwind in a normal working application was (gdb) bt #0 _Unwind_Find_FDE (pc=0xb7eb47f8 <_Unwind_RaiseException+56>, bases=0xbffff174) at ../../../../gcc/libgcc/unwind-dw2-fde-dip.c:451 #1 0xb7eb3e21 in uw_frame_state_for (context=context@entry=0xbffff120, fs=fs@entry=0xbffff010) at ../../../../gcc/libgcc/unwind-dw2.c:1179 #2 0xb7eb4362 in uw_init_context_1 (context=context@entry=0xbffff120, outer_cfa=outer_cfa@entry=0xbffff300, outer_ra=0xb7f40201 <__cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*))+97>) at ../../../../gcc/libgcc/unwind-dw2.c:1500 #3 0xb7eb47f9 in _Unwind_RaiseException (exc=0x52048) at ../../../../gcc/libgcc/unwind.inc:88 #4 0xb7f40201 in __cxxabiv1::__cxa_throw (obj=0x52068, tinfo=0x51780 <_ZTIi@@CXXABI_1.3>, dest=0x0) at ../../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:78 #5 0x00048d41 in PrintException () at exception/Exception.cpp:26 #6 0x00048ce0 in main () at exception/main.c:27 (gdb) and Back-trace at glibc/unwind in a non-working application (gdb) bt #0 _Unwind_Find_FDE (pc=0xb7d217f8 <_Unwind_RaiseException+56>, bases=0xbfffb8d4) at ../sysdeps/generic/unwind-dw2-fde-glibc.c:253 #1 0xb7d20e21 in uw_frame_state_for (context=context@entry=0xbfffb880, fs=fs@entry=0xbfffb770) at ../../../../gcc/libgcc/unwind-dw2.c:1179 #2 0xb7d21362 in uw_init_context_1 (context=context@entry=0xbfffb880, outer_cfa=outer_cfa@entry=0xbfffba60, outer_ra=0xb7f40201 <__cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*))+97>) at ../../../../gcc/libgcc/unwind-dw2.c:1500 #3 0xb7d217f9 in _Unwind_RaiseException (exc=0x172a3bd0) at ../../../../gcc/libgcc/unwind.inc:88 #4 0xb7f40201 in __cxxabiv1::__cxa_throw (obj=0x172a3bf0, tinfo=0x151ea200 <_ZTIi@@CXXABI_1.3>, dest=0x0) at ../../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:78 So I had to explicitly specify this order "-Wl,--start-group -lgcc_s -lgcc -lc -Wl,--end-group" in linker command line arguments to pick-up definitions from libgcc_s.so rather than from libc.