]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - package/mesa3d/0003-configure.ac-rework-latomic-check.patch
mesa3d: fix build with gcc <= 4.7 on some architectures
[coffee/buildroot.git] / package / mesa3d / 0003-configure.ac-rework-latomic-check.patch
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
5
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.
11
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:
17
18 powerpc-ctng_e500v2-linux-gnuspe/bin/ld: cannot find -latomic
19
20 This commit aims at fixing that, by not assuming -latomic is
21 available. The commit re-organizes the atomic intrinsics detection as
22 follows:
23
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,
26      and we're good to go.
27
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.
31
32 This has been tested in three situations:
33
34  - On x86-64, where atomic instrinsics are all built-in, with no need
35    for libatomic. In this case, config.log contains:
36
37    GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE='#'
38    GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE=''
39    LIBATOMIC_LIBS=''
40
41    This means: atomic intrinsics are available, and we don't need to
42    link with libatomic.
43
44  - On NIOS2, where atomic intrinsics are available, but some of them
45    (64-bit ones) require using libatomic. In this case, config.log
46    contains:
47
48    GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE='#'
49    GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE=''
50    LIBATOMIC_LIBS='-latomic'
51
52    This means: atomic intrinsics are available, and we need to link
53    with libatomic.
54
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:
58
59    GCC_ATOMIC_BUILTINS_SUPPORTED_FALSE=''
60    GCC_ATOMIC_BUILTINS_SUPPORTED_TRUE='#'
61
62    With means that atomic intrinsics are not usable.
63
64 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
65 Upstream-status: https://lists.freedesktop.org/archives/mesa-dev/2018-May/194214.html
66 ---
67  configure.ac | 37 +++++++++++++++++++++----------------
68  1 file changed, 21 insertions(+), 16 deletions(-)
69
70 diff --git a/configure.ac b/configure.ac
71 index f1fbdcc6c7..c94e547874 100644
72 --- a/configure.ac
73 +++ b/configure.ac
74 @@ -433,26 +433,31 @@ fi
75  AM_CONDITIONAL([SSE41_SUPPORTED], [test x$SSE41_SUPPORTED = x1])
76  AC_SUBST([SSE41_CFLAGS], $SSE41_CFLAGS)
77  
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
81 +dnl -latomic.
82 +AC_LINK_IFELSE([AC_LANG_SOURCE([[
83 +#include <stdint.h>
84  int main() {
85 -    int n;
86 -    return __atomic_load_n(&n, __ATOMIC_ACQUIRE);
87 +    uint64_t n;
88 +    return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
89  }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=1)
90 +
91 +dnl If that didn't work, we try linking with -latomic, which is needed on some
92 +dnl platforms.
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([[
97 +   #include <stdint.h>
98 +   int main() {
99 +        uint64_t n;
100 +        return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
101 +   }]])], GCC_ATOMIC_BUILTINS_SUPPORTED=1 LIBATOMIC_LIBS="-latomic")
102 +   LDFLAGS=$save_LDFLAGS
103 +fi
104 +
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>
111 -    uint64_t v;
112 -    int main() {
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"
118 -    fi
119  fi
120  AC_SUBST([LIBATOMIC_LIBS])
121  
122 -- 
123 2.14.3
124