util: build with external libatomic
authorDaniel Golle <daniel@makrotopia.org>
Thu, 21 Feb 2019 17:41:52 +0000 (18:41 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 23 Feb 2019 12:47:53 +0000 (13:47 +0100)
Recent versions of gcc on some architectures (MIPS, PPC, ...) moved
atomic functions into a separate library. As we are using atomic
load/store in util/time.c we may need to link libgnunetutil against
libatomic for __atomic_load_8 and __atomic_store_8 to be defined.

Fixes build problem on MIPS:
ld: ./.libs/libgnunetutil.so: undefined reference to `__atomic_store_8'
ld: ./.libs/libgnunetutil.so: undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
configure.ac
src/util/Makefile.am

index 87a60cb040b3d2ad4d19f992335f2d035ccca153..745300939aba2dc0bdc42d58e4c360a79af693e7 100644 (file)
@@ -282,6 +282,7 @@ have_addrinfo_a=0
 AC_CHECK_LIB(anl, getaddrinfo_a, [have_addrinfo_a=1 AC_DEFINE(HAVE_GETADDRINFO_A,1,[getaddrinfo_a supported])])
 AM_CONDITIONAL(HAVE_GETADDRINFO_A, [test "$have_addrinfo_a" = 1])
 
+
 # tests only run on Windows
 if test "x$build_target" = "xmingw"
 then
@@ -676,6 +677,8 @@ else
        AC_DEFINE([HAVE_LIBCURL],[1],[Have CURL])
 fi
 
+AC_SEARCH_LIBS(__atomic_load_8, atomic, [have_libatomic=1 AC_DEFINE(HAVE_LIBATOMIC,1,[external libatomic])])
+AM_CONDITIONAL(HAVE_LIBATOMIC, [test "$have_libatomic" = 1])
 
 # restore LIBS & CPPFLAGS
 LIBS=$SAVE_LIBS
index 0ba06f4bb6f895b3485720dfe671c2cf2a6d6e11..5fa6e907e444c81ae84b38ea49c036d6526f2c98 100644 (file)
@@ -123,6 +123,12 @@ libgnunetutil_la_SOURCES = \
   speedup.c speedup.h \
        proc_compat.c
 
+if HAVE_LIBATOMIC
+  LIBATOMIC= -latomic
+else
+  LIBATOMIC=
+endif
+
 if HAVE_LIBIDN
   LIBIDN= -lidn
 else
@@ -137,6 +143,7 @@ endif
 
 libgnunetutil_la_LIBADD = \
   $(GCLIBADD) $(WINLIB) \
+  $(LIBATOMIC) \
   $(LIBGCRYPT_LIBS) \
   $(LTLIBICONV) \
   $(LTLIBINTL) \