On Thu, Nov 23, 2006 at 04:10:44AM +0000, Pedro Alves wrote:
> Kevin O'Connor escreveu:
> > As to a fix - I'm a bit confused by the current mingw crt1.c code.
> > Why do we have WinMainCRTStartup call main() which then calls WinMain.
> > Wouldn't it be simpler to have a dummy WinMain that calls main().
> > This way, the code doesn't have to scan all the command-line arguments
> > if the application isn't interested in them.
Hi Pedro,
If I understand you correctly, MSVCRT and COREDLL are mutually
exclusive. If this is the case, I see no overlap between x86 mingw
and CE mingw in crt1.c. I fear the cost of maintaining the ifdef's
will be larger than the cost of maintaining a separate file for CE's
crt1.c.
> Yes, I also think it would be simpler. But, it requires a gcc change
> (simple one, I think). Currently the __gccmain call is emitted on main,
I don't see why - we can call __gccmain explicitly from the CRT code.
If it gets called again, the subsequent calls will just be ignored.
Attached is a patch that implements a new crt1_ce.c and winmain_ce.c.
With these new files, no changes from x86 mingw are needed to crt1.c
or main.c. Ideally, one should move all the recent CE specific
changes in init.c into winmain_ce.c -- that way no changes to init.c
would be necessary either.
I hope you'll agree that the new files make the process much easier to
understand and will make the changes easier to merge upstream.
I've only tested this with haret (a WinMain app) on a CE5 pda.
Comments?
-Kevin
Index: src/mingw/Makefile.in
===================================================================
--- src/mingw/Makefile.in (revision 821)
+++ src/mingw/Makefile.in (working copy)
@@ -167,13 +167,13 @@
endif
MINGW_OBJS = CRTglob.o CRTfmode.o CRTinit.o dllmain.o gccmain.o \
- main.o crtst.o mthr_stub.o \
+ crtst.o mthr_stub.o \
pseudo-reloc.o pseudo-reloc-list.o cpu_features.o
ifneq (,$(findstring wince,$(target_alias)))
-MINGW_OBJS += abort.o atexit.o assert.o
+MINGW_OBJS += winmain_ce.o abort.o atexit.o assert.o
else
-MINGW_OBJS += CRT_fp10.o txtmode.o
+MINGW_OBJS += main.o CRT_fp10.o txtmode.o
endif
MOLD_OBJS = isascii.o iscsym.o iscsymf.o toascii.o \
@@ -498,8 +498,13 @@
CRTfmode.o: CRTfmode.c
CRTglob.o: CRTglob.c
CRTinit.o: CRTinit.c
+ifneq (,$(findstring wince,$(target_alias)))
+crt1.o: crt1_ce.c
+crt2.o: crt1_ce.c
+else
crt1.o: crt1.c init.c
crt2.o: crt1.c init.c
+endif
crtmt.o: crtmt.c
crtst.o: crtst.c
ctype_old.o: ctype_old.c
@@ -507,6 +512,7 @@
dllcrt2.o: dllcrt1.c
dllmain.o: dllmain.c
main.o: main.c
+winmain_ce.o: winmain_ce.c init.c
oldnames.o: oldnames.c
string_old.o: string_old.c
CRT_fp8.o: CRT_fp8.c
--- /dev/null 2006-09-16 10:05:04.613854500 -0400
+++ src/mingw/crt1_ce.c 2006-11-24 23:03:19.000000000 -0500
@@ -0,0 +1,71 @@
+/*
+ * crt1_ce.c
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within the package.
+ *
+ * Source code for the startup proceedures used by all programs on a
+ * wince system. This code is compiled to make crt1.o, which should be
+ * located in the library path.
+ *
+ */
+
+/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to
+ avoid problems with older GCC. */
+#define __IN_MINGW_RUNTIME
+#include <stdlib.h>
+#include <stdio.h>
+#include <process.h>
+#include <float.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+extern void __gccmain ();
+extern void _pei386_runtime_relocator (void);
+
+/* No atexit on coredll, we must initialize our private version. */
+BOOL __atexit_init(void);
+
+/*
+ * This function is called from the entry point for all programs.
+ */
+void
+WinMainCRTStartup (HINSTANCE hInst, HINSTANCE hPrevInst,
+ LPWSTR lpCmdLine, int nCmdShow)
+{
+ int nRet;
+
+ /*
+ * Initialize floating point unit.
+ */
+ _fpreset (); /* Supplied by the runtime library. */
+
+ /* Adust references to dllimported data that have non-zero offsets. */
+ _pei386_runtime_relocator ();
+
+ /*
+ * Initialize the atexit table.
+ */
+ __atexit_init();
+
+ /* 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();
+
+ /*
+ * Call the main function. If the user does not supply one the one
+ * in the 'libmingw32.a' library will be linked in, and that one
+ * calls main. See winmain_ce.c in the 'lib' dir for more details.
+ */
+
+ nRet = WinMain(hInst, hPrevInst, lpCmdLine, nCmdShow);
+
+ /*
+ * Perform exit processing for the C library. This means
+ * flushing output and calling 'atexit' registered functions.
+ */
+ _cexit ();
+
+ ExitProcess (nRet);
+}
--- /dev/null 2006-09-16 10:05:04.613854500 -0400
+++ src/mingw/winmain_ce.c 2006-11-24 23:04:12.000000000 -0500
@@ -0,0 +1,37 @@
+/*
+ * winmain_ce.c
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is a part of the mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER within the package.
+ *
+ * Extra startup code for applications which do not have a WinMain
+ * function of their own (but do have a main). Generally these are
+ * non-GUI applications, but they don't *have* to be.
+ *
+ */
+
+#include <stdlib.h>
+#include <process.h>
+#include <windows.h>
+
+/* NOTE: The code for initializing the _argv, _argc, and environ variables
+ * has been moved to a separate .c file which is included in both
+ * crt1.c and dllcrt1.c. This means changes in the code don't have to
+ * be manually synchronized, but it does lead to this not-generally-
+ * a-good-idea use of include. */
+#include "init.c"
+
+// Normally, the application will define a WinMain function. However,
+// if the main application does not, this dummy WinMain will call a
+// main() function instead.
+extern int __cdecl
+WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
+ LPWSTR szCmdLine, int nShow)
+{
+ /*
+ * Set up __argc, __argv and _environ.
+ */
+ _mingw32_init_mainargs ();
+
+ return main(_argc, _argv);
+}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel