According to the man page, -mpreferred-stack-boundary allows one to specify
what the stack is aligned at.
"Attempt to keep the stack boundary aligned to a 2 raised to num byte boundary.
If -mpreferred-stack-boundary is not specified, the default is 4 (16 bytes or
128 bits)."
Example:
# gcc -mpreferred-stack-boundary=7 -mstackrealign testme.c -o ttt3.s -S
In ttt3.s you will see:
main:
leal4(%esp), %ecx
andl$-16, %esp
pushl -4(%ecx)
Expected:
main:
leal4(%esp), %ecx
andl$-128, %esp
pushl -4(%ecx)
No matter which value is passed to -mpreferred-stack-boundary (if it's larger
than 4), it will always align the stack to 16 bytes.
Fix (diff according to svn):
diff -urN gcc/gcc/config/i386/i386.c stack-boundary-fix/gcc/config/i386/i386.c
--- gcc/gcc/config/i386/i386.c 2007-09-19 00:37:00.0 +0200
+++ stack-boundary-fix/gcc/config/i386/i386.c 2007-09-19 01:06:57.0
+0200
@@ -6242,7 +6242,7 @@
/* Align the stack. */
emit_insn (gen_andsi3 (stack_pointer_rtx, stack_pointer_rtx,
-GEN_INT (-16)));
+GEN_INT
(-(cfun->preferred_stack_boundary/BITS_PER_UNIT;
/* And here we cheat like madmen with the unwind info. We force the
cfa register back to sp+4, which is exactly what it was at the
--
Summary: -mpreferred-stack-boundary=num is ignored if num > 4
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yyounan at fort-knox dot org
GCC build triplet: i386-linux-gnu
GCC host triplet: i386-linux-gnu
GCC target triplet: i386-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33484