Skip to content

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

Merged
itamaro merged 2 commits into
python:mainfrom
aozmekik:gh-160924-runshared-cross
Nov 8, 2026
Merged

itamaro merged 2 commits into
python:mainfrom
aozmekik:gh-160924-runshared-cross

Conversation

@aozmekik

@aozmekik aozmekik commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

@itamaro itamaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for the fix, I agree this is worth fixing.

I believe the compileall calls also need fixing (see inline comments).

Comment thread Makefile.pre.in Resolved
Comment thread Makefile.pre.in Resolved
Comment thread Makefile.pre.in Resolved
@bedevere-app

bedevere-app Bot commented Nov 8, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@aozmekik

aozmekik commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! You're right about compileall, I missed those two because $(RUNSHARED) and $(PYTHON_FOR_BUILD) are on separate lines there. Since both commands start with -, make ignored the failure: in a glibc → musl cross build, make install hit the same loader error twice and installed 441 .pyc files instead of 6651. With d864c6e there are no loader errors. I also took your NEWS wording, which covers the s390x report on the issue too.

I have made the requested changes; please review again

@bedevere-app

bedevere-app Bot commented Nov 8, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@itamaro: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from itamaro November 8, 2026 06:27
@itamaro itamaro added the needs backport to 3.15 bugs and security fixes label Nov 8, 2026
@itamaro
itamaro merged commit 7271803 into python:main Nov 8, 2026
58 of 61 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @aozmekik for the PR, and @itamaro for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @aozmekik and @itamaro, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 72718034979bf81a39817b76bfed53838982bddf 3.15

@aozmekik

aozmekik commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Manual 3.15 backport: #161659

@bedevere-app

bedevere-app Bot commented Nov 9, 2026

Copy link
Copy Markdown

GH-161659 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants