From: Eduard Bagdasaryan Date: Tue, 12 May 2020 14:50:10 +0000 (+0000) Subject: gcc-8+ build error: undefined reference to __atomic_is_lock_free (#625) X-Git-Tag: SQUID_5_0_3~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7e0116b4729dbe33f57a9cd1b5d8d12430ee7a5;p=thirdparty%2Fsquid.git gcc-8+ build error: undefined reference to __atomic_is_lock_free (#625) Compilers warned about AC_SEARCH_LIBS(__atomic_load_8)-generated code. Newer, stricter compilers (e.g., gcc-8), exit with an error, resulting in AC_SEARCH_LIBS failure when determining whether libatomic is needed. More at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=907277#30 It is unclear whether autoconf will ever handle this case better. Let's use a custom-made test for now. The current test refuses to build Squid on platforms where a program using std::atomic::is_lock_free() cannot be successfully linked (either with or without libatomic) for a the largest atomic T used by Squid (i.e. a 64 bit integer). Linking with libatomic may be required for many reasons that we do not fully understand, but we know that std::atomic::is_lock_free() does require linking with libatomic in some environments, even where T is an inlineable atomic. That is why we use that as a test case. --- diff --git a/configure.ac b/configure.ac index 285e1e4d2b..cc0b06e0a8 100644 --- a/configure.ac +++ b/configure.ac @@ -440,11 +440,33 @@ if test "x$with_dl" = "xyes"; then AC_MSG_NOTICE([With dl]) fi +AC_DEFUN([LIBATOMIC_CHECKER],[ + AC_MSG_CHECKING(whether linking $1 -latomic works) + AC_LINK_IFELSE([ + AC_LANG_SOURCE([[ +#include +#include + int + main(int, char **) { + return std::atomic{}.is_lock_free() ? 0 : 1; + } + ]])],[ + AC_MSG_RESULT(yes) + libatomic_checker_result="yes"],[ + AC_MSG_RESULT(no) + libatomic_checker_result="no" +])]) + ## check for atomics library before anything that might need it -# AC_SEARCH_LIBS pollutes LIBS SQUID_STATE_SAVE(LIBATOMIC) -AC_SEARCH_LIBS([__atomic_load_8],[atomic],[ - test "$ac_res" = "none required" || ATOMICLIB=$ac_res],[]) +LIBATOMIC_CHECKER(without) +AS_IF([test "x$libatomic_checker_result" = "xno"],[ + LIBS="$LIBS -latomic" + LIBATOMIC_CHECKER(with) + AS_IF([test "x$libatomic_checker_result" = "xyes"],[ + ATOMICLIB="-latomic"],[ + AC_MSG_ERROR([Required library libatomic not found.]) +])]) SQUID_STATE_ROLLBACK(LIBATOMIC) AC_SUBST(ATOMICLIB)