p2736.C Is dtor order guaranteed?
H.J. Lu
hjl@lucon.org
Wed Jul 22 16:13:00 GMT 1998
>
> > As far as I can tell, the only complete solution involves replacing atexit.
>
> Yes, I've seen this restriction. I think that autoconf could determine
> whether the system accepts at least 64 or so atexit calls; in
> addition, we could make a list of systems where atexit is known to be
> broken.
>
> Alternatively, we could make a list of systems where we know that
> atexit has no such restriction.
>
I believe Linux has no such restriction. However, I'd like to revert
back to __DTOR_LIST__ if a shared library is loaded via dlopen.
Otherwise, we will get a core dump after dlclose when the program
exits. We can put a restriction on dlopened objects that they cannot
call atexit explicitly or implicitly in C or C++.
Ulrich, can we expend the dynamic linker in glibc to let the shared
library know if it is loaded via dlopen? If we can do that, the change
to egcs will be simple:
static func_ptr __CTOR_END__[];
static func_ptr __DTOR_END__[];
static void
__do_global_ctors_aux ()
{
func_ptr *p;
if (dlopened)
for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
(*p) ();
else
{
func_ptr *dp = __CTOR_END__ - 1;
for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--, dp--)
{
(*p) ();
atexit (dp);
}
*(dp + 1) = NULL;
}
}
Can we fill up a specific data section with 1 in dynamic linker? If
we can do that, we can put a static variable in the ".dlopened" section
and dlopen will fill it up with 1.
Thanks.
H.J.
More information about the Gcc
mailing list