Skip to content

gh-160924: Don't run the build Python with RUNSHARED when cross-compiling - #161321

Open
aozmekik wants to merge 1 commit into
python:mainfrom
aozmekik:gh-160924-runshared-cross
Open

aozmekik wants to merge 1 commit into
python:mainfrom
aozmekik:gh-160924-runshared-cross

Conversation

@aozmekik

@aozmekik aozmekik commented Nov 4, 2026 •

Copy link
Copy Markdown

When cross-compiling, the build Python is the --with-build-python interpreter, but the Makefile still ran it with RUNSHARED. With --enable-shared that puts the target's build directory on LD_LIBRARY_PATH, so a shared build Python of the same version loads the target's libpython3.X.so.1.0 instead of its own. glibc to glibc gets away with it; for a musl target the loader then fails on musl's libc.so.

This adds RUNSHARED_FOR_BUILD, which is $(RUNSHARED) in native builds and empty in cross builds, and uses it where the Makefile runs $(PYTHON_FOR_BUILD). RUNSHARED itself doesn't change, so the PGO profile run from gh-141926 still gets it. TESTPYTHON keeps it too, since with HOSTRUNNER regrtest starts the target interpreter from it.

Tested on Ubuntu 24.04 with a shared build Python from the same commit:

  • glibc → x86_64-linux-musl (musl-gcc, --enable-shared): main fails at pybuilddir.txt with error while loading shared libraries: /lib/x86_64-linux-gnu/libc.so: invalid ELF header. With this change the build, make install (ensurepip) and the cross-built interpreter all work.
  • glibc → glibc cross build with --enable-optimizations: passes before and after, and the profile run still gets LD_LIBRARY_PATH. Clearing RUNSHARED for cross builds again, as before 3.15, breaks it (libpython3.16.so.1.0: cannot open shared object file).

…-compiling

In a cross build the build Python is the --with-build-python
interpreter. Running it with RUNSHARED puts the target's build directory
on the library path, so a shared build Python of the same version loads
the target's libpython, which fails when the target uses another libc.

Add RUNSHARED_FOR_BUILD, empty when cross-compiling, and use it for
$(PYTHON_FOR_BUILD). RUNSHARED itself is unchanged, so the PGO profile
run (pythongh-141926) and TESTPYTHON still get it.
@python-cla-bot

python-cla-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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