Merged from trunk rev. 3772:
2010-11-03  Kai Tietz  <kai.tietz@onevision.com>
	* crt/crtexe.c: Ensure to align stack for 32-bit
	to 16-bytes for SSE sake in main.


git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/branches/releases/v1.0@3803 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/ChangeLog b/mingw-w64-crt/ChangeLog
index eacb2b0..519348e 100644
--- a/mingw-w64-crt/ChangeLog
+++ b/mingw-w64-crt/ChangeLog
@@ -2,6 +2,13 @@
 
 	* crt/tlssup.c (_tls_used): Cleanup _WIN64 ifdefs.
 
+2010-10-06  Ozkan Sezer  <sezeroz@gmail.com>
+
+	Merged from trunk rev. 3772:
+	2010-11-03  Kai Tietz  <kai.tietz@onevision.com>
+	* crt/crtexe.c: Ensure to align stack for 32-bit
+	to 16-bytes for SSE sake in main.
+
 2010-10-19  Tsukasa Ooi  <li@livegrid.org>
 
 	* intrincs/__movsb.c: New.
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index 4a0328c..6440ed1 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -186,7 +186,16 @@
   STARTUPINFO StartupInfo;
   WINBOOL inDoubleQuote = FALSE;
   memset (&StartupInfo, 0, sizeof (STARTUPINFO));
-  
+
+#ifndef _WIN64
+  /* We need to make sure that this function is build with frame-pointer
+     and that we align the stack to 16 bytes for the sake of SSE ops in main
+     or in functions inlined into main.  */
+  lpszCommandLine = (_TCHAR *) alloca (32);
+  memset (lpszCommandLine, 0xcc, 32);
+  asm  __volatile__  ("andl $-16, %%esp" : : : "%esp");
+#endif
+
   if (mingw_app_type)
     GetStartupInfo (&StartupInfo);
   {
@@ -239,31 +248,31 @@
     if (mingw_app_type)
       {
 #ifdef WPRFLAG
-    lpszCommandLine = (_TCHAR *) _wcmdln;
+	lpszCommandLine = (_TCHAR *) _wcmdln;
 #else
-    lpszCommandLine = (char *) _acmdln;
+	lpszCommandLine = (char *) _acmdln;
 #endif
-    while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote))
-      {
-	if (*lpszCommandLine == DQUOTECHAR)
-	  inDoubleQuote = !inDoubleQuote;
-#ifdef _MBCS
-	if (_ismbblead (*lpszCommandLine))
+	while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine && inDoubleQuote))
 	  {
-	    if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
-	      lpszCommandLine++;
-	  }
+	    if (*lpszCommandLine == DQUOTECHAR)
+	      inDoubleQuote = !inDoubleQuote;
+#ifdef _MBCS
+	    if (_ismbblead (*lpszCommandLine))
+	      {
+		if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */
+		  lpszCommandLine++;
+	      }
 #endif
-	++lpszCommandLine;
-      }
-    while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
-      lpszCommandLine++;
+	    ++lpszCommandLine;
+	  }
+	while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
+	  lpszCommandLine++;
 
-    __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
-    __mingw_winmain_lpCmdLine = lpszCommandLine;
-    __mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
-				StartupInfo.wShowWindow : SW_SHOWDEFAULT;
-    }
+	__mingw_winmain_hInstance = (HINSTANCE) &__ImageBase;
+	__mingw_winmain_lpCmdLine = lpszCommandLine;
+	__mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ?
+				    StartupInfo.wShowWindow : SW_SHOWDEFAULT;
+      }
     duplicate_ppstrings (argc, &argv);
 #ifdef WPRFLAG
     __winitenv = envp;