diff mbox

[i386] Enable -mstackrealign with SSE on 32-bit Windows

Message ID 5969976.Bvae8NF9fS@polaris
State New
Headers show

Commit Message

Eric Botcazou Dec. 15, 2015, 8:42 a.m. UTC
Hi,

even the latest versions of Windows still guarantee only a 4-byte alignment of 
the stack in 32-bit mode, which doesn't play nice with some SSE instructions.
That's why some projects enable -mstackrealign by default on 32-bit Windows:
  https://bugzilla.mozilla.org/show_bug.cgi?id=631252
This eliminates an entire class of bugs which are sometimes hard to reproduce.

The attached patch automatically enables it when SSE instructions are used.
That's a good compromise IMO because the default configuration of the compiler 
on this platform doesn't enable SSE so should presumably not be modified.

Tested on i686-pc-mingw32, OK for the mainline?


2015-12-15  Eric Botcazou  <ebotcazou@adacore.com>

	* config/i386/cygming.h (STACK_REALIGN_DEFAULT): Define.


2015-12-15  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc.target/i386/stack-realign-win.c: New test.
diff mbox

Patch

Index: config/i386/cygming.h
===================================================================
--- config/i386/cygming.h	(revision 231605)
+++ config/i386/cygming.h	(working copy)
@@ -39,6 +39,11 @@  along with GCC; see the file COPYING3.
 #undef MAX_STACK_ALIGNMENT
 #define MAX_STACK_ALIGNMENT  (TARGET_SEH ? 128 : MAX_OFILE_ALIGNMENT)
 
+/* 32-bit Windows aligns the stack on a 4-byte boundary but SSE instructions
+   may require 16-byte alignment.  */
+#undef STACK_REALIGN_DEFAULT
+#define STACK_REALIGN_DEFAULT TARGET_SSE
+
 /* Support hooks for SEH.  */
 #undef  TARGET_ASM_UNWIND_EMIT
 #define TARGET_ASM_UNWIND_EMIT  i386_pe_seh_unwind_emit