@@ -6962,6 +6962,65 @@ then
6962
6962
[ Define if you want to disable the GIL] )
6963
6963
fi
6964
6964
6965
+ # gh-109054: Check if -latomic is needed to get <pyatomic.h> atomic functions.
6966
+ # On aarch64, GCC may require programs to be linked explicitly to libatomic.
6967
+ # Use _Py_atomic_or_uint64() which may require libatomic __atomic_fetch_or_8()
6968
+ # on Linux aarch64 (or not depending on the compiler and the compiler flags).
6969
+ #
6970
+ # Avoid #include <Python.h> or #include <pyport.h>. The <Python.h> header
6971
+ # requires <pyconfig.h> header which is only written below by AC_OUTPUT below.
6972
+ # If the check is done after AC_OUTPUT, modifying LIBS has no effect anymore.
6973
+ # <pyport.h> cannot be included alone, it's designed to be included by
6974
+ # <Python.h>: it expects other includes and macros to be defined.
6975
+ LIBATOMIC=""
6976
+
6977
+ _SAVE_VAR([ CPPFLAGS] )
6978
+ CPPFLAGS="${BASECPPFLAGS} -I. -I${srcdir}/Include ${CPPFLAGS}"
6979
+
6980
+ AC_CACHE_CHECK ( [ whether libatomic is needed by <pyatomic.h>] ,
6981
+ [ ac_cv_libatomic_needed] ,
6982
+ [ AC_RUN_IFELSE ( [ AC_LANG_SOURCE ( [ [
6983
+ // pyatomic.h needs uint64_t and Py_ssize_t types
6984
+ #include <stdint.h> // int64_t, intptr_t
6985
+ #ifdef HAVE_SYS_TYPES_H
6986
+ # include <sys/types.h> // ssize_t
6987
+ #endif
6988
+ // Code adapted from Include/pyport.h
6989
+ #if HAVE_SSIZE_T
6990
+ typedef ssize_t Py_ssize_t;
6991
+ #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
6992
+ typedef intptr_t Py_ssize_t;
6993
+ #else
6994
+ # error "unable to find a type fitting ssize_t"
6995
+ #endif
6996
+
6997
+ #include "cpython/pyatomic.h"
6998
+
6999
+ int main()
7000
+ {
7001
+ // use _Py_atomic_or_uint64() which requires libatomic __atomic_fetch_or_8()
7002
+ // on Linux aarch64.
7003
+ uint64_t byte;
7004
+ _Py_atomic_store_uint64(&byte, 2);
7005
+ if (_Py_atomic_or_uint64(&byte, 8) != 2) {
7006
+ return 1; // error
7007
+ }
7008
+ if (_Py_atomic_load_uint64(&byte) != 10) {
7009
+ return 1; // error
7010
+ }
7011
+ return 0; // all good
7012
+ }
7013
+ ] ] ) ] ,[
7014
+ ac_cv_libatomic_needed=no
7015
+ ] ,[ ac_cv_libatomic_needed=yes] ,[ ac_cv_libatomic_needed=yes] )
7016
+ ] )
7017
+
7018
+ AS_VAR_IF ( [ ac_cv_libatomic_needed] , [ yes] ,
7019
+ [ LIBATOMIC=${LIBATOMIC-"-latomic"}] )
7020
+ _RESTORE_VAR([ CPPFLAGS] )
7021
+
7022
+
7023
+ # stdlib
6965
7024
AC_DEFUN ( [ PY_STDLIB_MOD_SET_NA] , [
6966
7025
m4_foreach ( [ mod] , [ $@ ] , [
6967
7026
AS_VAR_SET ( [ py_cv_module_] mod , [ n/a] ) ] )
@@ -7229,7 +7288,10 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes],
7229
7288
[ $OPENSSL_INCLUDES] , [ $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH $LIBCRYPTO_LIBS] )
7230
7289
7231
7290
dnl test modules
7232
- PY_STDLIB_MOD([ _testcapi] , [ test "$TEST_MODULES" = yes] )
7291
+ PY_STDLIB_MOD([ _testcapi] ,
7292
+ [ test "$TEST_MODULES" = yes] , [ ]
7293
+ dnl Modules/_testcapi/pyatomic.c uses <cpython/pyatomic.h> header
7294
+ [ ] , [ ] , [ $LIBATOMIC] )
7233
7295
PY_STDLIB_MOD([ _testclinic] , [ test "$TEST_MODULES" = yes] )
7234
7296
PY_STDLIB_MOD([ _testclinic_limited] , [ test "$TEST_MODULES" = yes] )
7235
7297
PY_STDLIB_MOD([ _testinternalcapi] , [ test "$TEST_MODULES" = yes] )
@@ -7262,6 +7324,7 @@ AC_CONFIG_FILES(m4_normalize([
7262
7324
Modules/Setup.stdlib
7263
7325
] ) )
7264
7326
AC_CONFIG_FILES ( [ Modules/ld_so_aix] , [ chmod +x Modules/ld_so_aix] )
7327
+ # Generate files like pyconfig.h
7265
7328
AC_OUTPUT
7266
7329
7267
7330
AC_MSG_NOTICE ( [ creating Modules/Setup.local] )
0 commit comments