classification
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
process
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.

Files
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:
make
python bug.py

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 libffi.so.

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
user:        doko@ubuntu.com
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
description:
- 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
  architectures.
---

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 https://github.com/atgreen/libffi/pull/34/ and it has been released in libffi 3.1: https://github.com/atgreen/libffi/blob/17ffc3655a531c116e9eb9cc933e50bb1e5c47f8/ChangeLog.libffi-3.1#L481

(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):

* https://github.com/python/cpython/blob/master/Modules/_ctypes/libffi/src/arm/ffi.c#L43
* https://github.com/python/cpython/blob/master/Modules/_ctypes/libffi/src/arm/ffi.c#L128

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.
History
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