This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: libffi doesn't keep the stack aligned to 16 bytes
- From: Andrew Haley <aph at redhat dot com>
- To: libffi-discuss at sourceware dot org
- Date: Thu, 01 Jul 2010 19:07:55 +0100
- Subject: Re: libffi doesn't keep the stack aligned to 16 bytes
- References: <874ogj14cl.fsf@neilpc.example.org>
On 07/01/2010 06:47 PM, Neil Roberts wrote:
> Hi
>
> GCC appears to assume by default that the stack is always aligned to 16
> bytes when entering a function. Presumably this is to make it easier to
> use the aligned access instructions to load data into SSE
> registers. This means that if you have a variable with the aligned(16)
> attribute then GCC knows that it doesn't have to add an extra
> instruction to align the stack pointer because it will already be
> aligned.
>
> However, libffi doesn't appear to respect this. When it calls a function
> it allocates space on the stack by decrementing the stack pointer
> according to the amount of space required. This means the depending on
> the number of arguments the stack may or may not be aligned.
>
> This ends up causes crashes when calling libraries that use -mfpmath=sse
> because then GCC will try to store temporary SSE variables on the stack
> and it will assume it can use aligned access instructions.
>
> Attached is a test case which demonstates the problem and a patch to fix
> it. We are using this patch in MeeGo because all of the libraries are
> compiled with SSE math so we were getting crashes with gjs.
That looks right to me.
Andrew.