[Python-Dev] HEADS UP: Compilation risk with new GCC 4.5.0

James Y Knight foom at fuhm.net
Wed May 12 15:39:56 CEST 2010


On May 12, 2010, at 9:13 AM, Jesus Cea wrote:
> Short history: new GCC 4.5.0 (released a month ago), when compiling  
> with
> - -O3, is adding MMX/SSE instructions that requires stack aligned to  
> 16
> byte. This is wrong, since x86 ABI only requires stack aligned to 4  
> bytes.
>
> If you compile EVERYTHING with GCC 4.5.0, you are safe (I guess!), but
> if your environment has mixed compiled code (for instance, the OS
> libraries), you can possibly "core dump". If you have an old compiled
> Python and you update libs compiled with GCC 4.5.0, you can crash in  
> the
> process.
>
> Psyco is showing the issue, but it is not the culprit.  It only leaves
> - -correctly- the stack in not 16-byte alignment. But there are  
> plenty of
> examples of crashes not related to python+psyco.
>
> Proposal: add "-fno-tree-vectorize" to compilation options for  
> 2.7/3.2.
> Warm 2.3/2.4/2.5/2.6/3.0/3.1 users. Or warm users compiling with GCC  
> 4.5.0.


While assuming the stack is 16byte aligned is undeniably an ABI- 
violation in GCC, at this point, it's surely simpler to just go along:  
the new unofficial ABI for x86 is that the stack must always be left  
in 16-byte alignment...

So, just change psyco to always use 16-byte-aligned stackframes. GCC  
has used 16byte-aligned stackframes for a heck of a long time now (so  
if the stack starts 16byte aligned on entry to a function it will stay  
that way on calls). So usually the only way people run into unaligned  
stacks is via hand-written assembly code or JIT compilers.

I think you'll be a lot happier just modifying Psyco than making  
everyone else in the world change their compiler flags.

James


More information about the Python-Dev mailing list