https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/208815

>From 97a612ea8e3eae00b91e38b5cda91961c7aba6a6 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <[email protected]>
Date: Fri, 10 Jul 2026 16:45:04 -0700
Subject: [PATCH] [lldb] Make PolicyStack::Get() out-of-line

LLDB builds with hidden visibility by default, so a function-local
static in an inline function is not shared across shared library
boundaries: each dylib that includes this header and calls an inline
Get() gets its own private copy of the thread_local stack, silently
splitting one logical per-thread stack into several. Declaring it
out-of-line ensures every dylib resolves to the single instance defined
in Policy.cpp.

Nothing currently pushes a policy from outside liblldb, so this has no
observable effect yet, but any future capability that needs to be set
in one shared library and read in another depends on this.

Signed-off-by: Med Ismail Bennani <[email protected]>
---
 lldb/include/lldb/Utility/Policy.h                   | 5 +----
 lldb/source/Utility/Policy.cpp                       | 8 ++++++++
 lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp | 2 +-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/include/lldb/Utility/Policy.h 
b/lldb/include/lldb/Utility/Policy.h
index c841daf47a97d..afeeab19c2ed0 100644
--- a/lldb/include/lldb/Utility/Policy.h
+++ b/lldb/include/lldb/Utility/Policy.h
@@ -95,10 +95,7 @@ struct Policy {
 /// thread's stack when the task starts.
 class PolicyStack {
 public:
-  static PolicyStack &Get() {
-    static thread_local PolicyStack s_stack;
-    return s_stack;
-  }
+  static PolicyStack &Get();
 
   Policy Current() const;
 
diff --git a/lldb/source/Utility/Policy.cpp b/lldb/source/Utility/Policy.cpp
index 3c2fa8f7fc867..301f7ee36e897 100644
--- a/lldb/source/Utility/Policy.cpp
+++ b/lldb/source/Utility/Policy.cpp
@@ -15,6 +15,14 @@
 
 using namespace lldb_private;
 
+// Declared out-of-line so every shared library resolves to the same
+// instance: a function-local static in an inline function is not
+// shared across shared library boundaries under hidden visibility.
+PolicyStack &PolicyStack::Get() {
+  static thread_local PolicyStack s_stack;
+  return s_stack;
+}
+
 Policy PolicyStack::Current() const {
   Policy p = m_stack.back();
   if (Log *log = GetLog(LLDBLog::Process)) {
diff --git a/lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp 
b/lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
index 7dd0a4a0f1871..bb1e0d8cd1fea 100644
--- a/lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
+++ b/lldb/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
@@ -94,7 +94,7 @@ class SymbolFilePDBTests : public testing::Test {
     if (!left.FileEquals(right))
       return false;
     // If BOTH have a directory, also compare the directories.
-    if (left.GetDirectory() && right.GetDirectory())
+    if (!left.GetDirectory().empty() && !right.GetDirectory().empty())
       return left.DirectoryEquals(right);
 
     // If one has a directory but not the other, they match.

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to