Skip to content

Commit 317d430

Browse files
committed
Fix bad -pthread default when cross-compiling
Also, switch to using cross_compiling=yes instead of patching ./configure in place, which allows us to move rerunning autoconf to right before running ./configure, avoiding the risk of patching ./configure.ac too late. See astral-sh#599.
1 parent e15967c commit 317d430

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

cpython-unix/build-cpython.sh

+18-11
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,6 @@ else
306306
patch -p1 -i "${ROOT}/patch-python-configure-add-enable-static-libpython-for-interpreter-${PYTHON_MAJMIN_VERSION}.patch"
307307
fi
308308

309-
# We patched configure.ac above. Reflect those changes.
310-
autoconf
311-
312-
# configure assumes cross compiling when host != target and doesn't provide a way to
313-
# override. Our target triple normalization may lead configure into thinking we
314-
# aren't cross-compiling when we are. So force a static "yes" value when our
315-
# build system says we are cross-compiling.
316-
if [ -n "${CROSS_COMPILING}" ]; then
317-
patch -p1 -i ${ROOT}/patch-force-cross-compile.patch
318-
fi
319-
320309
# BOLT instrumented binaries segfault in some test_embed tests for unknown reasons.
321310
# On 3.12 (minimum BOLT version), the segfault causes the test harness to
322311
# abort and BOLT optimization uses the partial test results. On 3.13, the segfault
@@ -582,6 +571,14 @@ else
582571
fi
583572

584573
if [ -n "${CROSS_COMPILING}" ]; then
574+
# configure assumes cross compiling when host != target and doesn't
575+
# provide a way to override. Our target triple normalization may
576+
# lead configure into thinking we aren't cross-compiling when we
577+
# are. So force a static "yes" value when our build system says we
578+
# are cross-compiling.
579+
# See also https://savannah.gnu.org/support/?110348
580+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} cross_compiling=yes"
581+
585582
# configure doesn't like a handful of scenarios when cross-compiling.
586583
#
587584
# getaddrinfo buggy test fails for some reason. So we short-circuit it.
@@ -598,8 +595,18 @@ if [ -n "${CROSS_COMPILING}" ]; then
598595
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
599596
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_working_tzset=yes"
600597
fi
598+
599+
# Also, it cannot detect whether the compiler supports -pthread or
600+
# not, and conservatively defaults to no, which is not the right
601+
# default on relatively modern compilers.
602+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} ac_cv_pthread=yes"
603+
604+
# TODO: There are probably more of these, see #399.
601605
fi
602606

607+
# We patched configure.ac above. Reflect those changes.
608+
autoconf
609+
603610
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS LDFLAGS=$LDFLAGS \
604611
./configure ${CONFIGURE_FLAGS}
605612

cpython-unix/build.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -562,21 +562,34 @@ def python_build_info(
562562
bi["object_file_format"] = object_file_format
563563

564564
# Determine allowed libaries on Linux
565+
libs = extra_metadata["python_config_vars"].get("LIBS", "").split()
565566
mips = target_triple.split("-")[0] in {"mips", "mipsel"}
566567
linux_allowed_system_libraries = LINUX_ALLOW_SYSTEM_LIBRARIES.copy()
567568
if mips and version == "3.13":
568569
# See https://github.com/astral-sh/python-build-standalone/issues/410
569570
linux_allowed_system_libraries.add("atomic")
570571
riscv = target_triple.split("-")[0] in {"riscv64"}
571572
if riscv:
572-
# RISC-V binary often comes with libatomic on old GCC versions
573+
# On older GCC versions, RISC-V sub-word atomic operations require a
574+
# helper function found in libatomic. To facilitate this, GCC <15 adds
575+
# "-latomic" to the definition of "-pthread". We think it's generally
576+
# reasonable on RISC-V systems (but not all Linux systems in general)
577+
# to expect a libatomic system library is installed.
578+
#
579+
# Because "-latomic" is implicitly added by "-pthread", it may not be
580+
# found in the LIBS sysconfig variable, but we need to pretend it is so
581+
# that it gets into PYTHON.json (in particular, so that the validation
582+
# script accepts this dependency).
583+
#
573584
# See https://github.com/riscvarchive/riscv-gcc/issues/12
574585
# https://github.com/riscvarchive/riscv-gcc/issues/337
575586
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005
587+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104338
588+
# https://github.com/gcc-mirror/gcc/commit/203f3060dd363361b172f7295f42bb6bf5ac0b3b
576589
linux_allowed_system_libraries.add("atomic")
590+
libs.append("-latomic")
577591

578592
# Add in core linking annotations.
579-
libs = extra_metadata["python_config_vars"].get("LIBS", "").split()
580593
skip = False
581594
for i, lib in enumerate(libs):
582595
if skip:

cpython-unix/patch-force-cross-compile.patch

-20
This file was deleted.

0 commit comments

Comments
 (0)