This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libffi doesn't keep the stack aligned to 16 bytes


Hey Andrew,

Please commit to GCC and I'll pull it into libffi git.

Sorry about the top posting.  My phone is a pain that way.

Thanks,

AG

----- Original Message -----
From: libffi-discuss-owner@sourceware.org 
<libffi-discuss-owner@sourceware.org>
To: libffi-discuss@sourceware.org <libffi-discuss@sourceware.org>
Sent: Mon Jul 05 10:13:30 2010
Subject: Re: libffi doesn't keep the stack aligned to 16 bytes

On 07/01/2010 07:07 PM, Andrew Haley wrote:
> 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.

Should I just commit this patch as is?

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]