1 From 5865c7cb4e4ed1d63699e384ea52984448adfec9 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3 Date: Mon, 7 May 2018 10:36:10 +0200
4 Subject: [PATCH] configure.ac: rework -latomic check
6 The configure.ac logic added in commit
7 2ef7f23820a67e958c2252bd81eb0458903ebf33 ("configure: check if
8 -latomic is needed for __atomic_*") makes the assumption that if a
9 64-bit atomic intrinsic test program fails to link without -latomic,
10 it is because we must use -latomic.
12 Unfortunately, this is not completely correct: libatomic only appeared
13 in gcc 4.8, and therefore gcc versions before that will not have
14 libatomic, and therefore don't provide atomic intrinsics for all
15 architectures. This issue was for example encountered on PowerPC with
16 a gcc 4.7 toolchain, where the build fails with:
18 powerpc-ctng_e500v2-linux-gnuspe/bin/ld: cannot find -latomic
20 This commit aims at fixing that, by not assuming -latomic is
21 available. The commit re-organizes the atomic intrinsics detection as
24 (1) Test if a program using 64-bit atomic intrinsics links properly,
25 without -latomic. If this is the case, we have atomic intrinsics,
28 (2) If (1) has failed, then test to link the same program, but this
29 time with -latomic in LDFLAGS. If this is the case, then we have
30 atomic intrinsics, provided we link with -latomic.
32 This has been tested in three situations:
34 - On x86-64, where atomic instrinsics are all built-in, with no need
35 for libatomic. In this case, config.log contains:
37 GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE='#'
38 GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE=''
41 This means: atomic intrinsics are available, and we don't need to
44 - On NIOS2, where atomic intrinsics are available, but some of them
45 (64-bit ones) require using libatomic. In this case, config.log
48 GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE='#'
49 GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE=''
50 LIBATOMIC_LIBS='-latomic'
52 This means: atomic intrinsics are available, and we need to link
55 - On PowerPC with an old gcc 4.7 toolchain, where 32-bit atomic
56 instrinsics are available, but not 64-bit atomic instrinsics, and
57 there is no libatomic. In this case, config.log contains:
59 GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE=''
60 GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE='#'
62 With means that atomic intrinsics are not usable.
64 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
65 Upstream-status: https://lists.freedesktop.org/archives/mesa-dev/2018-May/194214.html
67 configure.ac | 37 +++++++++++++++++++++----------------
68 1 file changed, 21 insertions(+), 16 deletions(-)
70 diff --git a/configure.ac b/configure.ac
71 index f1fbdcc6c7..c94e547874 100644
74 @@ -433,26 +433,31 @@ fi
75 AM_CONDITIONAL([SSE41_SUPPORTED], [test x$SSE41_SUPPORTED = x1])
76 AC_SUBST([SSE41_CFLAGS], $SSE41_CFLAGS)
78 -dnl Check for new-style atomic builtins
79 -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
80 +dnl Check for new-style atomic builtins. We first check without linking to
82 +AC_LINK_IFELSE([AC_LANG_SOURCE([[
86 - return __atomic_load_n(&n, __ATOMIC_ACQUIRE);
88 + return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
89 }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=1)
91 +dnl If that didn't work, we try linking with -latomic, which is needed on some
93 +if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" != x1; then
94 + save_LDFLAGS=$LDFLAGS
95 + LDFLAGS="$LDFLAGS -latomic"
96 + AC_LINK_IFELSE([AC_LANG_SOURCE([[
100 + return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
101 + }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=1 LIBATOMIC_LIBS="-latomic")
102 + LDFLAGS=$save_LDFLAGS
105 if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" = x1; then
106 DEFINES="$DEFINES -DUSE_GCC_ATOMIC_BUILTINS"
107 - dnl On some platforms, new-style atomics need a helper library
108 - AC_MSG_CHECKING(whether -latomic is needed)
109 - AC_LINK_IFELSE([AC_LANG_SOURCE([[
110 - #include <stdint.h>
113 - return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
114 - }]])], GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=no, GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=yes)
115 - AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC)
116 - if test "x$GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC" = xyes; then
117 - LIBATOMIC_LIBS="-latomic"
120 AC_SUBST([LIBATOMIC_LIBS])