llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/183993.diff


2 Files Affected:

- (modified) 
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (+10-1) 
- (modified) lldb/test/API/lang/c/tls_globals/TestTlsGlobals.py (-1) 


``````````diff
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):

``````````

</details>


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

Reply via email to