This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12159] New: static C++ objects inside global functions (within a shared library) cause crash on program exit on Linux
- From: "tim dot crook at adobe dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Sep 2003 21:34:03 -0000
- Subject: [Bug c++/12159] New: static C++ objects inside global functions (within a shared library) cause crash on program exit on Linux
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12159
Summary: static C++ objects inside global functions (within a
shared library) cause crash on program exit on Linux
Product: gcc
Version: 3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tim dot crook at adobe dot com
CC: gcc-bugs at gcc dot gnu dot org
If you have a function like:
ComplexClass
foo ()
{
static ComplexClass blah;
return blah;
}
in a shared library and call it at least once (to initialize it with the
constructor), when the shared library is unloaded before main terminates, your
program will have a segment fault.
Under the covers, the code being generated for destruction of "blah" is done
using the C function atexit. A function "__tcf_0" was generated by the compiler
to do the cleanup - I turned off inlining.
By the definition in the Linux man page, the functions registered with atexit
are called on program termination. As the code segment for the shared library
has been deleted, this causes a memory fault.
On Solaris, the man page defines atexit functions as being called when EITHER
objects are unloaded OR program termination occurs. As a result, this problem
never happens on Solaris.
The solution to this problem may be to hook __tcf_0 into the function _fini,
which is called when a shared library is unloaded. It appears that for each
module compiled with at least one global static inside a global function, a
__tcf_0 is generated.