classification
Title: ctypes libffi needs to align the x86 stack to 16 bytes
Type: crash Stage: patch review
Components: Versions: Python 3.4, Python 3.3, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: benjamin.peterson, fijall, georg.brandl, gregory.p.smith, larry
Priority: release blocker Keywords: patch

Created on 2013-02-19 22:11 by gregory.p.smith, last changed 2013-03-20 00:17 by gregory.p.smith. This issue is now closed.

Files
File name Uploaded Description Edit
fix_libffi_x86_stack_align.gps01.diff gregory.p.smith, 2013-02-19 22:11 review
Messages (3)
msg182442 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2013-02-19 22:11
The problem: without the stack being 16-byte aligned, code generated by modern compilers like recent gcc/g++ or clang assumed that the stack is 16 byte aligned and uses SSE instructions in some circumstances that require this.  Without this fix, any ctypes call into such code will crash.

I mentioned this in the comment on issue17192 which seeks to update our ancient copy of libffi but we may want to do this independently of that.

In 2.7, we're running into the stack being misaligned in 32-bit x86 code which is something a libffi update fixes.  It is a trivial patch:

 http://patchwork.ozlabs.org/patch/58128/

which made it into the official libffi releases in 2010 via https://github.com/atgreen/libffi/commit/3f5b1375ab1e2b8e3d593e21b27097a4a50f9b83#src/x86/sysv.S.

patch against 2.7 attached.  it should apply to any tree easily enough.
msg184202 - (view) Author: Maciej Fijalkowski (fijall) * (Python committer) Date: 2013-03-14 22:37
This patch is not in the whatever version ubuntu supplies. Btw, this is code duplication, since there is already darwin alignment, see 17423
msg184713 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2013-03-20 00:17
I've updated libffi to v3.0.13 which contains the fixes for this in 2.7, 3.2, 3.3 and 3.4.

if someone wants to apply a surgical patch to fix this problem, the one mentioned above is good as well as:

 https://github.com/atgreen/libffi/commit/ee18766b169811426c14b011fbb46d81e344f926

I'm not actually positive that _both_ of those two small libffi patches are needed but they both fix the same thing and it doesn't hurt to have both and both are in the v3.0.13 libffi release.
History
Date User Action Args
2013-03-20 00:17:19gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg184713
2013-03-18 20:59:11gregory.p.smithlinkissue17423 superseder
2013-03-14 22:37:17fijallsetnosy: + fijall
messages: + msg184202
2013-02-19 22:11:10gregory.p.smithcreate