Title: ctypes: ARM hardfloat argument corruption calling functions with many float arguments
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, berker.peksag, bivab, doko, fijall, meador.inge, vstinner
Priority: normal Keywords:

Created on 2013-03-30 13:47 by bivab, last changed 2016-03-02 06:11 by berker.peksag. This issue is now closed.

File name Uploaded Description Edit
ctypes_arm.tar bivab, 2013-03-30 13:47
Messages (8)
msg185557 - (view) Author: David Schneider (bivab) Date: 2013-03-30 13:47
This issue affects C functions with many float/double arguments called through ctypes on ARM using the hardfloat ABI (i.e. the standard distribution for the raspberry pi uses hard-float).

Calling a C function using ctypes on ARM hard-float that takes a large number of float arguments (more than 16 floats or more than 8 doubles) corrupts the first float/double arguments passed on the stack to the called function. 

To check the issue run the following commands on an ARM hard-float system:

A patch for this issue has been accepted into libffi.
msg228600 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-05 17:48
Could we have a reply to this from our ctypes experts, thanks.
msg261067 - (view) Author: Maciej Fijalkowski (fijall) * (Python committer) Date: 2016-03-01 20:17
Apparently you can't have an opinion from ctypes experts. Can you please commit the upstream fix that has been committed 3 years ago or just stop vendoring random, old, broken version of ctypes if you can't maintain it enough to pull fixes from upstream?
msg261087 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-01 22:15
To me, it doesn't make sense to maintain a downstream "fork" of libffi. I would prefer to "simply" upgrade to a more recent version of libffi in CPython. But I don't know why we have a downstream version. What was patched? Does anyone know anything about it?

I understood that Linux packages configure with ./configure --with-system-libffi to reuse the system

Who uses the downstream version? Windows? OS X?
msg261088 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-01 22:20
David Schneider: "A patch for this issue has been accepted into libffi."

fijal: "Can you please commit the upstream fix that has been committed 3 years ago (...)"

Which patch? Attached tar archive doesn't look like a patch and I see no reference to a fix.

Previous libffi upgrade:
changeset:   92061:4331fa01398e
branch:      2.7
parent:      92058:928135d0fa7d
date:        Sun Aug 10 11:15:28 2014 +0200
files:       Misc/NEWS Modules/_ctypes/libffi.diff Modules/_ctypes/libffi/.gitignore Modules/_ctypes/libffi/.travis.yml Modules/_ctypes/libffi/ChangeLog Modules/_ctypes/libffi/Change
- Issue #22176: Update the ctypes module's libffi to v3.1.  This release
  adds support for the Linux AArch64 and POWERPC ELF ABIv2 little endian

This upgrade was made in august 2014, this issue was reported in march 2013. The upgrade didn't add the mentioned fix?
msg261089 - (view) Author: Maciej Fijalkowski (fijall) * (Python committer) Date: 2016-03-01 22:27
Then maybe it's fixed, I have no idea
msg261090 - (view) Author: Maciej Fijalkowski (fijall) * (Python committer) Date: 2016-03-01 22:27
The easiest way to check is to run the tests attached
msg261096 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-03-02 06:11
> Which patch?

Looks like the patch can be found at and it has been released in libffi 3.1:

(It's hard to share a specific commit since libffi's history is not linear.)

The patch also has been merged into CPython's fork in 0fef0afb9d19 (Update the ctypes module's libffi to v3.1):


I don't have an ARM system to run David's reproducer (thanks for your report and for the test script, by the way!), but I think we can safely assume that this has already been fixed.
Date User Action Args
2016-03-02 06:11:22berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg261096

resolution: out of date
stage: resolved
2016-03-01 22:27:44fijallsetmessages: + msg261090
2016-03-01 22:27:25fijallsetmessages: + msg261089
2016-03-01 22:20:27vstinnersetnosy: + doko
2016-03-01 22:20:14vstinnersetmessages: + msg261088
2016-03-01 22:15:37vstinnersetmessages: + msg261087
2016-03-01 20:17:14fijallsetnosy: + fijall
messages: + msg261067
2016-02-29 23:36:57BreamoreBoysetnosy: - BreamoreBoy
2016-02-29 16:19:37vstinnersetnosy: + vstinner
2014-10-05 17:48:41BreamoreBoysetnosy: + BreamoreBoy

messages: + msg228600
versions: + Python 3.5, - Python 3.2, Python 3.3
2013-06-27 19:29:43christian.heimessetversions: + Python 3.3, Python 3.4
2013-03-30 22:52:36pitrousetnosy: + amaury.forgeotdarc, belopolsky, meador.inge
2013-03-30 13:47:30bivabcreate