diff --git a/Makefile.pre.in b/Makefile.pre.in index aa3eaabc7559f61..7c2f7dff6d8cfbf 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -267,6 +267,7 @@ STATIC_LIBPYTHON= @STATIC_LIBPYTHON@ LIBS= @LIBS@ LIBM= @LIBM@ +LIBATOMIC= @LIBATOMIC@ LIBC= @LIBC@ SYSLIBS= $(LIBM) $(LIBC) SHLIBS= @SHLIBS@ diff --git a/configure.ac b/configure.ac index 612c072af329d46..039537277e85369 100644 --- a/configure.ac +++ b/configure.ac @@ -6962,6 +6962,64 @@ then [Define if you want to disable the GIL]) fi +# gh-109054: Check if -latomic is needed to get atomic functions. +# On aarch64, GCC may require programs to be linked explicitly to libatomic. +# +# Avoid #include or #include . The header +# requires header which is only written below by AC_OUTPUT below. +# If the check is done after AC_OUTPUT, modifying LIBS has no effect anymore. +# cannot be included alone, it's designed to be included by +# : it expects other includes and macros to be defined. +AC_SUBST([LIBATOMIC]) +LIBATOMIC="" + +_SAVE_VAR([CPPFLAGS]) +CPPFLAGS="${BASECPPFLAGS} -I. -I${srcdir}/Include ${CPPFLAGS}" + +AC_CACHE_CHECK([whether libatomic is needed by ], + [ac_cv_libatomic_needed], +[AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#define NDEBUG + +// pyatomic.h needs uint8_t and Py_ssize_t types +#include // int8_t, intptr_t +#ifdef HAVE_SYS_TYPES_H +# include // ssize_t +#endif +// Code adapted from Include/pyport.h +#if HAVE_SSIZE_T +typedef ssize_t Py_ssize_t; +#elif SIZEOF_VOID_P == SIZEOF_SIZE_T +typedef intptr_t Py_ssize_t; +#else +# error "unable to find a fitting type of ssize_t" +#endif + +#include "cpython/pyatomic.h" + +int main() +{ + uint8_t byte; + _Py_atomic_store_uint8(&byte, 5); + if (_Py_atomic_load_uint8(&byte) != 5) { + return 1; // error + } + return 0; // all good +} +]])],[ + ac_cv_libatomic_needed=no +],[ac_cv_libatomic_needed=yes],[ac_cv_libatomic_needed=yes]) +]) + +if test $ac_cv_libatomic_needed = yes +then + LIBATOMIC="-latomic" + AC_MSG_RESULT([XXX add -latomic to LIBS... too late?]) +fi +_RESTORE_VAR([CPPFLAGS]) + + +# stdlib AC_DEFUN([PY_STDLIB_MOD_SET_NA], [ m4_foreach([mod], [$@], [ AS_VAR_SET([py_cv_module_]mod, [n/a])]) @@ -7229,7 +7287,10 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes], [$OPENSSL_INCLUDES], [$OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS]) dnl test modules -PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes]) +PY_STDLIB_MOD([_testcapi], + [test "$TEST_MODULES" = yes], [] + dnl Modules/_testcapi/pyatomic.c uses header + [], [], [$LIBATOMIC]) PY_STDLIB_MOD([_testclinic], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testclinic_limited], [test "$TEST_MODULES" = yes]) PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes]) @@ -7264,6 +7325,7 @@ AC_CONFIG_FILES(m4_normalize([ AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix]) AC_OUTPUT + AC_MSG_NOTICE([creating Modules/Setup.local]) if test ! -f Modules/Setup.local then