Author: Med Ismail Bennani
Date: 2026-07-10T23:59:11Z
New Revision: 18f8a356957608d8b6c4318698af53aa4f27a36f

URL: 
https://github.com/llvm/llvm-project/commit/18f8a356957608d8b6c4318698af53aa4f27a36f
DIFF: 
https://github.com/llvm/llvm-project/commit/18f8a356957608d8b6c4318698af53aa4f27a36f.diff

LOG: [lldb] Make PolicyStack::Get() out-of-line (#208815)

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]>

Added: 
    

Modified: 
    lldb/include/lldb/Utility/Policy.h
    lldb/source/Utility/Policy.cpp

Removed: 
    


################################################################################
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)) {


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

Reply via email to