This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/5313: unable to catch exceptions thrown from subthreads during destruction of global objects in shared libraries



>Number:         5313
>Category:       c++
>Synopsis:       unable to catch exceptions thrown from subthreads during destruction of global objects in shared libraries
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 08 09:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     jc@roguewave.com
>Release:        gcc version 3.0.2
>Organization:
>Environment:
The operating system is Solaris 8 (SunOS 5.8).  The
complete output of 'g++ -v' is:

Reading specs from /package/1/compilers/g++/3.0.2/bin/../lib/gcc-lib/sparc-sun-solaris2.8/3.0.2/specs
Configured with: ../gcc-3.0.2/configure --prefix=/nfs/packages/mdx/Solaris/compilers/g++/3.0.2
Thread model: posix
gcc version 3.0.2
>Description:
With gcc 3.0.2 (or earlier), under very particular 
circumstances, some exceptions will not be caught.

Specifically, if an exception is thrown from a subthread 
after main() has returned but before the main thread has 
terminated (that is, during the destruction of a global 
object), then the exception cannot be caught if the global 
object resides within a shared library.

Instead, abort() is called and the program terminates on 
SIGKILL.  The stack trace is as follows:

#0  0xff059bf0 in __sigprocmask () from /usr/lib/libthread.so.1
#1  0xff04e628 in _resetsig () from /usr/lib/libthread.so.1
#2  0xff04dd18 in _sigon () from /usr/lib/libthread.so.1
#3  0xff050e8c in _thrp_kill () from /usr/lib/libthread.so.1
#4  0xff0c9b10 in raise () from /usr/lib/libc.so.1
#5  0xff0b512c in abort () from /usr/lib/libc.so.1
#6  0xff251528 in ?? ()
    at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/vec.cc:52
   from /package/1/compilers/g++/3.0.2/lib/libstdc++.so.3
#7  0xff251574 in ?? ()
    at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/vec.cc:52
   from /package/1/compilers/g++/3.0.2/lib/libstdc++.so.3
#8  0xff2516e0 in ?? ()
    at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/vec.cc:52
   from /package/1/compilers/g++/3.0.2/lib/libstdc++.so.3
#9  0x10cd8 in fcn ()

If any of the conditions are not met--if the exception is 
thrown before main() returns, if the exception is thrown 
from the main thread rather than a subthread, or if the 
global object resides in a static library--then the 
exception can be caught, and the program can terminate 
normally.
>How-To-Repeat:
g++ -pthreads complete.cpp -fPIC -mimpure-text -shared -o libglobal.so
g++ -pthreads -DMAIN complete.cpp -L. -o thr -lglobal -lposix4 -lpthread -lnsl
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
./thr

The test case begins by creating a subthread.  The main 
thread and the subthread enter loops that periodically 
sleep.  After the main() exits this loop, it sets a flag 
to indicate that the shutdown process has begun.  After 
main() returns, the destructor for a Global object in 
libglobal.so enters a loop that periodically sleeps; this 
prevents the main thread from terminating, and allows the 
subthread to continue running.  In its next loop iteration, 
the subthread notices the shutdown flag and throws an 
exception.  Its attempt to catch this exception fails with 
gcc, but succeeds with other compilers.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-unknown-content-type-cppfile; name="complete.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="complete.cpp"

ZXh0ZXJuICJDIiB7CiAgZXh0ZXJuIHVuc2lnbmVkIHNsZWVwKHVuc2lnbmVkKTsKfQoKY2xhc3Mg
R2xvYmFsIHsKICBwdWJsaWM6CiAgICB+R2xvYmFsKHZvaWQpOwp9OwoKI2lmbmRlZiBNQUlOCgpH
bG9iYWw6On5HbG9iYWwodm9pZCkKewogIGZvciAoaW50IGkgPSAwOyBpIDwgMTA7ICsraSkgewog
ICAgc2xlZXAoMSk7CiAgfSAvLyBmb3IKfQoKR2xvYmFsIGc7CgojZWxzZQoKI2luY2x1ZGUgPHB0
aHJlYWQuaD4KCmV4dGVybiBHbG9iYWwgZzsKCmludCBleGl0aW5nID0gMDsKCmV4dGVybiAiQyIg
ewogIHZvaWQqIGZjbih2b2lkICphcmcpOwp9Cgp2b2lkKgpmY24odm9pZCAqYXJnKQp7CiAgdHJ5
IHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgKytpKSB7CiAgICAgIGlmIChleGl0aW5nKSB7
CiAgICAgICAgdGhyb3cgNDI7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgc2xlZXAoMyk7CiAgICAg
IH0gLy8gZWxzZQogICAgfSAvLyBmb3IKCiAgfSBjYXRjaCAoLi4uKSB7fQoKICByZXR1cm4gKHZv
aWQqKTA7Cn0KCmludAptYWluKCkKewogIHB0aHJlYWRfdCBzdWJ0aHJlYWQ7CiAgcHRocmVhZF9j
cmVhdGUoJnN1YnRocmVhZCwgKHB0aHJlYWRfYXR0cl90KikwLCBmY24sICh2b2lkKikwKTsKCiAg
Zm9yIChpbnQgaSA9IDA7IGkgPCA1OyArK2kpIHsKICAgIHNsZWVwKDEpOwogIH0gLy8gZm9yCgog
IGV4aXRpbmcgPSAxOwogIHJldHVybiAwOwp9CgojZW5kaWYK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]