aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2021-07-13 20:50:48 +0000
committerGitHub <noreply@github.com>2021-07-13 20:50:48 +0000
commitd9f0f1582c4bd73e5beb8be447358c8a7170e553 (patch)
tree177d471161f3b293e5f4d2c07fde7201901eb1cb
parent1325434b2d758ecd0b07a3a4f883a0c43393ed37 (diff)
downloadsrc-d9f0f1582c4bd73e5beb8be447358c8a7170e553.tar.gz
src-d9f0f1582c4bd73e5beb8be447358c8a7170e553.zip
config/libatomic: require -latomic iff atomic.c doesn't link w/o it
In absence of LTO, and dynamic libatomic, la.so ends up in the needs section of every toolchain executable; some consider this an issue. Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12345 Closes #12359
-rw-r--r--config/user-libatomic.m434
1 files changed, 14 insertions, 20 deletions
diff --git a/config/user-libatomic.m4 b/config/user-libatomic.m4
index 14a60bbea9d0..d15069f9c445 100644
--- a/config/user-libatomic.m4
+++ b/config/user-libatomic.m4
@@ -1,33 +1,27 @@
dnl #
-dnl # If -latomic exists, it's needed for __atomic intrinsics.
-dnl #
-dnl # Some systems (like FreeBSD 13) don't have a libatomic at all because
-dnl # their toolchain doesn't ship it – they obviously don't need it.
-dnl #
-dnl # Others (like sufficiently ancient CentOS) have one,
-dnl # but terminally broken or unlinkable (e.g. it's a dangling symlink,
-dnl # or a linker script that points to a nonexistent file) –
-dnl # most arches affected by this don't actually need -latomic (and if they do,
-dnl # then they should have libatomic that actually exists and links,
-dnl # so don't fall into this category).
-dnl #
-dnl # Technically, we could check if the platform *actually* needs -latomic,
-dnl # or if it has native support for all the intrinsics we use,
-dnl # but it /really/ doesn't matter, and C11 recommends to always link it.
+dnl # If -latomic exists and atomic.c doesn't link without it,
+dnl # it's needed for __atomic intrinsics.
dnl #
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBATOMIC], [
- AC_MSG_CHECKING([whether -latomic is present])
+ AC_MSG_CHECKING([whether -latomic is required])
saved_libs="$LIBS"
LIBS="$LIBS -latomic"
+ LIBATOMIC_LIBS=""
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
- LIBATOMIC_LIBS="-latomic"
+ LIBS="$saved_libs"
+ saved_cflags="$CFLAGS"
+ CFLAGS="$CFLAGS -isystem lib/libspl/include"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "lib/libspl/atomic.c"], [])], [], [LIBATOMIC_LIBS="-latomic"])
+ CFLAGS="$saved_cflags"
+ ])
+
+ if test -n "$LIBATOMIC_LIBS"; then
AC_MSG_RESULT([yes])
- ], [
- LIBATOMIC_LIBS=""
+ else
AC_MSG_RESULT([no])
- ])
+ fi
LIBS="$saved_libs"
AC_SUBST([LIBATOMIC_LIBS])