<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, 23 Feb 2018 at 13:18 Thierry Reding <<a href="mailto:thierry.reding@gmail.com" target="_blank">thierry.reding@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Thierry Reding <<a href="mailto:treding@nvidia.com" target="_blank">treding@nvidia.com</a>><br>
<br>
The disk cache implementation uses 64-bit atomic operations. For some<br>
architectures, such as 32-bit ARM, GCC will not be able to translate<br>
these operations into lock-free instructions and will instead rely on<br>
the external atomics library to provide these operations.<br>
<br>
Check at configuration time whether or not linking against libatomic<br>
is necessary and if so, create a dependency that can be used while<br>
linking the mesautil library.<br>
<br>
This is the meson equivalent of 2ef7f23820a6 ("configure: check if<br>
-latomic is needed for __atomic_*").<br>
<br>
Signed-off-by: Thierry Reding <<a href="mailto:treding@nvidia.com" target="_blank">treding@nvidia.com</a>><br>
---<br>
meson.build | 15 +++++++++++++++<br>
src/util/meson.build | 2 +-<br>
2 files changed, 16 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/meson.build b/meson.build<br>
index 121341a950c4..7c6f40573421 100644<br>
--- a/meson.build<br>
+++ b/meson.build<br>
@@ -800,6 +800,21 @@ endif<br>
if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE); }',<br>
name : 'GCC atomic builtins')<br>
pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'<br>
+<br>
+ # Not all atomic calls can be turned into lock-free instructions, in which<br>
+ # GCC will make calls into the libatomic library. Check whether we need to<br>
+ # link with -latomic.<br>
+ #<br>
+ # This can happen for 64-bit atomic operations on 32-bit architectures such<br>
+ # as ARM.<br>
+ if not cc.links('''#include <stdint.h><br>
+ int main() {<br>
+ uint64_t n;<br>
+ return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);<br>
+ }''',<br>
+ name : 'GCC atomic builtins required -latomic')<br>
+ dep_atomic = cc.find_library('atomic')<br>
+ endif<br>
endif<br>
if not cc.links('''#include <stdint.h><br>
uint64_t v;<br>
diff --git a/src/util/meson.build b/src/util/meson.build<br>
index b23dba3a9851..eece1cefef6a 100644<br>
--- a/src/util/meson.build<br>
+++ b/src/util/meson.build<br>
@@ -102,7 +102,7 @@ libmesa_util = static_library(<br>
'mesa_util',<br>
[files_mesa_util, format_srgb],<br>
include_directories : inc_common,<br>
- dependencies : [dep_zlib, dep_clock, dep_thread],<br>
+ dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic],<br>
c_args : [c_msvc_compat_args, c_vis_args],<br>
build_by_default : false<br>
)<br>
--<br>
2.16.2<br><br></blockquote><div><br></div><div>Hi</div><div><br></div><div>I had this issue when building a 32bit Mesa on x86-64 when using Clang, 64bit was fine.</div><div><br></div><div>Will this work for Clang too and if so can a similar change be made for autotools?</div><div><br></div><div>I'm waiting for a change to Meson that'll allow me to specify a 32bit llvm-config to test this on Meson with 32bit</div><div><br></div><div>Thanks</div><div><br></div><div>Mike</div></div></div>