You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
macOS linking: switch shared library linking back to a two-level namespace
On macOS, extension library builds usually rely on the flag ``-undefined
dynamic_lookup`` to get the linker to temporarily accept missing CPython
API symbols. As the name implies, those symbols are then dynamically
resolved when Python imports such an extension library. Binaries
produced in this way are more portable since they don't contain a
hardcoded path to the CPython library. This is critical when
distributing binary wheels on PyPI, etc..
When targeting macOS>=12, XCode recently started to generate a somewhat
ominous warning:
``-undefined dynamic_lookup may not work with chained fixups``
This suggested that the dynamic resolution functionality became broken.
I reported this to Apple via feedback request FB11767124 and switched
nanobind to an alternative set of flags (``-undefined suppress
-flat_namespace``) in the meantime. The flat namespace setup has various
limitations though, so this was not a satisfactory long-term solution.
Apple investigated the request and updated the behavior of ``ld``
starting with XCode 14.3b1+: it now disables the fixup chain linker
optimization whenever ``-undefined dynamic_lookup`` is specified. The
feedback from Apple also stated that the parameter
``-Wl,-no_fixup_chains`` should be specified on pre-14.3 XCode versions
to ensure correct behavior.
This commit realizes those changes by reverting to a two-level namespace
for the overall linking process, checking the XCode version, and
potentially manually disabling fixup chains when needed.
Related discussion is available in the pybind11
(pybind/pybind11#4301) and CPython repositories
(python/cpython#97524).
0 commit comments