PATCH: PR target/40838: gcc shouldn't assume that the stack is aligned

H.J. Lu hjl.tools@gmail.com
Fri Aug 7 12:53:00 GMT 2009


On Fri, Aug 7, 2009 at 12:13 AM, Jakub Jelinek<jakub@redhat.com> wrote:
> On Fri, Aug 07, 2009 at 02:54:46AM +0200, Mikulas Patocka wrote:
>> > > In 32bit, the incoming stack may not be 16 byte aligned.  This patch
>> > > assumes the incoming stack is 4 byte aligned and realigns stack if any
>> > > SSE variable is put on stack. Any comments?
>> >
>> > IMHO this is wrong, I could live with a non-default option for those who
>> > don't care about performance and think a SCO document from 1996 has any
>> > relevance to Linux these days.  In reality a Linux ABI for years assumes
>> > 16 byte stack alignment for 32-bit code.
>>
>> Tell me which Linux distribution did you run with 16-byte stack alignment
>> checking (as proposed in bug 40838) and what was the result?
>>
>> For me, the result was that 75% of binaries in /bin in Debian Lenny do not
>> align the stack on 16-byte boundary.
>
> Besides the obstack glibc bug which has been fixed since then you haven't
> reported anything particular.  It is true that parts of i?86 glibc is
> compiled with -mpreferered-stack-boundary=2, but only parts that don't call
> callbacks.  Async signals AFAIK will align the stack properly.
>
> I simply don't trust your 75% claim, lots of stuff would break if things
> weren't aligned properly.
>

From gcc 3.4:

  /* Validate -mpreferred-stack-boundary= value, or provide default.
     The default of 128 bits is for Pentium III's SSE __m128, but we
     don't want additional code to keep the stack aligned when
     optimizing for code size.  */
  ix86_preferred_stack_boundary = (optimize_size
                                   ? TARGET_64BIT ? 128 : 32
                                   : 128);

If you compile code with -Os, you will get 4 byte stack alignment.
Just step back, we changed stack alignment from 4 byte to 16byte
for SSE since we couldn't realign stack at the time. Now we can
realign the stack very efficiently. I think we should do it for SSE
to support the existing Linux binaries which have 4 byte stack
alignment. If it helps, I can compare -m32 -O3 -msse2 -mfp-math=sse
results with SPEC CPU 2006, before and after my patch.

Thanks.


-- 
H.J.



More information about the Gcc-patches mailing list