FW: g++ 3.0.2 bug: unable to catch exceptions thrown from subthr eads during destruction of global objects in shared libraries

Carolyn Wasikowski jc@roguewave.com
Tue Dec 18 18:42:00 GMT 2001


I would like to update my earlier bug report.  The bug can be reproduced
with gcc 2.96 on RedHat Linux 7.1 and with gcc 2.95.2 on Solaris 8.

-JC


> -----Original Message-----
> From:	Carolyn Wasikowski 
> Sent:	Tuesday, December 18, 2001 2:18 PM
> To:	'bug-gcc@gnu.org'
> Subject:	g++ 3.0.2 bug:  unable to catch exceptions thrown from
> subthreads during destruction of global objects in shared libraries
> 
> [Note:  I attempted to submit this bug to
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl, but was unable to attach more than
> one file to the bug report.  Since the bug involves two source files--one
> for main() and the other for a shared library--you're getting email with
> MIME attachments instead.  Hope this isn't too inconvenient.]
> 
> Reporter's email:  jc@roguewave.com
> 
> Category:  c++ - C++ front end
> 
> Synopsis:  unable to catch exceptions thrown from subthreads during
> destruction of global objects in shared libraries
> 
> Confidential:  no
> 
> Severity:  critical
> 
> Priority:  high
> 
> Class:  sw-bug
> 
> Release:  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
> 
> Environment:  Solaris 8 (SunOS 5.8)
> 
> Description:
> With gcc 3.0.2 or 3.0.1 (but not 2.96 or 2.95), 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  0x13e5c in spew (arg=0x0) at thr.cpp:18
> 
> 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.
> 
> File attachments:
> global.ii.gz is a gzipped, preprocessed source file.  global.output is the
> output produced when creating global.ii via:
> 
> 	g++ -v -save-temps -Wall -pthreads -g -c global.cpp -fPIC
> -mimpure-text -shared 
> 
>  <<global.ii.gz>>  <<global.output>> 
> Likewise, thr.ii.gz is a gzipped, preprocessed source file, and thr.output
> is the output produced when creating thr.ii via:
> 
> 	g++ -v -save-temps -Wall -pthreads -g -c thr.cpp
> 
>  <<thr.ii.gz>>  <<thr.output>> 
> How to repeat:
> Compile global.ii into a shared library with:
> 
> 	gunzip global.ii.gz
> 	g++ -pthreads global.ii -fPIC -mimpure-text -shared -o libglobal.so
> 
> Compile thr.ii into a test case with:
> 
> 	gunzip thr.ii.gz
> 	g++ -pthreads thr.ii -L. -o thr -lglobal -lposix4 -lpthread -lnsl
> 
> Run the test case with:
> 
> 	export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH
> 	./thr
> 
> The test case begins by creating a subthread.  The main thread and the
> subthread then begin to periodically print diagnostics to cout.  After
> main() finishes with these diagnostics, it sets a flag to indicate that
> the shutdown process has begun.  After main() returns, the destructor for
> a Global object in libglobal.so begins to print statements to cout; this
> prevents the main thread from terminating, and allows the subthread to
> continue running.  Before printing its next diagnostic statement, the
> subthread notices the shutdown flag and throws an exception.  Its attempt
> to catch this exception fails with gcc 3.0.1 and 3.0.2, but succeeds with
> other compilers and earlier versions of gcc.
> 
> -JC
> 
> jc@roguewave.com
> http://www.roguewave.com
> (541)754-4094
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global.ii.gz
Type: application/octet-stream
Size: 76688 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20011218/fcecccdd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global.output
Type: application/octet-stream
Size: 2397 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20011218/fcecccdd/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: thr.ii.gz
Type: application/octet-stream
Size: 76821 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20011218/fcecccdd/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: thr.output
Type: application/octet-stream
Size: 2349 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20011218/fcecccdd/attachment-0003.obj>


More information about the Gcc-bugs mailing list