The future of __main (was Re: __main call for c++ on sparc-elf target)

Chris Lattner sabre@nondot.org
Thu Jun 26 16:32:00 GMT 2003


Jim Wilson wrote:
> __main is archaic. ELF systems use the .init/.fini sections to run
> static construtors/destructors. crti.o defines function prologues for
> init/fini, crtn.o defines function epilogues, crt0.o branches to the
> init function at startup, and registers passes the fini function to
> atexit.
...

> Some of the older embedded ELF targets aren't using .init/.fini yet, but
> should be fixed to do so. Perhaps sparc-elf is one of them? It could be
> broken from lack of maintenance.

I just wanted to say that I hope that __main never goes away: it is a
great way to expose the information about static ctors and dtors to the
compiler, which the "magic" .init/.fini sections doen't do as well.  In
particular, for most C programs (those which don't ctor or dtors), the
LLVM compiler is able to completely eliminate the overhead of the
_possibility_ of having ctors and dtors (general DCE algorithms just
delete the code automatically), which leaves __main empty for codes where
it is safe.

I don't see how to implement this important size optimization using crt0.o
and .init/.fini.  Will support for __main stay around forever, or should I
be looking for alternatives?  I would really like to avoid having to put
in special purpose code to handle this optimization.

Thanks,

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



More information about the Gcc mailing list