[llvm] r227352 - [LPM] Try to work around a bug with local-dynamic TLS on PowerPC 64.

Chandler Carruth chandlerc at gmail.com
Wed Jan 28 11:29:22 PST 2015

Author: chandlerc
Date: Wed Jan 28 13:29:22 2015
New Revision: 227352

URL: http://llvm.org/viewvc/llvm-project?rev=227352&view=rev
[LPM] Try to work around a bug with local-dynamic TLS on PowerPC 64.

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.


Modified: llvm/trunk/lib/Support/PrettyStackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PrettyStackTrace.cpp?rev=227352&r1=227351&r2=227352&view=diff
--- llvm/trunk/lib/Support/PrettyStackTrace.cpp (original)
+++ llvm/trunk/lib/Support/PrettyStackTrace.cpp Wed Jan 28 13:29:22 2015
@@ -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)
+// 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")))
+#define LLVM_THREAD_LOCAL __thread
+static LLVM_THREAD_LOCAL const PrettyStackTraceEntry *PrettyStackTraceHead =
+    nullptr;
 static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
   unsigned NextID = 0;

More information about the llvm-commits mailing list