Port-i386 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Fix GCC's preferred stack alignment to match psABI



On Tue, Sep 18, 2012 at 06:38:43PM +0200, Joerg Sonnenberger wrote:
> On Mon, Sep 17, 2012 at 06:34:45PM +0100, David Laight wrote:
> > If we set -mstackalign and align the stack in exec and for threads,
> > then the stack stays aligned through gcc calls - giving aligned
> > 8 byte items, but any frames that need 16bit alignment get the stack
> > realigned (which involves using %ebp relative addressing for the args
> > and %esp relative addressing for the local (unless alloca() is also used)).
> 
> As shown by the attached minimal test case, GCC does not correctly
> maintain stack alignment if only -mstackalign is used. In short, it
> doesn't work correctly. This is independent of the question whether
> preserving a stack alignment of 128bit is preferable or not.

This is really because there is a subtle difference between
a 'required alignment' and a 'preferred alignment'.
For 8 byte items the alignment is only ever 'preferred', it the
alignment is wrong the code won't fault.
This isn't true of 16 byte SSE data.

There is a long discussion about this at (retyped):
gcc.gnu.org/bugzilla/show_bug.cgi?id=40838.

This resulted in fixes to gcc's -mstackrealign option so that it
aligns the stack on all functions that put anything that requires
16 byte alignment on the stack.
These fixes are in 4.5.3 (possibly in 4.5.0), there maybe backports
to 4.4.x.

I propose that we default -mstackrealign on.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index