[Lldb-commits] [lldb] a27d34b - [lldb] Fix TLS support on Darwin platforms (#151601)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 4 11:44:20 PDT 2025
Author: Alex Langford
Date: 2025-08-04T11:44:17-07:00
New Revision: a27d34b3f22b1134b2d47590c25b7f81eb7710b2
URL: https://github.com/llvm/llvm-project/commit/a27d34b3f22b1134b2d47590c25b7f81eb7710b2
DIFF: https://github.com/llvm/llvm-project/commit/a27d34b3f22b1134b2d47590c25b7f81eb7710b2.diff
LOG: [lldb] Fix TLS support on Darwin platforms (#151601)
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
Added:
Modified:
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
lldb/test/API/lang/c/tls_globals/main.c
Removed:
################################################################################
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..fac760b350ab2 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(;;)
More information about the lldb-commits
mailing list