[Ffmpeg-devel] DECLARE_ALIGNED_16 not honoured correctly in MinGW

Benjamin Larsson banan
Tue Nov 7 14:50:10 CET 2006


elupus skrev:
>>> Yes, and this assumption is highly broken on gcc's part. All 
>> it has to
>>> do is insert an instruction "and $~15, %esp" before it sets 
>> up the new
>>> frame and some other minor support. Flame the gcc developers 
>> for being
>>> #$&(#$ idiots, yet again...
>>>
>>> Rich
>>>  
>>>
>> So if we move a stack variable so it aligns the struct is it going to
>> work then? Then it would still work properly on Unix while it could be
>> considered a hack on mingw.
>>
> 
> So was there any solution figured out for this? Gcc apperently assumes the
> stack is aligned at the point of the call to the function, after any
> parameters have been pushed onto stack, wich makes it very uggly to fix. One
> have to write special assembly rutines to call a function.
> 
> In ms style assembly for a function with one parameter, something like this.
> ( this is for calling a function in mplayer built as a dll, wich then will
> call lavc )
> 
>   int mplayer_open_file(const char* szFile)
>   {
>     int result;
>     __asm 
>     {      
>       mov esi,esp;
>       sub esp,4;   /* make room for paramteres */
>       and esp,~15; /* align stack */
>       add esp,4;   /* for parameters */
> 
>       mov eax,dword ptr [szFile];
>       push eax;
>       call dword ptr [pOpenFile];
>       mov result, eax;
>       mov esp,esi; /* restore stack */
>     }
> 
>     return result;
>   }
> 
> Doing that for every potential function that could be needing aligned stack
> is really uggly. 
> 
> The patch suggested by steve would probably work, and I think aslong as the
> memory that get's used for a struct is aligned properly, any property of
> that struct seem to be correctly aligned if it has the aligned keyword on
> it. Thus aslong as av_malloc or av_calloc is used, it should be fine. Just
> making sure any variable on stack that needs to be aligned uses _alloca.
> 
> /Joakim

There was another patch sent to fix the same thing. It allocated 
sizeof(array)+some bytes. Then it aligned the array pointer to the 
needed alignment.

http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/39476/focus=39476

If this hack can be done in the align macro it has a chance to be 
applied. I doubt it's possible though.


MvH
Benjamin Larsson




More information about the ffmpeg-devel mailing list