Description of problem: I get a segfault compiling a simple C++ program with -static under the following conditions: . x86_64 cpu (Opteron 254) . compile with -static switch . program includes a call to gethostbyaddr . program throws an exception that should be caught This does not crash on 32-bit machines running WS3. Version-Release number of selected component (if applicable): RedHat WS3 Taroon 7 g++ 3.2.3 standard binutils or version glibc 2.3.2-95.39 How reproducible: Steps to Reproduce: 1. Compile attachment on Opteron with g++ -static -o ts throwseg.cpp 2. run ./ts Actual results: observe segfault with backtrace like: $ gdb ts core Program received signal SIGSEGV, Segmentation fault. 0x0000000000442f2e in get_cie_encoding () (gdb) bt #0 0x0000000000442f2e in get_cie_encoding () #1 0x000000000044335a in classify_object_over_fdes () #2 0x0000000000443fd2 in init_object () #3 0x00000000004438b2 in search_object () #4 0x0000000000443936 in _Unwind_Find_registered_FDE () #5 0x0000000000443d49 in _Unwind_Find_FDE () #6 0x0000000000441b45 in uw_frame_state_for () #7 0x00000000004420b7 in uw_init_context_1 () #8 0x0000000000442332 in _Unwind_RaiseException () #9 0x0000000000434646 in __cxa_throw () #10 0x00000000004002d5 in main () Expected results: If the "ts" program ran to completion, it should output to stderr: about to throw exception compiling static, we never make it here Additional info: Works on 32-bit processors running WS3.
Created attachment 132853 [details] Sample code to reproduce segfault
This is caused by a binutils bug, .eh_frame section isn't terminated in some rare circumstances. The fix is quite involved though and the benefits outweight the risks this late in the RHEL3 development. There is an easy workaround: 1) don't link static, it is almost always a bad choice, see http://people.redhat.com/drepper/no_static_linking.html 2) if after reading it you are still convinced you need to link something statically, to workaround this bug you can just link an empty function object after -lc, as in: echo 'void ehframe_dummy (void) { }' > ehframe_dummy.C g++ -static ... -lc ehframe_dummy.C (-lc ehframe_dummy.C added to whatever you had on your command line before)