This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: Add --enable-__cxa_atexit
- From: martin at v dot loewis dot de (Martin v. Loewis)
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: "H . J . Lu" <hjl at lucon dot org>, Jakub Jelinek <jakub at redhat dot com>, Jack Howarth <howarth at bromo dot med dot uc dot edu>, gcc-patches at gcc dot gnu dot org
- Date: 06 Jun 2002 22:29:04 +0200
- Subject: Re: PATCH: Add --enable-__cxa_atexit
- References: <5670000.1023319933@localhost>
Mark Mitchell <mark@codesourcery.com> writes:
> And, if V3 does not use static initializers then there is no cost
> associated with using -fuse-cxa-atexit to compile it.
That is not true. With -fuse-cxa-atexit, global static variables are
registered with atexit, without that, they are not. So there is an
atexit call for every global as the overhead; with
-fno-use-cxa-atexit, the (static) linker will produce the .dtors array
that is not considered until shutdown.
Now, as for the cost of atexit - it could be O(log n) for n global
objects, but currently is O(n) (in glibc 2.2). The O(n) cost is caused
by the fact that it iterates over a linked list of all registered
atexit functions to find the last one (even though it iterates over it
in chunks of 32 functions); that could be improved. However, you
cannot achieve O(1) per atexit call, since you need to perform a
malloc to reserve more slots from time to time. The most efficient
strategy is to double the size every time, which gives you O(log n)
(assuming malloc is O(1)).
Somebody please correct me if I'm wrong.
Regards,
Martin