i386.h (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): New.
authorRichard Henderson <rth@redhat.com>
Mon, 6 Aug 2001 16:38:18 +0000 (09:38 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Mon, 6 Aug 2001 16:38:18 +0000 (09:38 -0700)
* config/i386/i386.h (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): New.
* function.c (expand_main_function): Implement it.
* doc/tm.texi: Document it.

From-SVN: r44664

gcc/ChangeLog
gcc/config/i386/i386.h
gcc/doc/tm.texi
gcc/function.c

index 603ee3ed4942197c24a14363f03989ced676b226..da7df11b66dfebcb1b65505f7b74ed1a72adf19e 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-06  Richard Henderson  <rth@redhat.com>
+
+       * config/i386/i386.h (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN): New.
+       * function.c (expand_main_function): Implement it.
+       * doc/tm.texi: Document it.
+
 2001-08-06  Stan Shebs  <shebs@apple.com>
 
        * doc/install.texi: Document powerpc-*-darwin* details.
index 408ea2bac120dddb4782a392b13406b703c91b60..e145cae3e8d24f1842dcd8f81e137c9f0a5e0714 100644 (file)
@@ -640,6 +640,13 @@ extern int ix86_arch;
    aligned; the compiler cannot rely on having this alignment.  */
 #define PREFERRED_STACK_BOUNDARY ix86_preferred_stack_boundary
 
+/* As of July 2001, many runtimes to not align the stack properly when
+   entering main.  This causes expand_main_function to forcably align
+   the stack, which results in aligned frames for functions called from
+   main, though it does nothing for the alignment of main itself.  */
+#define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN \
+  (ix86_preferred_stack_boundary > STACK_BOUNDARY)
+
 /* Allocation boundary for the code of a function. */
 #define FUNCTION_BOUNDARY 16
 
index e9c747ac7e4ef91c0c8b01e93ab74c10d5568577..4bcf82748b520d519664f76701e612858a509552 100644 (file)
@@ -1028,6 +1028,12 @@ for the desired alignment (measured in bits).  If @code{STACK_BOUNDARY} is
 also defined, this macro must evaluate to a value equal to or larger
 than @code{STACK_BOUNDARY}.
 
+@findex FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
+@item FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
+A C expression that evaluates true if @code{PREFERRED_STACK_BOUNDARY} is
+not guaranteed by the runtime and we should emit code to align the stack
+at the beginning of @code{main}.
+
 @cindex @code{PUSH_ROUNDING}, interaction with @code{PREFERRED_STACK_BOUNDARY}
 If @code{PUSH_ROUNDING} is not defined, the stack will always be aligned
 to the specified boundary.  If @code{PUSH_ROUNDING} is defined and specifies
index 6015366c4b11a3195eb3693fe8782ef7e25259dc..0c4d7126292c973685c7e0e9c0984ae32925631b 100644 (file)
@@ -6315,10 +6315,35 @@ mark_varargs ()
 void
 expand_main_function ()
 {
-#if !defined (HAS_INIT_SECTION)
+#ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
+  if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
+    {
+      int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
+      rtx tmp;
+
+      /* Forcably align the stack.  */
+#ifdef STACK_GROWS_DOWNWARD
+      tmp = expand_binop (Pmode, and_optab, stack_pointer_rtx,
+                         GEN_INT (-align), stack_pointer_rtx, 1, OPTAB_WIDEN);
+#else
+      tmp = expand_binop (Pmode, add_optab, stack_pointer_rtx,
+                         GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
+      tmp = expand_binop (Pmode, and_optab, tmp, GEN_INT (-align),
+                         stack_pointer_rtx, 1, OPTAB_WIDEN);
+#endif
+      if (tmp != stack_pointer_rtx)
+       emit_move_insn (stack_pointer_rtx, tmp);
+      
+      /* Enlist allocate_dynamic_stack_space to pick up the pieces.  */
+      tmp = force_reg (Pmode, const0_rtx);
+      allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
+    }
+#endif
+
+#ifndef HAS_INIT_SECTION
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0,
                     VOIDmode, 0);
-#endif /* not HAS_INIT_SECTION */
+#endif
 }
 \f
 extern struct obstack permanent_obstack;