From 88b38540d6b6f40b293eb1368292069bf8117bfc Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 25 Sep 2013 16:24:06 +0000 Subject: [PATCH] Fix "cannot compile this atomic library call" Thanks to Francisco Facioni for the refresh (Closes: #705115) --- debian/changelog | 2 ++ debian/patches/atomic_library_1.diff | 45 ++++++++++++++++++++++++++++ debian/patches/atomic_library_2.diff | 42 ++++++++++++++++++++++++++ debian/patches/series | 2 ++ 4 files changed, 91 insertions(+) create mode 100644 debian/patches/atomic_library_1.diff create mode 100644 debian/patches/atomic_library_2.diff diff --git a/debian/changelog b/debian/changelog index 785bc962..5fa20a13 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ llvm-toolchain-3.3 (1:3.3-10) unstable; urgency=low * Ship the lldb headers into lldb-X.Y-dev (Closes: #723743) I might create a liblldb-X.Y library at some point but I think it is too early. + * Fix "cannot compile this atomic library call" + Thanks to Francisco Facioni for the refresh (Closes: #705115) -- Sylvestre Ledru Mon, 09 Sep 2013 14:35:08 +0200 diff --git a/debian/patches/atomic_library_1.diff b/debian/patches/atomic_library_1.diff new file mode 100644 index 00000000..9c3b85d6 --- /dev/null +++ b/debian/patches/atomic_library_1.diff @@ -0,0 +1,45 @@ +Index: llvm-toolchain-3.3-3.3/clang/lib/Basic/Targets.cpp +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/clang/lib/Basic/Targets.cpp 2013-09-25 18:22:44.000000000 +0200 ++++ llvm-toolchain-3.3-3.3/clang/lib/Basic/Targets.cpp 2013-09-25 18:22:44.000000000 +0200 +@@ -3579,6 +3579,20 @@ + return Version >= 7; + } + ++ static bool shouldUseInlineAtomic(const llvm::Triple &T) { ++ // On linux, binaries targeting old cpus call functions in libgcc to ++ // perform atomic operations. The implementation in libgcc then calls into ++ // the kernel which on armv6 and newer uses ldrex and strex. The net result ++ // is that if we assume the kernel is at least as recent as the hardware, ++ // it is safe to use atomic instructions on armv6 and newer. ++ if (T.getOS() != llvm::Triple::Linux) ++ return false; ++ StringRef ArchName = T.getArchName(); ++ if (ArchName.startswith("armv6") || ArchName.startswith("armv7")) ++ return true; ++ return false; ++ } ++ + public: + ARMTargetInfo(const std::string &TripleStr) + : TargetInfo(TripleStr), ABI("aapcs-linux"), CPU("arm1136j-s"), IsAAPCS(true) +Index: llvm-toolchain-3.3-3.3/clang/test/CodeGen/linux-arm-atomic.c +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/clang/test/CodeGen/linux-arm-atomic.c 2013-09-25 18:22:44.000000000 +0200 ++++ llvm-toolchain-3.3-3.3/clang/test/CodeGen/linux-arm-atomic.c 2013-09-25 18:22:44.000000000 +0200 +@@ -1,5 +1,15 @@ + // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-linux | FileCheck %s + // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv6-unknown-linux | FileCheck %s ++ ++typedef int _Atomic_word; ++_Atomic_word exchange_and_add(volatile _Atomic_word *__mem, int __val) { ++ return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); ++} ++ ++// CHECK: define {{.*}} @exchange_and_add ++// CHECK: atomicrmw {{.*}} add ++// RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-linux | FileCheck %s ++// RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv6-unknown-linux | FileCheck %s + // RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-unknown-linux | FileCheck %s + + typedef int _Atomic_word; diff --git a/debian/patches/atomic_library_2.diff b/debian/patches/atomic_library_2.diff new file mode 100644 index 00000000..35efe244 --- /dev/null +++ b/debian/patches/atomic_library_2.diff @@ -0,0 +1,42 @@ +Index: llvm-toolchain-3.3-3.3/clang/test/CodeGen/linux-arm-atomic.c +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/clang/test/CodeGen/linux-arm-atomic.c 2013-09-25 18:23:43.000000000 +0200 ++++ llvm-toolchain-3.3-3.3/clang/test/CodeGen/linux-arm-atomic.c 2013-09-25 18:23:42.000000000 +0200 +@@ -1,5 +1,6 @@ + // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-linux | FileCheck %s + // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv6-unknown-linux | FileCheck %s ++// RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-unknown-linux | FileCheck %s + + typedef int _Atomic_word; + _Atomic_word exchange_and_add(volatile _Atomic_word *__mem, int __val) { +Index: llvm-toolchain-3.3-3.3/clang/lib/Basic/Targets.cpp +=================================================================== +--- llvm-toolchain-3.3-3.3.orig/clang/lib/Basic/Targets.cpp 2013-09-25 18:23:43.000000000 +0200 ++++ llvm-toolchain-3.3-3.3/clang/lib/Basic/Targets.cpp 2013-09-25 18:23:42.000000000 +0200 +@@ -3588,9 +3588,23 @@ + if (T.getOS() != llvm::Triple::Linux) + return false; + StringRef ArchName = T.getArchName(); +- if (ArchName.startswith("armv6") || ArchName.startswith("armv7")) +- return true; +- return false; ++ if (T.getArch() == llvm::Triple::arm) { ++ if (!ArchName.startswith("armv")) ++ return false; ++ StringRef VersionStr = ArchName.substr(4); ++ unsigned Version; ++ if (VersionStr.getAsInteger(10, Version)) ++ return false; ++ return Version >= 6; ++ } ++ assert(T.getArch() == llvm::Triple::thumb); ++ if (!ArchName.startswith("thumbv")) ++ return false; ++ StringRef VersionStr = ArchName.substr(6); ++ unsigned Version; ++ if (VersionStr.getAsInteger(10, Version)) ++ return false; ++ return Version >= 7; + } + + public: diff --git a/debian/patches/series b/debian/patches/series index e784c0de..7e54c41e 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -36,3 +36,5 @@ lldb-hurd.diff libstdc++-header-i386.diff kfreebsd_target_info_clang33.diff lldb-install-headers.diff +atomic_library_1.diff +atomic_library_2.diff