https://github.com/xgupta created 
https://github.com/llvm/llvm-project/pull/183993

On Linux AArch64, LLDB failed to resolve thread-local storage (TLS) variables 
due to incorrect computation of the DTV pointer.

LLDB applied the _thread_db_pthread_dtvp offset relative to the thread pointer 
(TPIDR_EL0). However, on Linux AArch64, TPIDR_EL0 already points directly to 
struct pthread, and the DTV pointer is located at offset 0.

Also enabled the disabled TLS test case for aarch64 and arm.

Original issue - https://github.com/llvm/llvm-project/issues/83466

>From 5278f7e0031eb8b6077fcd7f16cf65e12a6c8c21 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <[email protected]>
Date: Sun, 1 Mar 2026 09:56:17 +0000
Subject: [PATCH] [LLDB][Linux][AArch64] Fix TLS lookup and enable TLS test

On Linux AArch64, LLDB failed to resolve thread-local storage (TLS)
variables due to incorrect computation of the DTV pointer.

LLDB applied the _thread_db_pthread_dtvp offset relative to the
thread pointer (TPIDR_EL0). However, on Linux AArch64, TPIDR_EL0
already points directly to struct pthread, and the DTV pointer is
located at offset 0.

Also enabled the disabled TLS test case for aarch64 and arm.

Original issue - https://github.com/llvm/llvm-project/issues/83466
---
 .../POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp             | 11 ++++++++++-
 lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py    |  1 -
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 1d814f93484d8..a4a59593efd0f 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -865,7 +865,16 @@ DynamicLoaderPOSIXDYLD::GetThreadLocalData(const 
lldb::ModuleSP module_sp,
   }
 
   // Lookup the DTV structure for this thread.
-  addr_t dtv_ptr = tp + metadata.dtv_offset;
+  // On Linux AArch64, TPIDR_EL0 already points directly to struct pthread
+  // and the DTV pointer is stored at offset 0 while for X86 DTV pointer is
+  // located at an offset inside struct pthread.
+  const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
+  const llvm::Triple &triple = arch.GetTriple();
+  addr_t dtv_ptr =
+      (triple.isOSLinux() && triple.getArch() == llvm::Triple::aarch64)
+          ? tp
+          : tp + metadata.dtv_offset;
+
   addr_t dtv = ReadPointer(dtv_ptr);
   if (dtv == LLDB_INVALID_ADDRESS) {
     LLDB_LOGF(log, "GetThreadLocalData error: fail to read dtv");
diff --git a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py 
b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
index ed696bca54ab4..8d6963738aa5e 100644
--- a/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
+++ b/lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py
@@ -38,7 +38,6 @@ def setUp(self):
     # TLS works differently on Windows, this would need to be implemented
     # separately.
     @skipIfWindows
-    @skipIf(oslist=["linux"], archs=["arm$", "aarch64"])
     @skipIf(oslist=no_match([lldbplatformutil.getDarwinOSTriples(), "linux"]))
     @expectedFailureIf(lldbplatformutil.xcode15LinkerBug())
     def test(self):

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

Reply via email to