Let's see if I can make sense.

So that globsl C++ contructors are run, gcc puts a magic
call to a special function right at the top of `main'.  On most
targets that need it, it's called __main, but on ARM,
it's called __gccmain.   Now, in addition to this magic
call that gcc puts there itself, there's a call to __gccmain
somewhere in libmingw.a before the user `main' is called.

src/mingw/crt3.c:
  /* From libgcc.a, __main calls global class constructors,
     __do_global_ctors, which registers __do_global_dtors as the first
     entry of the private atexit table we have just initialised  */
  __gccmain();

(read that __main as __gccmain, though).

__gccmain can come from two places, either from libgcc.a or from
libmingw.a/gccmain.c.  However, the linker will pull in just
one of those.

Calls to __gccmain are idempotent.  You can call it a million
times, and it will still only run the contructors once.

However, if your x86 CE toolchain generates a call to __main instead
of to __gccmain at the top of `main', then the linker will pull
in __gccmain from libmingw.a, and that will be called by crt3.c;
and, will pull in __main from libgcc.a, and your program will
call that on entry to `main'.  It's likely separate instances of
basically the same function are using a different global var
to check if they've ran already, so, your contructors will run
twice, and so will your destructors.

You need to either make both calls be to __main, or to __gccmain,
never to both.

-- 
Pedro Alves

------------------------------------------------------------------------------
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to