Skip to content

Build Unix distributions with --enable-relocatable - #1397

Draft
zaniebot wants to merge 4 commits into
astral-sh:mainfrom
zaniebot:zb/relocatable-cpython-loader-paths
Draft

zaniebot wants to merge 4 commits into
astral-sh:mainfrom
zaniebot:zb/relocatable-cpython-loader-paths

Conversation

@zaniebot

@zaniebot zaniebot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PBS rewrites loader paths after installing CPython. On glibc, a wheel that links libpython and supplies its own DT_RUNPATH can still fail to import.

Backport the experimental --enable-relocatable flag proposed in python/cpython#160377 and implement it for Python 3.14, 3.15, and 3.16. CPython links shared libraries and standard-library extensions with paths relative to their installed locations. Its install rules generate relocatable scripts and embedding metadata, and sysconfig derives BINDIR, LIBDIR, and LIBPL from the running installation.

On glibc, the launcher that statically links libpython opens the bundled shared library at startup so a wheel can reuse it. On musl, the launcher carries a path to the library directory. Non-framework macOS builds give the dylib its @rpath install name at link time.

On one x86-64 Linux host with warm filesystem caches, minimal startup without site was 12–22% slower on glibc. The table gives median changes in milliseconds relative to the existing PBS builds. The import columns include startup and loading a C extension linked to libpython.

Python glibc startup glibc startup + import musl startup musl startup + import
3.14.9 +1.72 −0.57 −0.14 −0.44
3.15.1 +2.37 +0.02 (95% interval −0.03 to +0.06) +0.11 +0.06
3.16.0a1 +2.09 −0.35 +0.23 +0.19

At startup, the preloaded libpython occupied 3.84–4.28 MiB of resident memory on glibc, including 1.31–1.49 MiB of private dirty pages per process. On musl, the linked import was the first use of the shared library.

On Python 3.15.1, a glibc prototype that retried a failed import saved 0.98 ms at startup and added 0.27 ms when a retry was needed. A different libpython on LD_LIBRARY_PATH can satisfy the first load and bypass the retry.

@zaniebot zaniebot changed the title Set Unix CPython loader paths at link time Build Unix distributions with --enable-relocatable Oct 24, 2026

This branch has not been deployed

No deployments
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.

2 participants