Skip to content

Conversation

@beeender
Copy link

@beeender beeender commented Jan 22, 2026

The previous implementation of libpython3.so created an empty wrapper
library that recorded libpython3.X.so in DT_NEEDED but did not properly
re-export symbols. The program with proper Py_LIMITED_API defined cannot
actually linked with libpython3.so (-lpython3), and it makes the stable
API pointless.

And libpython3.so cannot simply be a symbolic link to the
libpython3.X.so, since due to the SONAME contains the minor version,
error will still be reported during the runtime with a different pythons
so version.

This fix uses patchelf on Linux to copy the versioned library and set
its SONAME to libpython3.so, ensuring binaries get the correct
DT_NEEDED entry for stable ABI compatibility.

  • Add PATCHELF variable detection in configure.ac (Linux only)
  • Require patchelf on Linux, error if not found
  • Update libpython3.so target to use patchelf when available
  • Fall back to original behavior on non-Linux platforms

A program linked with the newly patched libpython3.so and stable API,
can run with the previous empty wrapper libpython3.so.

The previous implementation of libpython3.so created an empty wrapper
library that recorded libpython3.X.so in DT_NEEDED but did not properly
re-export symbols. The program with proper Py_LIMITED_API defined cannot
actually linked with libpython3.so (-lpython3), and it makes the stable
API pointless.

And libpython3.so cannot simply be a symbolic link to the
libpython3.X.so, since due to the SONAME contains the minor version,
error will still be reported during the runtime with a different pythons
so version.

This fix uses patchelf on Linux to copy the versioned library and set
its SONAME to libpython3.so, ensuring binaries get the correct
DT_NEEDED entry for stable ABI compatibility.

- Add PATCHELF variable detection in configure.ac (Linux only)
- Require patchelf on Linux, error if not found
- Update libpython3.so target to use patchelf when available
- Fall back to original behavior on non-Linux platforms

A program linked with the newly patched libpython3.so and stable API,
can run with the previous empty wrapper libpython3.so.
@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Jan 22, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant