summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac35
-rw-r--r--m4/fp_gcc_supports__atomics.m452
2 files changed, 41 insertions, 46 deletions
diff --git a/configure.ac b/configure.ac
index cde0637d1f..482892b8e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -789,13 +789,10 @@ dnl ** See whether cc supports -no-pie
FP_GCC_SUPPORTS_NO_PIE
dnl ** Used to determine how to compile ghc-prim's atomics.c, used by
-dnl unregisterised, Sparc, and PPC backends.
+dnl unregisterised, Sparc, and PPC backends. Also determines whether
+dnl linking to libatomic is required for atomic operations, e.g. on
+dnl RISCV64 GCC.
FP_GCC_SUPPORTS__ATOMICS
-if test $CONF_GCC_SUPPORTS__ATOMICS = YES ; then
- AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does GCC support __atomic primitives?])
-else
- AC_MSG_ERROR([C compiler needs to support __atomic primitives.])
-fi
FP_GCC_EXTRA_FLAGS
@@ -1189,32 +1186,6 @@ AC_LINK_IFELSE([AC_LANG_CALL([], [printf\$LDBLStub])],
FP_CHECK_PTHREADS
-AC_MSG_CHECKING(whether -latomic is needed for sub-word-sized atomic operations)
-AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
- [
- AC_MSG_RESULT(no)
- AC_SUBST([CabalNeedLibatomic],[False])
- need_latomic=0
- ],
- [
- _save_LIBS=$LIBS
- LIBS="-latomic"
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
- [
- AC_MSG_RESULT(yes)
- AC_SUBST([CabalNeedLibatomic],[True])
- need_latomic=1
- ],
- [
- AC_SUBST([CabalNeedLibatomic],[False])
- AC_MSG_ERROR([sub-word-sized atomic operations not available.])
- need_latomic=0
- ])
- LIBS=$_save_LIBS
- ])
-AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
- [Define to 1 if we need -latomic for sub-word atomic operations.])
-
dnl ** check for eventfd which is needed by the I/O manager
AC_CHECK_HEADERS([sys/eventfd.h])
AC_CHECK_FUNCS([eventfd])
diff --git a/m4/fp_gcc_supports__atomics.m4 b/m4/fp_gcc_supports__atomics.m4
index 81fc44c500..6aa3c9dc93 100644
--- a/m4/fp_gcc_supports__atomics.m4
+++ b/m4/fp_gcc_supports__atomics.m4
@@ -1,17 +1,41 @@
-# FP_GCC_SUPPORTS__ATOMICS
-# ------------------------
-# Does gcc support the __atomic_* family of builtins?
+dnl FP_GCC_SUPPORTS__ATOMICS
+dnl ------------------------
+dnl Does gcc support the __atomic_* family of builtins?
AC_DEFUN([FP_GCC_SUPPORTS__ATOMICS],
[
- AC_REQUIRE([AC_PROG_CC])
- AC_MSG_CHECKING([whether GCC supports __atomic_ builtins])
- echo 'int test(int *x) { int y; __atomic_load(x, &y, __ATOMIC_SEQ_CST); return y; }' > conftest.c
- if $CC -c conftest.c > /dev/null 2>&1; then
- CONF_GCC_SUPPORTS__ATOMICS=YES
- AC_MSG_RESULT([yes])
- else
- CONF_GCC_SUPPORTS__ATOMICS=NO
- AC_MSG_RESULT([no])
- fi
- rm -f conftest.c conftest.o
+ AC_REQUIRE([AC_PROG_CC])
+ AC_MSG_CHECKING([whether GCC supports __atomic_ builtins])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x, y;]], [[__atomic_load(&x, &y, __ATOMIC_SEQ_CST); return y]])],
+ [
+ AC_MSG_RESULT(yes)
+ AC_MSG_CHECKING(whether -latomic is needed for sub-word-sized atomic operations)
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(no)
+ AC_SUBST([CabalNeedLibatomic],[False])
+ need_latomic=0
+ ],
+ [
+ _save_LIBS=$LIBS
+ LIBS="-latomic"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(yes)
+ AC_SUBST([CabalNeedLibatomic],[True])
+ need_latomic=1
+ ],
+ [
+ AC_MSG_RESULT(failed)
+ AC_MSG_ERROR([sub-word-sized atomic operations are not available.])
+ ])
+ LIBS=$_save_LIBS
+ ])
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([C compiler needs to support __atomic primitives.])
+ ])
+ AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does GCC support __atomic primitives?])
+ AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
+ [Define to 1 if we need -latomic for sub-word atomic operations.])
])