Skip to content

bpo-21536: C extensions are no longer linked to libpython #12946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2019
Merged

bpo-21536: C extensions are no longer linked to libpython #12946

merged 1 commit into from
Apr 25, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 25, 2019

On Unix, C extensions are no longer linked to libpython.

It is now possible to load a C extension built using a shared library
Python with a statically linked Python.

When Python is embedded, libpython must not be loaded with
RTLD_LOCAL, but RTDL_GLOBAL instead. Previously, using RTLD_LOCAL, it
was already not possible to load C extensions which were not linked
to libpython, like C extensions of the standard library built by the
"shared" section of Modules/Setup.

distutils, python-config and python-config.py have been modified.

https://bugs.python.org/issue21536

@vstinner
Copy link
Member Author

This PR allows to load a C extension built by a shared libpython with a statically linked Python: https://bugs.python.org/issue21536#msg340819

It also allows to load C extension built in release mode with a Python built in debug mode: https://bugs.python.org/issue21536#msg340821

@vstinner
Copy link
Member Author

One potential issue: linking an application to libpython to embed Python, see discussion at https://bugs.python.org/issue21536#msg340837

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

On Unix, C extensions are no longer linked to libpython.

It is now possible to load a C extension built using a shared library
Python with a statically linked Python.

When Python is embedded, libpython must not be loaded with
RTLD_LOCAL, but RTLD_GLOBAL instead. Previously, using RTLD_LOCAL, it
was already not possible to load C extensions which were not linked
to libpython, like C extensions of the standard library built by the
"*shared*" section of Modules/Setup.

distutils, python-config and python-config.py have been modified.
@vstinner vstinner merged commit 8c3ecc6 into python:master Apr 25, 2019
@vstinner vstinner deleted the omit_libpython branch April 25, 2019 18:13
gferon added a commit to gferon/libArcus that referenced this pull request Jun 2, 2020
As of Python 3.8, python C extensions modules should not link to
libpython, unless they embed the interpreter in their code.

Relevant upstream PR: python/cpython#12946

Signed-off-by: Gabriel Féron <[email protected]>
gferon added a commit to gferon/libSavitar that referenced this pull request Jun 2, 2020
As of Python 3.8, python C extensions modules should not link to
libpython, unless they embed the interpreter in their code.

Relevant upstream PR: python/cpython#12946

Signed-off-by: Gabriel Féron <[email protected]>
@froody
Copy link

froody commented Dec 7, 2020

This change causes strange bugs on Mac OS X due to the two-level namespace symbol resolution for dynamic libraries. A C extension that links against libpython will resolve symbols from libpython instead of the python executable (for example, PDAL/python#75 ). I believe linking C extensions on Mac OS X with "-flat_namespace" would be a reliable fix, as it would allow the python executable symbols to take precedence over those from libpython.

@vstinner
Copy link
Member Author

vstinner commented Dec 7, 2020

Please don't comment closed PRs, but open a new issue at https://bugs.python.org/ Otherwise, your comment will simply be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants