Skip to content

gh-104612: Fix libpython3.so stable ABI on Linux using patchelf - #144136

Open
beeender wants to merge 2 commits into
python:mainfrom
beeender:mc/libpython3_so
Open

gh-104612: Fix libpython3.so stable ABI on Linux using patchelf#144136
beeender wants to merge 2 commits into
python:mainfrom
beeender:mc/libpython3_so

Conversation

@beeender

@beeenderbeeender commented Jan 22, 2026

Copy link
Copy Markdown

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
Copy Markdown

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

python-cla-botBot commented Jan 22, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label May 5, 2026
@beeender

Copy link
Copy Markdown
Author

This PR is stale because it has been open for 30 days with no activity.

shall i do anything ?

@github-actionsgithub-actionsBot removed the stale Stale PR or inactive for long period of time. label May 17, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Aug 18, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewstaleStale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@beeender