Bug 33484 - -mpreferred-stack-boundary=num is ignored if num > 4
Summary: -mpreferred-stack-boundary=num is ignored if num > 4
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-18 23:29 UTC by Yves Younan
Modified: 2007-09-18 23:44 UTC (History)
1 user (show)

See Also:
Host: i386-linux-gnu
Target: i386-linux-gnu
Build: i386-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch against latest version in svn (330 bytes, patch)
2007-09-18 23:44 UTC, Yves Younan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yves Younan 2007-09-18 23:29:11 UTC
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:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)

Expected:
main:
        leal    4(%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.000000000 +0200
+++ stack-boundary-fix/gcc/config/i386/i386.c   2007-09-19 01:06:57.000000000 +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
Comment 1 Yves Younan 2007-09-18 23:44:19 UTC
Created attachment 14222 [details]
Patch against latest version in svn