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?


> 
> Robert Lipe <robertl@dgii.com> writes:
> 
> > For COFF, the order is not reversed:
> 
> > init5.C is XFAILed on all targets so it never shows up in the testsuite
> > as a failure.  If I manually run it, it aborts on both COFF and ELF.
> 
> So it is broken.  init5.C will test for this kind of misbehavior too,
> but egcs can't currently handle destruction of local static variables
> interspersed with global variables.

The current implementation is wrong. We have to put the destructors
for local static variables onto __DTOR_LIST__. Otherwise, we will also
run into problems with dlopen/dlclose. The current scheme uses atexit.
It may put a dlclosed function on the exit list. The result is core
dump when you call a function in an unloaded memory.

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.

It might work.

-- 
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]