Skip to content

Commit d9f0f15

Browse files
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 <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #12345 Closes #12359
1 parent 1325434 commit d9f0f15

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

config/user-libatomic.m4

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
dnl #
2-
dnl # If -latomic exists, it's needed for __atomic intrinsics.
3-
dnl #
4-
dnl # Some systems (like FreeBSD 13) don't have a libatomic at all because
5-
dnl # their toolchain doesn't ship it – they obviously don't need it.
6-
dnl #
7-
dnl # Others (like sufficiently ancient CentOS) have one,
8-
dnl # but terminally broken or unlinkable (e.g. it's a dangling symlink,
9-
dnl # or a linker script that points to a nonexistent file) –
10-
dnl # most arches affected by this don't actually need -latomic (and if they do,
11-
dnl # then they should have libatomic that actually exists and links,
12-
dnl # so don't fall into this category).
13-
dnl #
14-
dnl # Technically, we could check if the platform *actually* needs -latomic,
15-
dnl # or if it has native support for all the intrinsics we use,
16-
dnl # but it /really/ doesn't matter, and C11 recommends to always link it.
2+
dnl # If -latomic exists and atomic.c doesn't link without it,
3+
dnl # it's needed for __atomic intrinsics.
174
dnl #
185
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBATOMIC], [
19-
AC_MSG_CHECKING([whether -latomic is present])
6+
AC_MSG_CHECKING([whether -latomic is required])
207
218
saved_libs="$LIBS"
229
LIBS="$LIBS -latomic"
10+
LIBATOMIC_LIBS=""
2311
2412
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
25-
LIBATOMIC_LIBS="-latomic"
13+
LIBS="$saved_libs"
14+
saved_cflags="$CFLAGS"
15+
CFLAGS="$CFLAGS -isystem lib/libspl/include"
16+
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "lib/libspl/atomic.c"], [])], [], [LIBATOMIC_LIBS="-latomic"])
17+
CFLAGS="$saved_cflags"
18+
])
19+
20+
if test -n "$LIBATOMIC_LIBS"; then
2621
AC_MSG_RESULT([yes])
27-
], [
28-
LIBATOMIC_LIBS=""
22+
else
2923
AC_MSG_RESULT([no])
30-
])
24+
fi
3125
3226
LIBS="$saved_libs"
3327
AC_SUBST([LIBATOMIC_LIBS])

0 commit comments

Comments
 (0)