https://github.com/bulbazord updated 
https://github.com/llvm/llvm-project/pull/151601

>From 28e3ee59aca4c4c8ce6a5d9e67be48cf692d7d86 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangf...@apple.com>
Date: Thu, 31 Jul 2025 14:48:55 -0700
Subject: [PATCH 1/2] [lldb] Fix TLS support on Darwin platforms

When I wrote this previously, I was unaware that the TLS function
already adds the offset. The test was working previously because the
offset was 0 in this case (only 1 thread-local variable). I added
another thread-local variable to the test to make sure the offset is
indeed handled correctly.

rdar://156547548
---
 .../DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp  |  7 +++----
 lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py     | 10 ++++++++++
 lldb/test/API/lang/c/tls_globals/main.c                |  2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp 
b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
index 1270d57423c7b..8deb17c99136e 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -1159,9 +1159,8 @@ DynamicLoaderDarwin::GetThreadLocalData(const 
lldb::ModuleSP module_sp,
   //  size_t offset;
   // }
   //
-  // The strategy is to take get_addr, call it with the address of the
-  // containing TLS_Thunk structure, and add the offset to the resulting
-  // pointer to get the data block.
+  // The strategy is to take get_addr and call it with the address of the
+  // containing TLS_Thunk structure.
   //
   // On older apple platforms, the key is treated as a pthread_key_t and passed
   // to pthread_getspecific. The pointer returned from that call is added to
@@ -1190,7 +1189,7 @@ DynamicLoaderDarwin::GetThreadLocalData(const 
lldb::ModuleSP module_sp,
       const addr_t tls_data = evaluate_tls_address(
           thunk_load_addr, llvm::ArrayRef<addr_t>(tls_load_addr));
       if (tls_data != LLDB_INVALID_ADDRESS)
-        return tls_data + tls_offset;
+        return tls_data;
     }
   }
 
diff --git a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py 
b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
index 5c0f304bdb37e..dad2b19a67170 100644
--- a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
+++ b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
@@ -73,6 +73,11 @@ def test(self):
             VARIABLES_DISPLAYED_CORRECTLY,
             patterns=[r"\(int\) \$.* = 88"],
         )
+        self.expect(
+            "expr var_static2",
+            VARIABLES_DISPLAYED_CORRECTLY,
+            patterns=[r"\(int\) \$.* = 66"],
+        )
         self.expect(
             "expr var_shared",
             VARIABLES_DISPLAYED_CORRECTLY,
@@ -104,6 +109,11 @@ def test(self):
             VARIABLES_DISPLAYED_CORRECTLY,
             patterns=[r"\(int\) \$.* = 44"],
         )
+        self.expect(
+            "expr var_static2",
+            VARIABLES_DISPLAYED_CORRECTLY,
+            patterns=[r"\(int\) \$.* = 22"],
+        )
         self.expect(
             "expr var_shared",
             VARIABLES_DISPLAYED_CORRECTLY,
diff --git a/lldb/test/API/lang/c/tls_globals/main.c 
b/lldb/test/API/lang/c/tls_globals/main.c
index bdfd78c1ac34b..890f823c2046b 100644
--- a/lldb/test/API/lang/c/tls_globals/main.c
+++ b/lldb/test/API/lang/c/tls_globals/main.c
@@ -10,10 +10,12 @@ touch_shared();
 
 // Create some TLS storage within the static executable.
 __thread int var_static = 44;
+__thread int var_static2 = 22;
 
 void *fn_static(void *param)
 {
        var_static *= 2;
+  var_static2 *= 3;
        shared_check();
        usleep(1); // thread breakpoint
        for(;;)

>From a0679fb1ab6cda9db3683998aca579aee4fdaf85 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangf...@apple.com>
Date: Mon, 4 Aug 2025 11:30:15 -0700
Subject: [PATCH 2/2] fixup! [lldb] Fix TLS support on Darwin platforms

---
 lldb/test/API/lang/c/tls_globals/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/API/lang/c/tls_globals/main.c 
b/lldb/test/API/lang/c/tls_globals/main.c
index 890f823c2046b..fac760b350ab2 100644
--- a/lldb/test/API/lang/c/tls_globals/main.c
+++ b/lldb/test/API/lang/c/tls_globals/main.c
@@ -15,7 +15,7 @@ __thread int var_static2 = 22;
 void *fn_static(void *param)
 {
        var_static *= 2;
-  var_static2 *= 3;
+       var_static2 *= 3;
        shared_check();
        usleep(1); // thread breakpoint
        for(;;)

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to