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]

[Bug c++/12159] New: static C++ objects inside global functions (within a shared library) cause crash on program exit on Linux


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.


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