configure.ac/meson.build: Fix -latomic test
authorNicolas Boichat <drinkcat@chromium.org>
Thu, 5 Apr 2018 01:33:09 +0000 (09:33 +0800)
committerMatt Turner <mattst88@gmail.com>
Mon, 7 May 2018 17:14:53 +0000 (10:14 -0700)
When compiling with LLVM 6.0 on x86 (32-bit) for Android, the test
fails to detect that -latomic is actually required, as the atomic
call is inlined.

In the code itself (src/util/disk_cache.c), we see this pattern:
p_atomic_add(cache->size, - (uint64_t)size);
where cache->size is an uint64_t *, and results in the following
link time error without -latomic:
src/util/disk_cache.c:628: error: undefined reference to '__atomic_fetch_add_8'

Fix the configure/meson test to replicate this pattern, which then
correctly realizes the need for -latomic.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
configure.ac
meson.build

index f1fbdcc6c7c0b0b81ae67be96a40fbd8a15a3ea2..c0fbfe94135a63e83f9b71a9e84fa503d3effaf7 100644 (file)
@@ -445,9 +445,11 @@ if test "x$GCC_ATOMIC_BUILTINS_SUPPORTED" = x1; then
     AC_MSG_CHECKING(whether -latomic is needed)
     AC_LINK_IFELSE([AC_LANG_SOURCE([[
     #include <stdint.h>
-    uint64_t v;
+    struct {
+        uint64_t *v;
+    } x;
     int main() {
-        return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
+        return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE);
     }]])], GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=no, GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC=yes)
     AC_MSG_RESULT($GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC)
     if test "x$GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC" = xyes; then
index 6e6176680961f6a7560c662c80c89583510d35ae..e52b4a51093247bef95a7aad0863081d845b4393 100644 (file)
@@ -849,8 +849,10 @@ if cc.compiles('int main() { int n; return __atomic_load_n(&n, __ATOMIC_ACQUIRE)
   # as ARM.
   if not cc.links('''#include <stdint.h>
                      int main() {
-                       uint64_t n;
-                       return (int)__atomic_load_n(&n, __ATOMIC_ACQUIRE);
+                       struct {
+                         uint64_t *v;
+                       } x;
+                       return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE);
                      }''',
                   name : 'GCC atomic builtins required -latomic')
     dep_atomic = cc.find_library('atomic')