Bug 25515 - broken exceptions with -Os ?
Summary: broken exceptions with -Os ?
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 3.4.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-21 14:56 UTC by Pawel Sikora
Modified: 2005-12-25 01:07 UTC (History)
1 user (show)

See Also:
Host: amd64-linux
Target: amd64-linux
Build: amd64-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase (643 bytes, application/octet-stream)
2005-12-21 14:57 UTC, Pawel Sikora
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2005-12-21 14:56:55 UTC
$ 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)
Comment 1 Pawel Sikora 2005-12-21 14:57:29 UTC
Created attachment 10545 [details]
testcase
Comment 2 Pawel Sikora 2005-12-21 18:02:55 UTC
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.
Comment 3 Pawel Sikora 2005-12-21 18:30:54 UTC
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?
Comment 4 Andrew Pinski 2005-12-25 01:07:59 UTC
The code is invalid as the undwinding of the stack also dlclose the shared library which causes the typeinfo to go back.