This is the mail archive of the gcc@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]

Re: p2736.C Is dtor order guaranteed?


> > One way to fix all these is
> 
> > 1. egcs reserves a slot on __DTOR_LIST__ for the destructor of the
> > local static variable. We can mark it as -1 so that
> > __do_global_dtors_aux won't run it.
> > 2. Put an auxiliary constructor of the local static variable on
> > _CTOR_LIST__ to record some information for the real constructor.
> > 3. The real constructor of the local static variable will put the
> > destructor in the reserved slot on __DTOR_LIST__ and rearrange
> > the order of __DTOR_LIST__ if necessary.
> 
> But that doesn't handle the atexit problem.  The idea of rearranging
> __DTOR_LIST__ is also a bit dodgy.
> 

The problem is we cannot use atexit to register the destructor of
the local static variable. My approach lets the constructor of the
local static variable put the destructor onto __DTOR_LIST__ together
with the global destructors. We should use the same mechanism for
the file-scope destructors. 

The constructor of the local static has 2 passes. When the first
time it is called from __CTOR_LIST__, it does nothing but records
the necessary info for the second pass. The second pass is called
by the function where the local static variable is defined. It will put
the destructor onto __DTOR_LIST__ at the right place.

-- 
H.J. Lu (hjl@gnu.org)


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