[Ffmpeg-devel] DECLARE_ALIGNED_16 not honoured correctly in MinGW

Steve Lhomme slhomme
Fri Oct 27 18:43:21 CEST 2006

Benjamin Larsson wrote:
> Steve Lhomme skrev:
>> Hi,
>> We are encountering a crash when calling DrFFMPEG from DrDivX on 
>> Windows. The crash occurs when decoding WMA content. After some 
>> investigation it appears that this declaration in wmadec.c doesn't 
>> produce what it's supposed to do:
>> DECLARE_ALIGNED_16(FFTSample, output[BLOCK_MAX_SIZE * 2]);
>> When the DLL (could be libavcodec) is called from MSVC code 'output' 
>> is not aligned to 16 bits (0x01F36D28 in this case for example). And 
>> it crashes the SSE code used later. But it works fine when everything 
>> is built with MinGW. It appears that gcc assumes the stack is already 
>> aligned a certain way when it does the alignment of this variable in 
>> the stack. And this is not true when the stack is given by MSVC code.
>> Now I understand there's no support for MSVC here, but on the other 
>> hand libavcodec is a library, no matter how it's being called. Plus 
>> the bug is not in MSVC (who has the right to do whatever they want 
>> with the stack) but in gcc.
>> So my question is: does anybody know a way to make gcc behave 
>> correctly in such case ?
>> The other possibility I see to avoid the crash in my case is to add a 
>> test in ff_imdct_calc_sse() and vector_fmul_add_add_sse() to use the C 
>> code if one of the parameter passed is not aligned as it should. (I 
>> could make the patch if the solution is OK)
>> Thanks
>> Steve
> I'm just confirming this. There has been several reported instances of 
> this on irc. Both with mingw and with gcc on BeOS. And I would reject 
> the proposed imdct hack and use an aligned malloc instead (assuming that 
> atleast mallocs can be aligned properly), that should work just as well 
> if I remember the code correctly.

Here is the code I use to avoid the crash. It seems to work well. There 
are still some DECLARE_ALIGNED_16 in structures which can't be turned 
into alloca(), av_malloc() or whatever else... The only safe solution 
for these is to make sure gcc does what it's supposed to do... And I 
don't plan to fix gcc.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: declare_aligned-mingw.patch
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20061027/5d5e40d1/attachment.txt>

More information about the ffmpeg-devel mailing list