[Lldb-commits] [PATCH] D111779: [lldb] Make the thread_local g_global_boundary accessed from a single file

Martin Storsjö via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 13 23:44:29 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: labath, teemperor, JDevlieghere.
mstorsjo requested review of this revision.
Herald added a project: LLDB.

This makes the compiler generated code for accessing the thread local
variable much simpler (no need for wrapper functions and weak pointers
to potential init functions), and can avoid toolchain bugs regarding how
to access TLS variables.

In particular, this fixes LLDB when built with current GCC/binutils for
MinGW, see https://github.com/msys2/MINGW-packages/issues/8868.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111779

Files:
  lldb/include/lldb/Utility/ReproducerInstrumentation.h
  lldb/source/Utility/ReproducerInstrumentation.cpp


Index: lldb/source/Utility/ReproducerInstrumentation.cpp
===================================================================
--- lldb/source/Utility/ReproducerInstrumentation.cpp
+++ lldb/source/Utility/ReproducerInstrumentation.cpp
@@ -16,6 +16,9 @@
 using namespace lldb_private;
 using namespace lldb_private::repro;
 
+// Whether we're currently across the API boundary.
+static thread_local bool g_global_boundary = false;
+
 void *IndexToObject::GetObjectForIndexImpl(unsigned idx) {
   return m_mapping.lookup(idx);
 }
@@ -227,6 +230,13 @@
   return m_sequence;
 }
 
+void Recorder::PrivateThread() { g_global_boundary = true; }
+
+void Recorder::UpdateBoundary() {
+  if (m_local_boundary)
+    g_global_boundary = false;
+}
+
 void InstrumentationData::Initialize(Serializer &serializer,
                                      Registry &registry) {
   InstanceImpl().emplace(serializer, registry);
@@ -248,6 +258,5 @@
   return g_instrumentation_data;
 }
 
-thread_local bool lldb_private::repro::Recorder::g_global_boundary = false;
 std::atomic<unsigned> lldb_private::repro::Recorder::g_sequence;
 std::mutex lldb_private::repro::Recorder::g_mutex;
Index: lldb/include/lldb/Utility/ReproducerInstrumentation.h
===================================================================
--- lldb/include/lldb/Utility/ReproducerInstrumentation.h
+++ lldb/include/lldb/Utility/ReproducerInstrumentation.h
@@ -868,17 +868,14 @@
 
   /// Mark the current thread as a private thread and pretend that everything
   /// on this thread is behind happening behind the API boundary.
-  static void PrivateThread() { g_global_boundary = true; }
+  static void PrivateThread();
 
 private:
   static unsigned GetNextSequenceNumber() { return g_sequence++; }
   unsigned GetSequenceNumber() const;
 
   template <typename T> friend struct replay;
-  void UpdateBoundary() {
-    if (m_local_boundary)
-      g_global_boundary = false;
-  }
+  void UpdateBoundary();
 
 #ifdef LLDB_REPRO_INSTR_TRACE
   void Log(unsigned id) {
@@ -902,9 +899,6 @@
   /// The sequence number for this pair of function and result.
   unsigned m_sequence;
 
-  /// Whether we're currently across the API boundary.
-  static thread_local bool g_global_boundary;
-
   /// Global mutex to protect concurrent access.
   static std::mutex g_mutex;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111779.379615.patch
Type: text/x-patch
Size: 2313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211014/99168b36/attachment-0001.bin>


More information about the lldb-commits mailing list