[LPM] Try to work around a bug with local-dynamic TLS on PowerPC 64.
authorChandler Carruth <chandlerc@gmail.com>
Wed, 28 Jan 2015 19:29:22 +0000 (19:29 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 28 Jan 2015 19:29:22 +0000 (19:29 +0000)
Sadly, this precludes optimizing it down to initial-exec or local-exec
when statically linking, and in general makes the code slower on PPC 64,
but there's nothing else for it until we can arrange to produce the
correct bits for the linker.

Lots of thanks to Ulirch for tracking this down and Bill for working on
the long-term fix to LLVM so that we can relegate this to old host
clang versions.

I'll be watching the PPC build bots to make sure this effectively
revives them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227352 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/PrettyStackTrace.cpp

index 3483dfc3721995f622fc83000a1a14825cbf31f6..2e9634c6946652b49cd603d2248dd10943181eb5 100644 (file)
@@ -32,12 +32,25 @@ using namespace llvm;
 // thread-local variable. Some day, we should be able to use a limited subset
 // of C++11's thread_local, but compilers aren't up for it today.
 // FIXME: This should be moved to a Compiler.h abstraction.
-#ifdef _MSC_VER // MSVC supports this with a __declspec.
-static __declspec(thread) const PrettyStackTraceEntry
-    *PrettyStackTraceHead = nullptr;
-#else // Clang, GCC, and all compatible compilers tend to use __thread.
-static __thread const PrettyStackTraceEntry *PrettyStackTraceHead = nullptr;
+#ifdef _MSC_VER
+// MSVC supports this with a __declspec.
+#define LLVM_THREAD_LOCAL __declspec(thread)
+#else
+// Clang, GCC, and all compatible compilers tend to use __thread. But we need
+// to work aronud a bug in the combination of Clang's compilation of
+// local-dynamic TLS and the ppc64 linker relocations which we do by forcing to
+// general-dynamic.
+// FIXME: Make this conditional on the Clang version once this is fixed in
+// top-of-tree.
+#if defined(__clang__) && defined(__powerpc64__)
+#define LLVM_THREAD_LOCAL __thread __attribute__((tls_model("general-dynamic")))
+#else
+#define LLVM_THREAD_LOCAL __thread
 #endif
+#endif
+
+static LLVM_THREAD_LOCAL const PrettyStackTraceEntry *PrettyStackTraceHead =
+    nullptr;
 
 static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
   unsigned NextID = 0;