gh-156112: Load the ObjC runtime by name when find_library() cannot resolve it - #156113
Open
clementperon wants to merge 2 commits into
Open
gh-156112: Load the ObjC runtime by name when find_library() cannot resolve it#156113clementperon wants to merge 2 commits into
clementperon wants to merge 2 commits into
Conversation
ctypes.util.find_library() resolves a system library through the dyld shared cache, which requires _dyld_shared_cache_contains_path(). Modules/_ctypes/ callproc.c guards that symbol with __builtin_available(iOS 14.0), so on iOS 13 - the oldest release CPython's iOS support targets - find_library() returns None for any library that exists only in the cache, and importing _ios_support fails outright rather than degrading. dyld resolves a bare library name against the cache by itself, so use that when find_library() comes up empty. A genuine load failure is still reported as ImportError.
This was referenced Aug 20, 2026
clementperon
added a commit
to clementperon/xbmc
that referenced
this pull request
Aug 20, 2026
CPython appends -mios-version-min - the device flag - to every iOS build. Against the simulator SDK the linker rejects the dylibs it resolves there, and the first configure check that links one fails, taking the depends build with it. The local patch faked ac_sys_system=iOS by deleting CPython's host parsing, because config.site.in pinned every package to the tree's darwin triplet. Python now configures against its own iOS triplet, so CPython derives ac_sys_system, the deployment target and the device/simulator split itself, and the 76 lines that deleted that logic are gone. What is left matches three patches under review upstream, so all three can be dropped when python is next bumped: python/cpython#156110 python/cpython#156116 python/cpython#156113 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clementperon
added a commit
to clementperon/xbmc
that referenced
this pull request
Aug 20, 2026
CPython appends -mios-version-min - the device flag - to every iOS build. Against the simulator SDK the linker rejects the dylibs it resolves there, and the first configure check that links one fails, taking the depends build with it. The local patch faked ac_sys_system=iOS by deleting CPython's host parsing, because config.site.in pinned every package to the tree's darwin triplet. Python now configures against its own iOS triplet, so CPython derives ac_sys_system, the deployment target and the device/simulator split itself, and the 76 lines that deleted that logic are gone. What is left matches three patches under review upstream, so all three can be dropped when python is next bumped: python/cpython#156110 python/cpython#156116 python/cpython#156113 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
clementperon
added a commit
to clementperon/xbmc
that referenced
this pull request
Aug 20, 2026
CPython appends -mios-version-min - the device flag - to every iOS build. Against the simulator SDK the linker rejects the dylibs it resolves there, and the first configure check that links one fails, taking the depends build with it. The local patch faked ac_sys_system=iOS by deleting CPython's host parsing, because config.site.in pinned every package to the tree's darwin triplet. Python now configures against its own iOS triplet, so CPython derives ac_sys_system, the deployment target and the device/simulator split itself, and the 76 lines that deleted that logic are gone. What is left matches three patches under review upstream, so all three can be dropped when python is next bumped: python/cpython#156110 python/cpython#156116 python/cpython#156113 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_ios_supportraisesImportErrorat import whenctypes.util.find_library("objc")returnsNone. That happens whenever the dyld shared cache cannot be queried:dyld_find()falls back to_dyld_shared_cache_contains_path(), whichModules/_ctypes/callproc.cguards with__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *), so on iOS 13 it raisesNotImplementedErrorand no path can be resolved for a library that exists only in the cache.IPHONEOS_DEPLOYMENT_TARGETdefaults to13.0, so this sits inside the supported range, and it takesplatform.platform()andplatform.ios_ver()down with it.dyld resolves a bare library name against the cache by itself, so this falls back to the name when
find_library()comes up empty, and keeps reporting a real load failure asImportErrorrather than lettingOSErrorescape.Verified on macOS, where the same cache mechanism applies —
find_library("objc")names a path that is not a file, and a bare-name load works:and with
find_librarypatched to returnNone, the module loads the runtime andobjc_getClass(b"NSProcessInfo")succeeds.I do not have an iOS 13 device or simulator runtime available, so the import failure itself is derived from the source rather than reproduced on-device; the fallback is verified as above.