The future of __main (was Re: __main call for c++ on sparc-elf target)
Chris Lattner
sabre@nondot.org
Thu Jun 26 16:42:00 GMT 2003
On Thu, 26 Jun 2003, Paul Koning wrote:
> Chris> I don't see how to implement this important size optimization
> Chris> using crt0.o and .init/.fini. Will support for __main stay
> Chris> around forever, or should I be looking for alternatives? I
> Chris> would really like to avoid having to put in special purpose
> Chris> code to handle this optimization.
>
> I don't understand what important size optimization you're talking
> about here. If a particular program has no constructors/destructors,
> I would hope the compiler and/or linker could eliminate the code that
> deals with them from .init just as well. Perhaps they don't currently
> do that, but that doesn't mean hanging on to the obsolete mechanism is
> a good idea. (In any case, aren't we talking about a few words here?)
It's much much than a few words of data: it is all of the code which gets
invoked to sort the ctor/dtor lists by priority, register the atexit
handler, and walk the ctor/dtor lists, calling the function pointers. If
the program does not have ctors/dtors, the list itself is small (in my
implementation, basically just a null terminator), but the code that
implements it is a fairly substantial percentage of the size of small
programs.
> More importantly, the old mechanism is completely broken for an
> important case: it doesn't cope with shared libraries that contain
> static objects that need construction or destructing.
This is a great point. In our system, we plan to have dlopen/close walk
exactly the same lists that __main does, as necessary. Of course, we
haven't implemented it yet, but we *think* it should work just fine. :)
My main point is just that I didn't want support for __main to go away
unless absolutely necessary. I'm sure we could figure out other ways to
do this optimization, but __main is so convenient. :)
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the Gcc
mailing list