@cryptotaxi247 / netdata-1 / commits / 1fd40e59d

Detect whether libatomic should be linked in when using CXX linker. (#11818)

* Detect whether libatomic should be linked in when using CXX linker. There was already a check for this when building with the bundled protobuf. Considering that we needed the same check when building for ML, I moved the check so that it can happen in either case when a C++ linker is required for the build to succeed. * Try to unconditionally link with -latomic, if the library is available.

vkalintiris committed Dec 7, 2021 at 15:13 UTC 1fd40e59d84ad6cad8d33cb0cbe7f8b890f2e465
2 files changed +39 -27
Makefile.am
+1 -1
@@ -969,6 +969,7 @@ NETDATA_COMMON_LIBS = \
969 $(OPTIONAL_JUDY_LIBS) \
970 $(OPTIONAL_SSL_LIBS) \
971 $(OPTIONAL_JSONC_LIBS) \
972 + $(OPTIONAL_ATOMIC_LIBS) \
973 $(NULL)
974
975 if LINK_STATIC_JSONC
@@ -995,7 +996,6 @@ netdata_LDADD = \
996
997 if ACLK_NG
998 netdata_LDADD += $(OPTIONAL_PROTOBUF_LIBS) \
998 - $(OPTIONAL_ATOMIC_LIBS) \
999 $(NULL)
1000 endif
1001
configure.ac
+38 -26
@@ -799,27 +799,6 @@ if test "$enable_cloud" != "no" -a "$aclk_ng" != "no"; then
799 AC_MSG_RESULT([yes])
800 fi
801
802 - if test "${with_bundled_protobuf}" = "yes"; then
803 - AC_LANG_PUSH([C++])
804 - CXXFLAGS="${CXXFLAGS} -std=c++11"
805 -
806 - # On some platforms, std::atomic needs a helper library
807 - AC_MSG_CHECKING(whether -latomic is needed for static protobuf)
808 - AC_LINK_IFELSE([AC_LANG_SOURCE([[
809 - #include <atomic>
810 - #include <cstdint>
811 - std::atomic<std::int64_t> v;
812 - int main() {
813 - return v;
814 - }
815 - ]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes)
816 - AC_MSG_RESULT($STD_ATOMIC_NEED_LIBATOMIC)
817 - if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
818 - OPTIONAL_ATOMIC_LIBS="-latomic"
819 - fi
820 - AC_SUBST([OPTIONAL_ATOMIC_LIBS])
821 - AC_LANG_POP([C++])
822 - fi
802 AC_MSG_CHECKING([ACLK Next Generation can support New Cloud protocol])
803 AC_MSG_RESULT([${can_build_new_cloud_protocol}])
804 if test "$new_cloud_protocol" = "yes" -a "$can_build_new_cloud_protocol" != "yes"; then
@@ -1655,11 +1634,44 @@ AC_MSG_RESULT([${enable_lto}])
1634
1635 # -----------------------------------------------------------------------------
1636
1658 -AM_CONDITIONAL([ENABLE_CXX_LINKER], [test "${enable_backend_kinesis}" = "yes" \
1659 - -o "${enable_exporting_pubsub}" = "yes" \
1660 - -o "${enable_backend_prometheus_remote_write}" = "yes" \
1661 - -o "${new_cloud_protocol}" = "yes" \
1662 - -o "${build_ml}" = "yes"])
1637 +if test "${enable_backend_kinesis}" = "yes" -o \
1638 + "${enable_exporting_pubsub}" = "yes" -o \
1639 + "${enable_backend_prometheus_remote_write}" = "yes" -o \
1640 + "${new_cloud_protocol}" = "yes" -o \
1641 + "${build_ml}" = "yes"; then
1642 + enable_cxx_linker="yes"
1643 +
1644 + # Try to unconditionally link with -latomic. If the compiler can satisfy
1645 + # all the atomic ops with builtins then, the library will be left unused.
1646 + # Otherwise, some ops will be covered by the compiler's intrinsics and some
1647 + # will be picked up by the linker from -latomic. In the later case, if
1648 + # -latomic is not available there will be a build failure, which would
1649 + # have happened either way before this change.
1650 + AC_LANG_PUSH([C++])
1651 +
1652 + AC_MSG_CHECKING(whether we can use -latomic)
1653 + OLD_LIBS="${LIBS}"
1654 + LIBS="-latomic"
1655 + AC_LINK_IFELSE([AC_LANG_SOURCE([[
1656 + #include <atomic>
1657 + #include <cstdint>
1658 + std::atomic<std::int64_t> v;
1659 + int main() {
1660 + return v;
1661 + }
1662 + ]])], CAN_USE_LIBATOMIC=yes, CAN_USE_LIBATOMIC=no)
1663 + LIBS="${OLD_LIBS}"
1664 + AC_MSG_RESULT($CAN_USE_LIBATOMIC)
1665 +
1666 + if test "x$CAN_USE_LIBATOMIC" = xyes; then
1667 + OPTIONAL_ATOMIC_LIBS="-latomic"
1668 + fi
1669 + AC_SUBST([OPTIONAL_ATOMIC_LIBS])
1670 +
1671 + AC_LANG_POP([C++])
1672 +fi
1673 +
1674 +AM_CONDITIONAL([ENABLE_CXX_LINKER], [test "${enable_cxx_linker}" = "yes"])
1675
1676 AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])
1677