$ make clean all OPT=-Os rm -rf *.ii *.o *.s lib.so main g++ -Os lib.cpp -fPIC -shared -Wl,-soname,lib -o lib.so g++ -Os main.cpp -o main -ldl LD_LIBRARY_PATH=./ ./main Memory fault works fine with -O[0123]. $ g++ -v Reading specs from /usr/lib64/gcc/amd64-pld-linux/3.4.5/specs Configured with: ../configure --prefix=/usr --libdir=/usr/lib64 --libexecdir=/usr/lib64 --infodir=/usr/share/info --mandir=/usr/share/man --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-languages=c,c++,f77,objc,ada,java --enable-c99 --enable-long-long --enable-nls --with-gnu-as --with-gnu-ld --with-system-zlib --with-slibdir=/lib64 --without-x amd64-pld-linux Thread model: posix gcc version 3.4.5 (PLD Linux)
Created attachment 10545 [details] testcase
if I change the myexception definition to: struct myexception : public std::exception {}; then testcase will crashe at all optimization levels on i386/amd64. Program received signal SIGSEGV, Segmentation fault. 0xb7ef7a06 in ?? () (gdb) bt #0 0xb7ef7a06 in ?? () #1 0xb7eb42eb in __cxa_throw () from /usr/lib/libstdc++.so.6 #2 0xb7dde6ed in _Unwind_DeleteException () from /lib/libgcc_s.so.1 #3 0xb7eb34e6 in __cxa_end_catch () from /usr/lib/libstdc++.so.6 #4 0x08048777 in main () at main.cpp:25 this backtrace comes from gcc-4.1/i386.
i suppose the lib.so and myexception's typeinfo is unavailable after unwinding the try{} block (due to ~dll/dlclose) which is a reason why the program crash. am i rigth?
The code is invalid as the undwinding of the stack also dlclose the shared library which causes the typeinfo to go back.