gh-104612: Fix libpython3.so stable ABI on Linux using patchelf #144136
+74
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A program linked with the newly patched libpython3.so and stable API,
can run with the previous empty wrapper libpython3.so.