The example that will be attached in the next comment exhibits a problem with recursive functions. It looks that gcc doesn't align stack correctly if the only remaining call (after inlining?) in the function is the call to itself. Compiling the test source with -O3 -m32 produces: sbisect: -4 -8 pushl %ebp movl %esp, %ebp -12 pushl %edi -16 pushl %esi -20 pushl %ebx -196 subl $176, %esp movl 32(%ebp), %eax ... movl %eax, 4(%esp) 0xC4!! call sbisect movl 40(%ebp), %ecx ... ^^^^ offset from %esp at call site. This violates assumption that %esp is aligned to 16 bytes at call sites. When program recurses into the function, the frame gets unaligned, leading to segfaults when aligned insns are used to access the frame.
Created attachment 15796 [details] test case The testcase, distilled from povray-3.6.1
Patch at http://gcc.gnu.org/ml/gcc-patches/2008-06/msg01361.html
*** Bug 35271 has been marked as a duplicate of this bug. ***
Author: uros Date: Mon Jun 23 17:31:12 2008 New Revision: 137045 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137045 Log: PR middle-end/PR36584 * calls.c (expand_call): Increase alignment for recursive functions. testsuite/ChangeLog: PR middle-end/PR36584 * testsuite/gcc.dg/pr36584.c: New test. * testsuite/gcc.target/i386/local2.c: Remove invalid test. Added: trunk/gcc/testsuite/gcc.dg/pr36584.c Removed: trunk/gcc/testsuite/gcc.target/i386/local2.c Modified: trunk/gcc/ChangeLog trunk/gcc/calls.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 36584 Author: uros Date: Tue Jun 24 07:58:17 2008 New Revision: 137059 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137059 Log: PR middle-end/36584 * calls.c (expand_call): Increase alignment for recursive functions. testsuite/ChangeLog: PR middle-end/36584 * testsuite/gcc.dg/pr36584.c: New test. * testsuite/gcc.target/i386/local2.c: Remove invalid test. Added: branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/pr36584.c - copied, changed from r137045, trunk/gcc/testsuite/gcc.dg/pr36584.c Removed: branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/local2.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/calls.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed for mainline and 4.3 branch.
Subject: Bug 36584 Author: hjl Date: Fri Jun 27 13:59:05 2008 New Revision: 137179 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137179 Log: 2008-06-27 H.J. Lu <hongjiu.lu@intel.com> PR middle-end/36584 * gcc.target/i386/stackalign/local-1.c: Remove invalid test. Removed: branches/stack/gcc/testsuite/gcc.target/i386/stackalign/local-1.c Modified: branches/stack/gcc/testsuite/ChangeLog.stackalign