Skip to content

Commit a27d34b

Browse files
authored
[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
1 parent 4e0b68c commit a27d34b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,8 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
11591159
// size_t offset;
11601160
// }
11611161
//
1162-
// The strategy is to take get_addr, call it with the address of the
1163-
// containing TLS_Thunk structure, and add the offset to the resulting
1164-
// pointer to get the data block.
1162+
// The strategy is to take get_addr and call it with the address of the
1163+
// containing TLS_Thunk structure.
11651164
//
11661165
// On older apple platforms, the key is treated as a pthread_key_t and passed
11671166
// to pthread_getspecific. The pointer returned from that call is added to
@@ -1190,7 +1189,7 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
11901189
const addr_t tls_data = evaluate_tls_address(
11911190
thunk_load_addr, llvm::ArrayRef<addr_t>(tls_load_addr));
11921191
if (tls_data != LLDB_INVALID_ADDRESS)
1193-
return tls_data + tls_offset;
1192+
return tls_data;
11941193
}
11951194
}
11961195

lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def test(self):
7373
VARIABLES_DISPLAYED_CORRECTLY,
7474
patterns=[r"\(int\) \$.* = 88"],
7575
)
76+
self.expect(
77+
"expr var_static2",
78+
VARIABLES_DISPLAYED_CORRECTLY,
79+
patterns=[r"\(int\) \$.* = 66"],
80+
)
7681
self.expect(
7782
"expr var_shared",
7883
VARIABLES_DISPLAYED_CORRECTLY,
@@ -104,6 +109,11 @@ def test(self):
104109
VARIABLES_DISPLAYED_CORRECTLY,
105110
patterns=[r"\(int\) \$.* = 44"],
106111
)
112+
self.expect(
113+
"expr var_static2",
114+
VARIABLES_DISPLAYED_CORRECTLY,
115+
patterns=[r"\(int\) \$.* = 22"],
116+
)
107117
self.expect(
108118
"expr var_shared",
109119
VARIABLES_DISPLAYED_CORRECTLY,

lldb/test/API/lang/c/tls_globals/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ touch_shared();
1010

1111
// Create some TLS storage within the static executable.
1212
__thread int var_static = 44;
13+
__thread int var_static2 = 22;
1314

1415
void *fn_static(void *param)
1516
{
1617
var_static *= 2;
18+
var_static2 *= 3;
1719
shared_check();
1820
usleep(1); // thread breakpoint
1921
for(;;)

0 commit comments

Comments
 (0)