<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJytV0tzozgQ_jX4ooLCYGP74IPjODOpnezMJt7DnighBGgHECsJO8mvn25hHDzjPHdSKVlIra_frVYi04flNSnojpOE85oY9SDqnBhJMnFPTMFJRkWJS0krylQTWdtV-5VIQ5zIZyWtc1c3VLFo4gJxe-9WbWmENjTnQECc6cXYmV6STCryXysMJ1pWnBgBQy33nuNfOv6qG7eArjjVwAjJexFaxYnQ8EmNXQM237kijNY1SJGJOkVR4lg_1Cze0TJmsgKJeEzrNNZ72sRzlGRfgJJWeNQJeISBmwhD7r6tbtewK1iBbBCT7oAtTUre6YzMqcq5ccLVUF5APfx3n8FVqxWMiahhLFMgJ3uqauCHU_eR5HXr7rjSQtauZko0xrXCGiLyWiqevoDUKPkvZ0bDAp4RJVeuMrgtEhg1rYURj1yh-pXEc-sb-p1fASGeud3e9RRrS-BZt3mpUCenAa2TxWNN40nkLMAfbc0MSI2WTqQsCZi7P4JWCVfUyEqwo-35PSsgNnisjZKo__q5E62oTTSJwbgbJ5i_RkV2sqQGdHICMNP6WTmeUHFx-9B85MAZ6opXUj3EUqWwEiycYPYUFMHVjqqjQ_o8geleKohY9ELKE0HB94am6L9D5qBLX84kAC131dtd_7TU-wXxvQKEnfvo07ZOOaQOTyHjMq54zTim_quJBPqejX07rhgDwxyqCIVkywG9kcpgCH1ar9GimMGdTDYZjStqPWALIeB5Hlq2Kx4hFg-QgTBZawFGB4lT3ijOqIEpSDYoYbptwMw8hY3kwXKywAcTnEAPeE8vJsDkpBKt6hRlxcCnzPRiZ7Is5R7V06JqoDoUlH3Hasn1U2UkMrOVceAnYPdzuYHvL-jj5ypKKrKsW8IZcd0cjtJf_M8qyHCMNao5VJI6E7kr7j27TJJ3kXfcoJjye5LOEn8cTLJwOok8L4gifzzmSco5J2PfjyaTjth13XfK1CfKRff_IRGdiQ__xA38CBwzI4DTTcdjctirKFMS3G24NnFXujX63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    <tr>
        <th>Summary</th>
        <td>
            compiler-rt uses deprecated built-ins for atomic access
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          glaubitz
      </td>
    </tr>
</table>

<pre>
    I have been trying to fix the failing builds on the buildbot `clang-sparc64-linux-multistage` [1] for quite some time now.

The reason for the failure is that the linker cannot find `__sync_val_compare_and_swap_8` when building on 32-bit SPARC which is not available on this target:

```
/usr/bin/ld: warning: -z gnu-version-script-compat ignored
/usr/bin/ld: projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_libignore.cpp.o: in function `bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint64_t>(__sanitizer::atomic_uint64_t volatile*, __sanitizer::atomic_uint64_t::Type*, __sanitizer::atomic_uint64_t::Type, __sanitizer::memory_order)':
/var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h:80: undefined reference to `__sync_val_compare_and_swap_8'
```

According to a bug report in GCC, the atomic built-ins `__sync_(...)` [3] are considered deprecated and have been superseded by the `__atomic_(...)` built-ins [4].

And, in fact, the following simple hack fixes the build of `compiler-rt` on 32-bit SPARC on Linux:

```diff
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index d7b0124f3546..266011ebdeee 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -206,7 +206,11 @@ macro(test_targets)
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
       test_target_arch(s390x "" "")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
-      test_target_arch(sparc "" "-m32")
+      if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+       test_target_arch(sparc "" "-m32 -latomic")
+      else()
+       test_target_arch(sparc "" "-m32")
+      endif()
       test_target_arch(sparcv9 "" "-m64")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
       # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
index fc13ca52dda7..bfe30c775663 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h
@@ -77,7 +77,7 @@ inline bool atomic_compare_exchange_strong(volatile T *a, typename T::Type *cmp,
   typedef typename T::Type Type;
   Type cmpv = *cmp;
   Type prev;
-  prev = __sync_val_compare_and_swap(&a->val_dont_use, cmpv, xchg);
+  prev = __atomic_compare_exchange(&a->val_dont_use, &cmpv, &xchg, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
   if (prev == cmpv) return true;
   *cmp = prev;
   return false;
```

I would therefore suggest that `compiler-rt` switches to the new built-ins for atomic access.

> [1] https://lab.llvm.org/staging/#/builders/113
> [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63368
> [3] https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/Atomic-Builtins.html
> [4] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytV0tz4ygQ_jXyhZLKeli2Dz44jjOT2snObOI97EmFEJLYkYQXkJ3k1283shw54zxrUimMoPm66aY_mlRmD4trUtIdJynnDTHqQTQFMZLk4p6YkpOcigqH0lZUmSaysaP2K5WGOPGYVbQpXL2lisWRC8LtvVu3lRHa0IKDAHEmF74zuSS5VOS_VhhOtKw5MQKaRu49Z3zpjJdduwF0xakGRSjem9AqToSGT2rsGKj5yRVhtGnAilw0GZqSJPqhYcm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