configure: Improve check for built-in __atomic_* functions

With AC_SEARCH_LIBS() we don't succeed if the searched function is a
built-in as the check uses the wrong signature so the built-in will not
be applied (the warning issued by GCC is "conflicting types for built-in
function '...'").  So even if not required, libatomic will be linked if
it is found, which could be problematic if compiling on a separate host
and the target host does not have libatomic installed.

Also, some tests showed that it's more likely that __atomic_and_fetch()
requires linking libatomic than __atomic_load_n() does.

References #1533.
This commit is contained in:
Tobias Brunner 2016-07-20 11:01:17 +02:00
parent 1806ba0890
commit 6e19a1f5f2
1 changed files with 13 additions and 2 deletions

View File

@ -501,9 +501,20 @@ LIBS=$DLLIB
AC_SEARCH_LIBS(pthread_create, pthread, [PTHREADLIB=$LIBS])
AC_SUBST(PTHREADLIB)
# uClibc requires explicit -latomic for __atomic_* operations
# Some architectures require explicit -latomic for __atomic_* operations
# AC_SEARCH_LIBS() does not work when checking built-ins due to conflicting types
LIBS=""
AC_SEARCH_LIBS(__atomic_load, atomic, [ATOMICLIB=$LIBS])
AC_MSG_CHECKING(for library containing __atomic_and_fetch)
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[]], [[int x; __atomic_and_fetch(&x, 1, __ATOMIC_RELAXED);]])],
[AC_MSG_RESULT([none required])],
[LIBS="-latomic";
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[]], [[int x; __atomic_and_fetch(&x, 1, __ATOMIC_RELAXED);]])],
[AC_MSG_RESULT([-latomic]); ATOMICLIB=$LIBS],
[AC_MSG_RESULT([no])])
]
)
AC_SUBST(ATOMICLIB)
LIBS=$saved_LIBS