This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new fa4a43008 interpreters/python: fix build for x86_64 targets built with
the host gcc
fa4a43008 is described below
commit fa4a43008054691eb09890436d5566fb50f47380
Author: raiden00pl <[email protected]>
AuthorDate: Tue Aug 18 10:39:42 2026 +0200
interpreters/python: fix build for x86_64 targets built with the host gcc
NuttX x86_64 (qemu-intel64) builds with the native host gcc, which
exposed several host-environment leaks in the CPython cross build:
- Pass the -D/-U macro flags from CFLAGS as CPPFLAGS so
preprocessor-only configure probes (Misc/platform_triplet.c) do not
see the host's __linux__ and misdetect the platform as
x86_64-linux-gnu, enabling Linux-only code such as the perf
trampoline.
- Force linux/random.h and sys/xattr.h probes to no in config.site:
NuttX provides neither, but a native toolchain resolves them against
the host /usr/include. The former drags host ioctl macros into
posixmodule, the latter enables os xattr support with no xattr
syscalls to link against.
- Disable _curses, _curses_panel, _dbm, _gdbm, _hashlib and _tkinter:
their host libraries are discovered via pkg-config when the target
compiler can compile host headers. hashlib keeps working through
the built-in HACL implementations.
- Only build _posixsubprocess when the arch has a real fork(): its
vfork() support is only an optimization and the fork() fallback path
(PyOS_BeforeFork/PyOS_AfterFork_*) is compiled unconditionally but
declared only under HAVE_FORK. This also fixes rv-virt:python,
which became vfork-only after the fork/vfork split.
Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
---
interpreters/python/Makefile | 13 +++++++++----
interpreters/python/Setup.local.in | 6 ++++++
interpreters/python/config.site.in | 6 ++++++
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/interpreters/python/Makefile b/interpreters/python/Makefile
index 8909586cc..7cceabf4e 100644
--- a/interpreters/python/Makefile
+++ b/interpreters/python/Makefile
@@ -140,10 +140,10 @@ endif
$(SETUP_LOCAL):
$(Q) ( cp $(SETUP_LOCAL).in $(SETUP_LOCAL))
-# _posixsubprocess is the fork-then-exec path, so vfork() is enough for it;
-# os.fork() itself needs a real fork() and is governed by ac_cv_func_fork
-# above.
-ifeq ($(CONFIG_ARCH_HAVE_FORK)$(CONFIG_ARCH_HAVE_VFORK),)
+# _posixsubprocess needs a real fork(): its vfork() support is only an
+# optimization and the fork() fallback path is compiled unconditionally
+# (PyOS_BeforeFork/PyOS_AfterFork_* are declared only under HAVE_FORK).
+ifneq ($(CONFIG_ARCH_HAVE_FORK),y)
@echo "_posixsubprocess" >> $@
endif
ifneq ($(CONFIG_LIBC_DLFCN),y)
@@ -163,6 +163,10 @@ endif
# Also, use -O0 for OPT because -Os is causing problems in
# Python/Modules/getpath.c (issue will be filed soon to track this
# problem).
+#
+# CPPFLAGS carries the -D/-U macro flags from CFLAGS so preprocessor-only
+# probes (Misc/platform_triplet.c) do not see the build host's __linux__
+# when NuttX is built with the native gcc (x86_64).
ifneq ($(CONFIG_NET),y)
PYTHON_CONFIGURE_EXTRAS = --disable-ipv6
@@ -182,6 +186,7 @@ $(TARGETBUILD)/Makefile: $(HOSTPYTHON) $(CONFIG_SITE)
$(SETUP_LOCAL)
ARCH="$${ARCH//-/}"; \
ARCH_CHIP="$${ARCH_CHIP//-/}"; \
CFLAGS="$$(echo "$${CFLAGS}" | sed 's/-Os //')" \
+ CPPFLAGS="$$(echo "$${CFLAGS}" | tr ' ' '\n' | grep -E
'^-[DU]' | tr '\n' ' ')" \
CC="$(CC)" \
CXX="$(CXX)" \
AR="$(AR)" \
diff --git a/interpreters/python/Setup.local.in
b/interpreters/python/Setup.local.in
index d8c27292b..e92249dc9 100644
--- a/interpreters/python/Setup.local.in
+++ b/interpreters/python/Setup.local.in
@@ -11,8 +11,13 @@ _codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
+_curses
+_curses_panel
+_dbm
_decimal
_elementtree
+_gdbm
+_hashlib
_heapq
_interpchannels
_interpqueues
@@ -29,6 +34,7 @@ _testclinic_limited
_testexternalinspection
_testinternalcapi
_testlimitedcapi
+_tkinter
_uuid
_xxtestfuzz
_zoneinfo
diff --git a/interpreters/python/config.site.in
b/interpreters/python/config.site.in
index d19337ea6..066351be4 100644
--- a/interpreters/python/config.site.in
+++ b/interpreters/python/config.site.in
@@ -35,3 +35,9 @@ export ac_cv_func_ffi_prep_cif_var="yes"
export ac_cv_func_ffi_prep_closure_loc="yes"
export ac_cv_func_ffi_closure_alloc="yes"
export ac_cv_func_utimes="no"
+# NuttX provides neither header; without the overrides a native toolchain
+# (x86_64) resolves them against the host /usr/include, dragging host
+# ioctl macros into posixmodule and enabling xattr support that cannot
+# link.
+export ac_cv_header_linux_random_h="no"
+export ac_cv_header_sys_xattr_h="no"