Skip to content

Commit

Permalink
Try to unconditionally link with -latomic, if the library is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalintiris committed Nov 23, 2021
1 parent 5e45590 commit 632fbda
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions configure.ac
Expand Up @@ -1641,23 +1641,33 @@ if test "${enable_backend_kinesis}" = "yes" -o \
"${build_ml}" = "yes"; then
enable_cxx_linker="yes"

# Link with libatomic when using toolchains that don't provide all the
# atomic ops as builtins.
# Try to unconditionally link with -latomic. If the compiler can satisfy
# all the atomic ops with builtins then, the library will be left unused.
# Otherwise, some ops will be covered by the compiler's intrinsics and some
# will be picked up by the linker from -latomic. In the later case, if
# -latomic is not available there will be a build failure, which would
# have happened either way before this change.
AC_LANG_PUSH([C++])
AC_MSG_CHECKING(whether -latomic is needed)

AC_MSG_CHECKING(whether we can use -latomic)
OLD_LIBS="${LIBS}"
LIBS="-latomic"
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <atomic>
#include <cstdint>
std::atomic<std::int64_t> v;
int main() {
return v;
}
]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes)
AC_MSG_RESULT($STD_ATOMIC_NEED_LIBATOMIC)
if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
]])], CAN_USE_LIBATOMIC=yes, CAN_USE_LIBATOMIC=no)
LIBS="${OLD_LIBS}"
AC_MSG_RESULT($CAN_USE_LIBATOMIC)

if test "x$CAN_USE_LIBATOMIC" = xyes; then
OPTIONAL_ATOMIC_LIBS="-latomic"
fi
AC_SUBST([OPTIONAL_ATOMIC_LIBS])

AC_LANG_POP([C++])
fi

Expand Down

0 comments on commit 632fbda

Please sign in to comment.