[llvm] r227411 - [LPM] Clean up the use of TLS in pretty stack trace and disable it
Chandler Carruth
chandlerc at gmail.com
Wed Jan 28 17:23:05 PST 2015
Author: chandlerc
Date: Wed Jan 28 19:23:04 2015
New Revision: 227411
URL: http://llvm.org/viewvc/llvm-project?rev=227411&view=rev
Log:
[LPM] Clean up the use of TLS in pretty stack trace and disable it
entirely when threads are not enabled. This should allow anyone who
needs to bootstrap or cope with a host loader without TLS support to
limp along without threading support.
There is still some bug in the PPC TLS stuff that is not worked around.
I'm getting access to a machine to reproduce and debug this further.
There is some chance that I'll have to add a terrible workaround for
PPC.
There is also some problem with iOS, but I have no ability to really
evaluate what the issue is there. I'm leaving it to folks maintaining
that platform to suggest a path forward -- personally I don't see any
useful path forward that supports threading in LLVM but does so without
support for *very basic* TLS. Note that we don't need more than some
pointers, and we don't need constructors, destructors, or any of the
other fanciness which remains widely unimplemented.
Modified:
llvm/trunk/include/llvm/Support/Compiler.h
llvm/trunk/lib/Support/PrettyStackTrace.cpp
Modified: llvm/trunk/include/llvm/Support/Compiler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Compiler.h?rev=227411&r1=227410&r2=227411&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Compiler.h (original)
+++ llvm/trunk/include/llvm/Support/Compiler.h Wed Jan 28 19:23:04 2015
@@ -373,4 +373,39 @@
#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
#endif
+/// \macro LLVM_THREAD_LOCAL
+/// \brief A thread-local storage specifier which can be used with globals,
+/// extern globals, and static globals.
+///
+/// This is essentially an extremely restricted analog to C++11's thread_local
+/// support, and uses that when available. However, it falls back on
+/// platform-specific or vendor-provided extensions when necessary. These
+/// extensions don't support many of the C++11 thread_local's features. You
+/// should only use this for PODs that you can statically initialize to
+/// some constant value. In almost all circumstances this is most appropriate
+/// for use with a pointer, integer, or small aggregation of pointers and
+/// integers.
+#if LLVM_ENABLE_THREADS
+#if __has_feature(cxx_thread_local)
+#define LLVM_THREAD_LOCAL thread_local
+#elif defined(_MSC_VER)
+// MSVC supports this with a __declspec.
+#define LLVM_THREAD_LOCAL __declspec(thread)
+#elif defined(__clang__) && defined(__powerpc64__)
+// 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
+// global-dynamic (called in most documents "general dynamic").
+// FIXME: Make this conditional on the Clang version once this is fixed in
+// top-of-tree.
+#define LLVM_THREAD_LOCAL __thread __attribute__((tls_model("global-dynamic")))
+#elif
+#define LLVM_THREAD_LOCAL __thread
+#endif
+#else // !LLVM_ENABLE_THREADS
+// If threading is disabled entirely, this compiles to nothing and you get
+// a normal global variable.
+#define LLVM_THREAD_LOCAL
+#endif
+
#endif
Modified: llvm/trunk/lib/Support/PrettyStackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PrettyStackTrace.cpp?rev=227411&r1=227410&r2=227411&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PrettyStackTrace.cpp (original)
+++ llvm/trunk/lib/Support/PrettyStackTrace.cpp Wed Jan 28 19:23:04 2015
@@ -16,6 +16,7 @@
#include "llvm-c/Core.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Config/config.h" // Get autoconf configuration settings
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/Watchdog.h"
#include "llvm/Support/raw_ostream.h"
@@ -29,26 +30,7 @@ using namespace llvm;
// We need a thread local pointer to manage the stack of our stack trace
// objects, but we *really* cannot tolerate destructors running and do not want
// to pay any overhead of synchronizing. As a consequence, we use a raw
-// 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.
-#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
-// global-dynamic (called in most documents "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("global-dynamic")))
-#else
-#define LLVM_THREAD_LOCAL __thread
-#endif
-#endif
-
+// thread-local variable.
static LLVM_THREAD_LOCAL const PrettyStackTraceEntry *PrettyStackTraceHead =
nullptr;
More information about the llvm-commits
mailing list