This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes unittest crashes with libffi 3.4.2
Type: crash Stage: resolved
Components: ctypes Versions: Python 3.11, Python 3.8
process
Status: closed Resolution: duplicate
Dependencies: Superseder: configure incorrectly ignores pkg-config information for libffi and Tcl/Tk in 3.10
View: 45350
Assigned To: Nosy List: Ryan May, erykoff, h-vetinari, isuruf, jakirkham, ned.deily, zan
Priority: normal Keywords:

Created on 2021-07-03 01:27 by zan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg396885 - (view) Author: Zan (zan) Date: 2021-07-03 01:27
Running the unittests after upgrading libffi to latest version 3.4.2 and recompiling python, leads to several tests in Lib/ctypes/test/ to crash with Abort: trap 6. This does not happen with version 3.3 of libffi.

Steps to reproduce:

git clone https://github.com/libffi/libffi
cd libffi
autoreconf -fvi
export CC=/usr/bin/clang
./configure
make
sudo make install # installs into /usr/local

git clone https://github.com/python/CPython
cd CPython
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="-I/usr/local/include" 
export LDFLAGS="-L/usr/local/lib"
./configure --with-system-ffi
make
./python Lib/ctypes/test/__main__.py -v

...
test_callbacks (ctypes.test.test_as_parameter.AsParamPropertyWrapperTestCase) ... Abort trap: 6

If I repeat the above steps with 'git checkout v3.3' in libffi, all tests in ctypes complete successfully.

Tested with :
- python 3.11 commit ec8759b0 (current master), also tried 3.8.11
- libffi 3.4.2
- macOS 11.4, Xcode 12.5.1
- MacBook Air, x86_64, Intel Sky Lake, i5-8210Y
msg406626 - (view) Author: (jakirkham) Date: 2021-11-19 23:17
We ran into the same issue in conda-forge ( https://github.com/conda-forge/python-feedstock/issues/522 ).

The problem is Apple also supplies their own `libffi`. However if the build scripts in CPython fail to find the user provided `libffi`, they end up pulling the headers from Apple's `libffi`, but the linker will link to the user provided `libffi`. IOW mashing these two incompatible `libffi`'s together. As result one gets crashes like the one illustrated in this bug.

In conda-forge, we are resolving this by forcing our `pkg-config` to be used to ensure we pick up the headers from our `libffi` as well as the libraries. Other users may be able to workaround this issue by explicitly setting `LIBFFI_INCLUDE_DIR`.

That said, it would be preferable to have a clear way to specify the `libffi` used and ensure that Apple's one doesn't get accidentally pulled in. If this exists and we are just missing these details, some pointers to this effect would be very helpful.
msg406627 - (view) Author: Eli Rykoff (erykoff) * Date: 2021-11-19 23:23
To add a bit more color, I don't think you can explicitly set LIBFFI_INCLUDE_DIR, it's set by the configure script explicitly.  The problem is that some time between python 3.9 and 3.10 the configure script has (at least in our system) failed to figure out the $PKG_CONFIG variable correctly.  It should be set to the executable with the full path name, as is done with 3.9, but now it is set to just the executable name.  When that happens the library location check fails.
msg406631 - (view) Author: Isuru Fernando (isuruf) * Date: 2021-11-20 00:04
Duplicate of https://bugs.python.org/issue45350
msg406695 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-11-21 00:16
Yes, this does appear to be a result of the problem described in Issue45350. As noted there, the problem was caused by running autoreconf to regerenerate the ./configure script in an environment where pkg-config wasn't installed which caused some pkg-config code to be removed from ./configure. And, unfortunately, the ./configure script included with the v3.10.0 release still had that problem. You can copy an updated version from the current 3.10.0 branch or wait for 3.10.1 or you can try running autoreconf yourself in the source directory.
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88722
2021-11-21 00:16:41ned.deilysetstatus: open -> closed

superseder: configure incorrectly ignores pkg-config information for libffi and Tcl/Tk in 3.10

nosy: + ned.deily
messages: + msg406695
resolution: duplicate
stage: resolved
2021-11-20 00:04:20isurufsetnosy: + isuruf
messages: + msg406631
2021-11-19 23:23:06erykoffsetnosy: + erykoff
messages: + msg406627
2021-11-19 23:17:03jakirkhamsetnosy: + jakirkham
messages: + msg406626
2021-11-19 15:14:20h-vetinarisetnosy: + h-vetinari
2021-11-19 09:27:32Ryan Maysetnosy: + Ryan May
2021-07-03 01:27:44zancreate