https://github.com/python/cpython/commit/72718034979bf81a39817b76bfed53838982bddf
commit: 72718034979bf81a39817b76bfed53838982bddf
branch: main
author: Ahmed Semih Ă–zmekik <[email protected]>
committer: itamaro <[email protected]>
date: 2026-11-08T08:13:51-08:00
summary:
gh-160924: Don't run the build Python with RUNSHARED when cross-compiling
(#161321)
When cross-compiling, `PYTHON_FOR_BUILD` uses the interpreter specified
by `--with-build-python`. With `--enable-shared`, running it with
`RUNSHARED` adds the target build directory to `LD_LIBRARY_PATH`. A
shared build Python can then load the target's `libpython` instead of
its own, failing if the target uses an incompatible libc or architecture.
Introduce `RUNSHARED_FOR_BUILD`, set to `$(RUNSHARED)` for native builds
and empty for cross builds, and use it for `PYTHON_FOR_BUILD` invocations
during building and installation.
Leave `RUNSHARED` unchanged for PGO profiling (gh-141926) and
`TESTPYTHON`, which uses `HOSTRUNNER` to launch the target interpreter.
files:
A Misc/NEWS.d/next/Build/2026-11-04-15-00-00.gh-issue-160924.WQgVVh.rst
M Makefile.pre.in
M configure
M configure.ac
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 3955afae436e9c..1d109dac77fa90 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -242,6 +242,7 @@ LIPO_INTEL64_FLAGS=@LIPO_INTEL64_FLAGS@
# Environment to run shared python without installed libraries
RUNSHARED= @RUNSHARED@
+RUNSHARED_FOR_BUILD= @RUNSHARED_FOR_BUILD@
# ensurepip options
ENSUREPIP= @ENSUREPIP@
@@ -1013,7 +1014,7 @@ $(BUILDPYTHON): Programs/python.o $(PLATFORM_MAIN_OBJS)
$(LINK_PYTHON_DEPS)
$(LINKCC) $(PY_CORE_EXE_LDFLAGS) $(LINKFORSHARED) -o $@
Programs/python.o $(PLATFORM_MAIN_OBJS) $(LINK_PYTHON_OBJS) $(LIBS) $(MODLIBS)
$(SYSLIBS)
platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
- $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import
get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))'
>platform
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -c 'import sys ; from
sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(),
*sys.version_info[:2]))' >platform
# Create build directory and generate the sysconfig build-time data there.
# pybuilddir.txt contains the name of the build dir and is used for
@@ -1024,7 +1025,7 @@ platform: $(PYTHON_FOR_BUILD_DEPS) pybuilddir.txt
# or removed in case of failure.
pybuilddir.txt: $(PYTHON_FOR_BUILD_DEPS)
@echo "none" > ./pybuilddir.txt
- $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -X pathconfig_warnings=0 -m
sysconfig --generate-posix-vars ;\
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -S -X pathconfig_warnings=0
-m sysconfig --generate-posix-vars ;\
if test $$? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
@@ -1032,7 +1033,7 @@ pybuilddir.txt: $(PYTHON_FOR_BUILD_DEPS)
fi
$(BUILD_DETAILS): pybuilddir.txt
- $(RUNSHARED) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/generate-build-details.py `cat
pybuilddir.txt`/$(BUILD_DETAILS)
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/generate-build-details.py `cat
pybuilddir.txt`/$(BUILD_DETAILS)
# Build static library
$(LIBRARY): $(LIBRARY_OBJS)
@@ -1604,11 +1605,11 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
.PHONY: checksharedmods
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
@if [ -n "@MISSING_STDLIB_CONFIG@" ]; then \
- $(RUNSHARED) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info
--with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py --generate-missing-stdlib-info
--with-missing-stdlib-config="@MISSING_STDLIB_CONFIG@"; \
else \
- $(RUNSHARED) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py
--generate-missing-stdlib-info; \
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py
--generate-missing-stdlib-info; \
fi
- @$(RUNSHARED) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py
+ @$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD)
$(srcdir)/Tools/build/check_extension_modules.py
.PHONY: rundsymutil
rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
@@ -2437,7 +2438,7 @@ install: @FRAMEWORKINSTALLFIRST@ @INSTALLTARGETS@
@FRAMEWORKINSTALLLAST@
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
- $(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -m ensurepip \
$$ensurepip --root=$(DESTDIR)/ ; \
fi
@@ -2448,7 +2449,7 @@ altinstall: commoninstall
upgrade) ensurepip="--altinstall --upgrade" ;; \
install|*) ensurepip="--altinstall" ;; \
esac; \
- $(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
+ $(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -m ensurepip \
$$ensurepip --root=$(DESTDIR)/ ; \
fi
@@ -2914,12 +2915,12 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
patch --force --reject-file
"$(abs_builddir)/app-store-compliance.rej" --strip 2 --directory
"$(DESTDIR)$(LIBDEST)" --input "$(abs_srcdir)/$(APP_STORE_COMPLIANCE_PATCH)" ||
true ; \
fi
@ # Build PYC files for the 3 optimization levels (0, 1, 2)
- -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED_FOR_BUILD) \
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-o 0 -o 1 -o 2 $(COMPILEALL_OPTS) -d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages' \
$(DESTDIR)$(LIBDEST)
- -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED_FOR_BUILD) \
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-o 0 -o 1 -o 2 $(COMPILEALL_OPTS) -d $(LIBDEST)/site-packages
-f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
@@ -3139,7 +3140,7 @@ frameworkinstallunversionedstructure: $(LDLIBRARY)
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/include; \
fi
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
- sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import
platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist >
$(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
+ sed 's/%VERSION%/'"`$(RUNSHARED_FOR_BUILD) $(PYTHON_FOR_BUILD) -c
'import platform; print(platform.python_version())'`"'/g' <
$(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
$(INSTALL_SHARED) $(LDLIBRARY)
$(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBDIR)
$(LN) -fs "../$(LDLIBRARY)"
"$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib"
diff --git
a/Misc/NEWS.d/next/Build/2026-11-04-15-00-00.gh-issue-160924.WQgVVh.rst
b/Misc/NEWS.d/next/Build/2026-11-04-15-00-00.gh-issue-160924.WQgVVh.rst
new file mode 100644
index 00000000000000..2817321dc7e4d1
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-11-04-15-00-00.gh-issue-160924.WQgVVh.rst
@@ -0,0 +1,3 @@
+Fix cross-compilation failures with ``--enable-shared`` caused by the
+build Python loading the target's ``libpython`` through the shared-library
+search path (such as musl from glibc).
diff --git a/configure b/configure
index fca5669c3756b4..65d58fd1e810e2 100755
--- a/configure
+++ b/configure
@@ -1035,6 +1035,7 @@ CONFIG_ARGS
SOVERSION
VERSION
PYTHON_FOR_REGEN
+RUNSHARED_FOR_BUILD
PYTHON_FOR_BUILD_DEPS
FREEZE_MODULE_DEPS
FREEZE_MODULE
@@ -3863,6 +3864,9 @@ then :
FREEZE_MODULE='$(FREEZE_MODULE_BOOTSTRAP)'
FREEZE_MODULE_DEPS='$(FREEZE_MODULE_BOOTSTRAP_DEPS)'
PYTHON_FOR_BUILD_DEPS=''
+ # The build Python is a separate interpreter. RUNSHARED would make it
+ # load the in-tree libpython, which may need a different libc.
+ RUNSHARED_FOR_BUILD=''
else case e in #(
e)
@@ -3871,6 +3875,7 @@ else case e in #(
FREEZE_MODULE='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
FREEZE_MODULE_DEPS="_bootstrap_python
\$(srcdir)/Programs/_freeze_module.py"
PYTHON_FOR_BUILD_DEPS='$(BUILDPYTHON)'
+ RUNSHARED_FOR_BUILD='$(RUNSHARED)'
;;
esac
@@ -3881,6 +3886,7 @@ fi
+
for ac_prog in python$PACKAGE_VERSION python3.16 python3.15 python3.14
python3.13 python3.12 python3.11 python3.10 python3 python
do
# Extract the first word of "$ac_prog", so it can be a program name with
args.
diff --git a/configure.ac b/configure.ac
index 753f997a20da4a..a041f0115bd7ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,6 +194,9 @@ AS_VAR_IF([cross_compiling], [yes],
FREEZE_MODULE='$(FREEZE_MODULE_BOOTSTRAP)'
FREEZE_MODULE_DEPS='$(FREEZE_MODULE_BOOTSTRAP_DEPS)'
PYTHON_FOR_BUILD_DEPS=''
+ # The build Python is a separate interpreter. RUNSHARED would make it
+ # load the in-tree libpython, which may need a different libc.
+ RUNSHARED_FOR_BUILD=''
],
[
dnl internal build tools also depend on Programs/_freeze_module and
_bootstrap_python.
@@ -202,6 +205,7 @@ AS_VAR_IF([cross_compiling], [yes],
FREEZE_MODULE='$(PYTHON_FOR_FREEZE) $(srcdir)/Programs/_freeze_module.py'
FREEZE_MODULE_DEPS="_bootstrap_python
\$(srcdir)/Programs/_freeze_module.py"
PYTHON_FOR_BUILD_DEPS='$(BUILDPYTHON)'
+ RUNSHARED_FOR_BUILD='$(RUNSHARED)'
]
)
AC_SUBST([FREEZE_MODULE_BOOTSTRAP])
@@ -209,6 +213,7 @@ AC_SUBST([FREEZE_MODULE_BOOTSTRAP_DEPS])
AC_SUBST([FREEZE_MODULE])
AC_SUBST([FREEZE_MODULE_DEPS])
AC_SUBST([PYTHON_FOR_BUILD_DEPS])
+AC_SUBST([RUNSHARED_FOR_BUILD])
AC_CHECK_PROGS([PYTHON_FOR_REGEN],
[python$PACKAGE_VERSION python3.16 python3.15 python3.14 python3.13
python3.12 python3.11 python3.10 python3 python],
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]