Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS Big Sur - Python ctypes find_library does not find libraries (ssl, CoreFoundation, etc

MacOS Big Sur is out in Dev Beta and I am running it to test out a few things. One of the things I've noticed is that in Python ctypes, find_library() no longer finds the libraries.

An example would be

from ctypes.util import find_library

find_library("ssl")

This should find the ssl file similar to the output like

>>> find_library("ssl")
'libssl.so.1.1'

However, with Big Sur, it finds nothing. I noticed their are some Dynamic Linker changes. That might contribute to this behavior.

Has anyone else encountered this? I am looking for the new method for finding libraries across the Big Sur system.

I believe it is the same as iOS in that it's using /System/Library/dyld/dyld_shared_cache_x86_64 for shared cache. But I am not familiar enough to know how to open that file for accessing things like CoreFoundations, ssl, etc. Still looking into it.

like image 579
Terminal Avatar asked Jun 26 '20 02:06

Terminal


1 Answers

This issue is due to python using stat() to check for dylibs on disk before it dlopen's them. This behaviour stopped working in macOS Big Sur due to dylibs being removed from disk when they are included in the dyld shared cache.

The python included in macOS has a fix for this.

/usr/bin/python3
from ctypes.util import find_library
>>> find_library("ssl")
'libssl.so.1.1'

Additionally, here is a link to a pull request for open source python for the same fix there. https://github.com/python/cpython/pull/21241

like image 66
Tony Mai Avatar answered Nov 15 '22 22:11

Tony Mai