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

Re: PATCH: Add --enable-__cxa_atexit


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


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