diff --git a/configure.ac b/configure.ac index 20f1c551..3746c80b 100644 --- a/configure.ac +++ b/configure.ac @@ -813,6 +813,26 @@ __sync_lock_release(&_sodium_lock); AC_DEFINE([HAVE_ATOMIC_OPS], [1], [atomic operations are supported])], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(if C11 memory fences are supported) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include + ]], [[ +atomic_thread_fence(memory_order_acquire); +]] +)], +[AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_C11_MEMORY_FENCES], [1], [C11 memory fences are supported])], +[AC_MSG_RESULT(no)]) + +AC_MSG_CHECKING(if gcc memory fences are supported) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[ +__atomic_thread_fence(__ATOMIC_ACQUIRE); +]] +)], +[AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_GCC_MEMORY_FENCES], [1], [GCC memory fences are supported])], +[AC_MSG_RESULT(no)]) + dnl Checks for functions and headers AC_FUNC_ALLOCA diff --git a/src/libsodium/include/sodium/private/common.h b/src/libsodium/include/sodium/private/common.h index 7d86b96a..3386e4cd 100644 --- a/src/libsodium/include/sodium/private/common.h +++ b/src/libsodium/include/sodium/private/common.h @@ -260,8 +260,10 @@ extern void ct_unpoison(const void *, size_t); # define UNPOISON(X, L) (void) 0 #endif -#ifdef __ATOMIC_ACQUIRE +#ifdef HAVE_GCC_MEMORY_FENCES # define ACQUIRE_FENCE __atomic_thread_fence(__ATOMIC_ACQUIRE) +#elif defined(HAVE_C11_MEMORY_FENCES) +# define ACQUIRE_FENCE atomic_thread_fence(memory_order_acquire) #else # define ACQUIRE_FENCE (void) 0 #endif