Skip to content

Commit 7106f58

Browse files
committed
[lldb] Make the thread_local g_global_boundary accessed from a single file
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 msys2/MINGW-packages#8868. Differential Revision: https://reviews.llvm.org/D111779
1 parent ca0ce99 commit 7106f58

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lldb/include/lldb/Utility/ReproducerInstrumentation.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,17 +868,14 @@ class Recorder {
868868

869869
/// Mark the current thread as a private thread and pretend that everything
870870
/// on this thread is behind happening behind the API boundary.
871-
static void PrivateThread() { g_global_boundary = true; }
871+
static void PrivateThread();
872872

873873
private:
874874
static unsigned GetNextSequenceNumber() { return g_sequence++; }
875875
unsigned GetSequenceNumber() const;
876876

877877
template <typename T> friend struct replay;
878-
void UpdateBoundary() {
879-
if (m_local_boundary)
880-
g_global_boundary = false;
881-
}
878+
void UpdateBoundary();
882879

883880
#ifdef LLDB_REPRO_INSTR_TRACE
884881
void Log(unsigned id) {
@@ -902,9 +899,6 @@ class Recorder {
902899
/// The sequence number for this pair of function and result.
903900
unsigned m_sequence;
904901

905-
/// Whether we're currently across the API boundary.
906-
static thread_local bool g_global_boundary;
907-
908902
/// Global mutex to protect concurrent access.
909903
static std::mutex g_mutex;
910904

lldb/source/Utility/ReproducerInstrumentation.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
using namespace lldb_private;
1717
using namespace lldb_private::repro;
1818

19+
// Whether we're currently across the API boundary.
20+
static thread_local bool g_global_boundary = false;
21+
1922
void *IndexToObject::GetObjectForIndexImpl(unsigned idx) {
2023
return m_mapping.lookup(idx);
2124
}
@@ -227,6 +230,13 @@ unsigned Recorder::GetSequenceNumber() const {
227230
return m_sequence;
228231
}
229232

233+
void Recorder::PrivateThread() { g_global_boundary = true; }
234+
235+
void Recorder::UpdateBoundary() {
236+
if (m_local_boundary)
237+
g_global_boundary = false;
238+
}
239+
230240
void InstrumentationData::Initialize(Serializer &serializer,
231241
Registry &registry) {
232242
InstanceImpl().emplace(serializer, registry);
@@ -248,6 +258,5 @@ llvm::Optional<InstrumentationData> &InstrumentationData::InstanceImpl() {
248258
return g_instrumentation_data;
249259
}
250260

251-
thread_local bool lldb_private::repro::Recorder::g_global_boundary = false;
252261
std::atomic<unsigned> lldb_private::repro::Recorder::g_sequence;
253262
std::mutex lldb_private::repro::Recorder::g_mutex;

0 commit comments

Comments
 (0)