Skip to content

[lldb] Fix TLS support on Darwin platforms #11116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,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
Expand Down Expand Up @@ -1204,7 +1203,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;
}
}

Expand Down
10 changes: 10 additions & 0 deletions lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def test(self):
VARIABLES_DISPLAYED_CORRECTLY,
patterns=["\(int\) \$.* = 88"],
)
self.expect(
"expr var_static2",
VARIABLES_DISPLAYED_CORRECTLY,
patterns=[r"\(int\) \$.* = 66"],
)
self.expect(
"expr var_shared",
VARIABLES_DISPLAYED_CORRECTLY,
Expand Down Expand Up @@ -104,6 +109,11 @@ def test(self):
VARIABLES_DISPLAYED_CORRECTLY,
patterns=["\(int\) \$.* = 44"],
)
self.expect(
"expr var_static2",
VARIABLES_DISPLAYED_CORRECTLY,
patterns=[r"\(int\) \$.* = 22"],
)
self.expect(
"expr var_shared",
VARIABLES_DISPLAYED_CORRECTLY,
Expand Down
2 changes: 2 additions & 0 deletions lldb/test/API/lang/c/tls_globals/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(;;)
Expand Down