]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
utils: Enable __atomic* built-ins based on the GCC version
authorTobias Brunner <tobias@strongswan.org>
Fri, 2 May 2014 15:58:26 +0000 (17:58 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 4 May 2014 17:16:46 +0000 (19:16 +0200)
This solves a problem with GNAT when compiling charon-tkm as __atomic*
built-ins are only provided in GCC 4.7 and newer.

Currently GNAT 4.6 and GCC 4.7.2 is shipped with Debian wheezy (stable),
as used in the testing environment.  So while the configure script correctly
detected the __atomic* built-ins, and defined HAVE_GCC_ATOMIC_OPERATIONS,
this define turned out to be incorrect when charon-tkm was later built
with GNAT.

configure.ac
src/libstrongswan/utils/utils.h

index 4aae79dc56be931db175ea0c8fb4aee017753cbb..1bd68d66dfde557a6887a252b12c8bf6c6fc9174 100644 (file)
@@ -668,25 +668,6 @@ AC_COMPILE_IFELSE(
        [AC_MSG_RESULT([no])]
 )
 
-AC_MSG_CHECKING([for GCC __atomic operations])
-AC_RUN_IFELSE([AC_LANG_SOURCE(
-       [[
-                       int main() {
-                       int ref = 1, val;
-                       __atomic_fetch_add(&ref, 1, __ATOMIC_RELAXED);
-                       val = __atomic_sub_fetch(&ref, 1, __ATOMIC_RELAXED);
-                       __atomic_compare_exchange_n(&ref, &val, 0, 0, __ATOMIC_RELAXED,
-                                                                               __ATOMIC_RELAXED);
-                       return ref;
-               }
-       ]])],
-       [AC_MSG_RESULT([yes]);
-        AC_DEFINE([HAVE_GCC_ATOMIC_OPERATIONS], [],
-                  [have GCC __atomic_* operations])],
-       [AC_MSG_RESULT([no])],
-       [AC_MSG_RESULT([no])]
-)
-
 AC_MSG_CHECKING([for GCC __sync operations])
 AC_RUN_IFELSE([AC_LANG_SOURCE(
        [[
index 8f91e843111df72a5a851bb262b80b873e1cf62d..75b31ec1b364125a66710fb8814d5ab1ef078039 100644 (file)
@@ -748,6 +748,13 @@ static inline size_t round_down(size_t size, size_t alignment)
  */
 typedef u_int refcount_t;
 
+/* use __atomic* built-ins with GCC 4.7 and newer */
+#ifdef __GNUC__
+# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))
+#  define HAVE_GCC_ATOMIC_OPERATIONS
+# endif
+#endif
+
 #ifdef HAVE_GCC_ATOMIC_OPERATIONS
 
 #define ref_get(ref) __atomic_add_fetch(ref, 1, __ATOMIC_RELAXED)