crt: gccmain: Make __do_global_dtors/__do_global_ctors/__main compatible with libgcc

libgcc's __do_global_dtors is incrementing callback iteration pointer
before invoking the callback. This is probably a guard which allows
callback function to call the __do_global_dtors() without invoking the
callback function itself second time.

libgcc's __do_global_ctors is comparing first element of __CTOR_LIST__[]
against -1 with casting both of them to __SIZE_TYPE__ instead of unsigned
long. This has effect for 64-bit windows systems as unsigned long type on
them is 32-bit but __SIZE_TYPE__ is 64-bit.

Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/crt/gccmain.c b/mingw-w64-crt/crt/gccmain.c
index 13ef04f..e2eb08b 100644
--- a/mingw-w64-crt/crt/gccmain.c
+++ b/mingw-w64-crt/crt/gccmain.c
@@ -23,18 +23,18 @@
 
   while (*p)
     {
-      (*(p)) ();
       p++;
+      (*(p-1)) ();
     }
 }
 
 void
 __do_global_ctors (void)
 {
-  unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0];
-  unsigned long i;
+  __SIZE_TYPE__ nptrs = (__SIZE_TYPE__) __CTOR_LIST__[0];
+  __SIZE_TYPE__ i;
 
-  if (nptrs == (unsigned long) -1)
+  if (nptrs == (__SIZE_TYPE__) -1)
     {
       for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
     }
@@ -47,12 +47,11 @@
   atexit (__do_global_dtors);
 }
 
-static int initialized = 0;
-
 __attribute__((used)) /* required for gcc -flto -Ofast */
 void
 __main (void)
 {
+  static int initialized = 0;
   if (!initialized)
     {
       initialized = 1;