@cryptotaxi247 / netdata-1 / commits / 22e5bb32e

Check if libatomic can be linked (#12583)

* dont link with atomic on macos * check if we can link with libatomic

Emmanuel Vasilakis committed Apr 4, 2022 at 14:49 UTC 22e5bb32ea6705c68e3760f43654dba2c4b06118
1 file changed +27 -5
configure.ac
+27 -5
@@ -1554,13 +1554,35 @@ if test "${enable_exporting_kinesis}" = "yes" -o \
1554 enable_cxx_linker="yes"
1555 fi
1556
1557 -# Unconditionally link with the libatomic since:
1558 -# - if atomics are not needed, the library will be unused
1559 -# - if atomics are needed, either atomics are fulfilled by the compiler builtins
1560 -# and the library is unused or the library is needed anyway.
1561 -OPTIONAL_ATOMIC_LIBS="-latomic"
1557 +# Try to unconditionally link with -latomic. If the compiler can satisfy
1558 +# all the atomic ops with builtins then, the library will be left unused.
1559 +# Otherwise, some ops will be covered by the compiler's intrinsics and some
1560 +# will be picked up by the linker from -latomic. In the later case, if
1561 +# -latomic is not available there will be a build failure, which would
1562 +# have happened either way before this change.
1563 +AC_LANG_PUSH([C++])
1564 +
1565 +AC_MSG_CHECKING(whether we can use -latomic)
1566 +OLD_LIBS="${LIBS}"
1567 +LIBS="-latomic"
1568 +AC_LINK_IFELSE([AC_LANG_SOURCE([[
1569 + #include <atomic>
1570 + #include <cstdint>
1571 + std::atomic<std::int64_t> v;
1572 + int main() {
1573 + return v;
1574 + }
1575 +]])], CAN_USE_LIBATOMIC=yes, CAN_USE_LIBATOMIC=no)
1576 +LIBS="${OLD_LIBS}"
1577 +AC_MSG_RESULT($CAN_USE_LIBATOMIC)
1578 +
1579 +if test "x$CAN_USE_LIBATOMIC" = xyes; then
1580 + OPTIONAL_ATOMIC_LIBS="-latomic"
1581 +fi
1582 AC_SUBST([OPTIONAL_ATOMIC_LIBS])
1583
1584 +AC_LANG_POP([C++])
1585 +
1586 AM_CONDITIONAL([ENABLE_CXX_LINKER], [test "${enable_cxx_linker}" = "yes"])
1587
1588 AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])