10000 Add an rpath to bin/python3 on glibc platforms to fix #619 by geofft · Pull Request #621 · astral-sh/python-build-standalone · GitHub
[go: up one dir, main page]

Skip to content

Add an rpath to bin/python3 on glibc platforms to fix #619 #621

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

Conversation

geofft
Copy link
Collaborator
@geofft geofft commented May 22, 2025

Even though the Python interpreter no longer needs libpython3.x.so, it turns out some extension modules (incorrectly) do, and miraculously, allowing them to find libpython3.x.so doesn't actually break things, for reasons detailed in the comment. So set an rpath that allows libpython3.x.so to be loaded if needed by some other library, even though we won't use that ourselves. We are already doing this on musl; do it on glibc too.

Note that this change does not risk users who want to make bin/python3 setuid or setcap (e.g. #576); while the rpath is presumably ignored for privileged binaries, there is no error message, and the binary launches fine, and because we do not need the rpath in order for the interpreter to work, everything (except these misbuilt extension modules) works.

Even though the Python interpreter no longer needs libpython3.x.so, it
turns out some extension modules (incorrectly) do, and miraculously,
allowing them to find libpython3.x.so doesn't actually break things, for
reasons detailed in the comment. So set an rpath that allows
libpython3.x.so to be loaded if needed by some other library, even
though we won't use that ourselves. We are already doing this on musl;
do it on glibc too.

Note that this change does not risk users who want to make bin/python3
setuid or setcap (e.g. astral-sh#576); while the rpath is presumably ignored for
privileged binaries, there is no error message, and the binary launches
fine, and _because_ we do not need the rpath in order for the
interpreter to work, everything (except these misbuilt extension
modules) works.
@geofft geofft force-pushed the wide-is-the-rpath-that-leads-to-destruction branch from 5d1e377 to f794daa Compare May 22, 2025 00:11
@geofft geofft changed the title Restore an rpath to bin/python3 to fix #619 Add an rpath to bin/python3 on glibc platforms to fix #619 May 22, 2025
# usually is thanks to gdb, vim, etc.), because libpython is in
# the system lib directory, as well as the behavior in practice
# on conda-forge miniconda and probably other Conda-family
# Python distributions, which too set an rpath.
Copy link
Member

Choose a reason for hiding this comment

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

typo? costly to rebuild :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

don't think so, or I'm not seeing it? "which, also, set an rpath."

Thanks for the style feedback, I may or may not roll it into an update of this file depending on how builds go :) My overall instinct is that there's enough going on that I want things like this highly visible to the next person to think "can I change this" but yeah I could have done that differently.

(Also, oops, should have tagged this linux, doing that now before I forget just in case we have to rebuild)

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. I got confused by the phrasing haha. Definitely understand following up separately.

# problematic, i.e., we could load the shared library from the wrong location if
# `LD_LIBRARY_PATH` is set, but there's not a clear alternative at this time. The
# long term solution is probably to statically link to libpython instead.
# Although we are statically linking libpython, some extension
Copy link
Member

Choose a reason for hiding this comment

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

The column wrap on this is pretty intense given the amount of content and the presence of longer lines in the file, but 🤷‍♀️

Overall, this feels a little more long-form than I'd personally do here when you could just have a brief version and put the rest it in the pull request, but I don't feel strongly about the styling here.

# version-specific library), because there is no particular
# speedup/benefit in statically linking libpython into
# libpython3.so, and we'd just be shipping a third copy of the
# libpython code. Therefore we use the old logic for that and
Copy link
Member

Choose a reason for hiding this comment

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

"old logic" here feels confusing in a comment, old compared to when? It seems like this will go stale.

@geofft geofft added the platform:linux Specific to the Linux platform label May 22, 2025
@geofft geofft merged commit 482a9bc into astral-sh:main May 22, 2025
438 checks passed
geofft added a commit that referenced this pull request May 23, 2025
@geofft geofft deleted the wide-is-the-rpath-that-leads-to-destruction branch May 30, 2025 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:linux Specific to the Linux platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0