This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: i386 stack missalignment on main
Hi,
here is 3.0 version of the patch
Mon Jul 30 22:20:59 CEST 2001 Jan Hubicka <jh@suse.cz>
* i386-protos.h (ix86_output_main_function_alignment_hack): Declare.
* i386.c (ix86_output_main_function_alignment_hack): New global
function.
* i386.h (FUNCTION_PROLOGUE): New macro.
* osf1elf.h (FUNCTION_PROLOGUE): Call new function.
* osfrose.h (FUNCTION_PROLOGUE): Likewise.
Index: i386-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386-protos.h,v
retrieving revision 1.36.2.4
diff -c -3 -p -r1.36.2.4 i386-protos.h
*** i386-protos.h 2001/03/07 02:32:33 1.36.2.4
--- i386-protos.h 2001/07/30 20:14:55
*************** extern void ix86_init_builtins PARAMS ((
*** 141,146 ****
--- 141,147 ----
extern rtx ix86_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
#endif
extern void ix86_set_move_mem_attrs PARAMS ((rtx, rtx, rtx, rtx, rtx));
+ extern void ix86_output_main_function_alignment_hack PARAMS ((FILE *f, int));
#endif
Index: i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.211.2.12
diff -c -3 -p -r1.211.2.12 i386.c
*** i386.c 2001/07/23 21:18:36 1.211.2.12
--- i386.c 2001/07/30 20:15:02
*************** ix86_free_from_memory (mode)
*** 8836,8838 ****
--- 8836,8880 ----
? 2
: 4))));
}
+
+ /* Most of current runtimes (Jul 2001) do not align stack properly when
+ entering main, so emit an wrapper to align stack before the real main
+ code is called.
+
+ This can eventually go if we manage to fix the runtimes or teach gcc
+ to dynamically align stack in main automatically.
+
+ Adding check to configure is probably not good idea, as binarry can move
+ from one shared library to older. */
+
+ void
+ ix86_output_main_function_alignment_hack (file, size)
+ FILE *file;
+ int size ATTRIBUTE_UNUSED;
+ {
+ rtx label;
+ char buf[256];
+ /* Check that we see main function with maximally 8 bytes of arguments.
+ if so, emit the hack to align stack for runtimes, where this constraint
+ is broken. */
+ if (strcmp (cfun->name, "main"))
+ return;
+ if (cfun->pops_args || cfun->args_size > 12)
+ return;
+ if (PREFERRED_STACK_BOUNDARY <= 2)
+ return;
+ label = gen_label_rtx ();
+ fprintf (file, "\tpushl\t%%ebp\n");
+ fprintf (file, "\tmovl\t%%esp, %%ebp\n");
+ fprintf (file, "\tandl\t$0xfffffff0, %%esp\n");
+ fprintf (file, "\tpushl\t%%ebp\n");
+ fprintf (file, "\tpushl\t16(%%ebp)\n");
+ fprintf (file, "\tpushl\t12(%%ebp)\n");
+ fprintf (file, "\tpushl\t8(%%ebp)\n");
+ fprintf (file, "\tcall\t");
+ ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (label));
+ assemble_name (file, buf);
+ fprintf (file, "\n\tleave\n");
+ fprintf (file, "\tret\n");
+ ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (label));
+ }
Index: i386.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.147.2.8
diff -c -3 -p -r1.147.2.8 i386.h
*** i386.h 2001/05/30 20:28:42 1.147.2.8
--- i386.h 2001/07/30 20:15:04
*************** extern enum reg_class const regclass_map
*** 2932,2937 ****
--- 2932,2941 ----
extern struct rtx_def *ix86_compare_op0; /* operand 0 for comparisons */
extern struct rtx_def *ix86_compare_op1; /* operand 1 for comparisons */
+ #ifndef FUNCTION_PROLOGUE
+ #define FUNCTION_PROLOGUE(f,s) ix86_output_main_function_alignment_hack(f,s)
+ #endif
+
/*
Local variables:
version-control: t
Index: osf1elf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/osf1elf.h,v
retrieving revision 1.8.4.1
diff -c -3 -p -r1.8.4.1 osf1elf.h
*** osf1elf.h 2001/04/16 18:25:49 1.8.4.1
--- osf1elf.h 2001/07/30 20:15:04
*************** do \
*** 141,146 ****
--- 141,148 ----
char *lprefix = LPREFIX; \
int labelno = profile_label_no; \
\
+ ix86_output_main_function_alignment_hack(FILE,SIZE); \
+ \
if (profile_flag && OSF_PROFILE_BEFORE_PROLOGUE) \
{ \
if (!flag_pic) \
Index: osfrose.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/osfrose.h,v
retrieving revision 1.17.4.1
diff -c -3 -p -r1.17.4.1 osfrose.h
*** osfrose.h 2001/04/16 18:25:49 1.17.4.1
--- osfrose.h 2001/07/30 20:15:04
*************** do \
*** 214,219 ****
--- 214,220 ----
char *lprefix = LPREFIX; \
int labelno = profile_label_no; \
\
+ ix86_output_main_function_alignment_hack(FILE,SIZE); \
if (profile_flag && OSF_PROFILE_BEFORE_PROLOGUE) \
{ \
if (!flag_pic && !HALF_PIC_P ()) \