(CPython) Warning about chained fixups when using ``-undefined dynamic_lookup``

I'm a core developer with the CPython project and I am researching a warning we're getting with recent version of the system compiler.

First some background:

The CPython interpreter can be extended using extension modules. Those modules are shared libraries with a known entry point based on the extension name and are loaded using dlopen(3).  Currently extension modules are not linked to libpython (or a python framework), but use -undefined dynamic_lookups to look up symbols at runtime.

The major advantage for us for this is that compiled extension modules can be used with multiple different python distributions (our own installer, homebrew, anaconda, ...), which makes it possible to redistribute compiled extensions on the PyPI index. A minor advantage is that the same build procedure can be used with all types of CPython builds (statically linked, shared library, framework). A disadvantage is that some build errors are only detected at runtime (e.g. typo's in symbol names).

The issue:

With recent versions of Xcode (and the commmand line tools) we get link errors when linking extension modules:

ld: warning: -undefined dynamic_lookup may not work with chained fixups

We've been unable to come up with a good fix for this so far.

What we've looked into:

  1. Use -bundle_loader .../python while linking

    This works for static builds, but not for shared library builds even when reexporting libpython symbols in the executable.

  2. Link extension modules to libpython using @rpath

    This won't work with static builds as there is no shared library to link to.

Is there a way to avoid this problem without disabling chained fixups (for which there is no documented link option)?

We're tracking this issue in #97524 in CPython's GitHub repository.

One of your colleagues filed a bug about this, FB11767124 [1]. Apple is using that bug to coordinate our response to this issue. I’m not going to pre-announced the resolution here but I will say that:

  • We’re taking this issue seriously.

  • We don’t plan to break this option in the short term.

As to the subject of when we’ll address FB11767124, I can’t comment on The Future™. I recommend that you continue to watch for new Xcode beta seeds and their associated release notes.

But, yeah, irredeemably breaking CPython is not on Apple’s to-do list (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Hmmm, I asked them to add the bug number to your GitHub issue but… oh wait… they did include it, but as a Open Radar link. See this comment.

(CPython) Warning about chained fixups when using ``-undefined dynamic_lookup``
 
 
Q