Skip to content

Conversation

@Jlalond
Copy link
Contributor

@Jlalond Jlalond commented Aug 20, 2025

Unlike x86, ARM doesn't support a generic thread pointer for TLS data, so things like

reg read tp
...
memory read tp

Don't work, and you need to specify tpidr. This works, especially because that's the name GDB uses. But for ease of use, and at the request of aperez I've made it so we can reference it via tp.

I personally don't have an aarch machine, and all the arm examples in Shell/Register/Core are freebsd and don't contain tpidr, so I was unable to add a shell test for this. I added a test to the AARCH register tests, but without an Aarch machine I'm hoping these work.

@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)

Changes

Unlike x86, ARM doesn't support a generic thread pointer for TLS data, so things like

reg read tp
...
memory read tp

Don't work, and you need to specify tpidr. This works, especially because that's the name GDB uses. But for ease of use, and at the request of @aperez I've made it so we can reference it via tp.

I personally don't have an aarch machine, and all the arm examples in Shell/Register/Core are freebsd and don't contain tpidr, so I was unable to add a shell test for this. I added a test to the AARCH register tests, but without an Aarch machine I'm hoping these work.


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

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp (+10-1)
  • (modified) lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py (+3)
diff --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
index fbf128553fd5e..d29af3c568dd7 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
@@ -79,7 +79,16 @@ static lldb_private::RegisterInfo g_register_infos_mte[] = {
     DEFINE_EXTENSION_REG(mte_ctrl)};
 
 static lldb_private::RegisterInfo g_register_infos_tls[] = {
-    DEFINE_EXTENSION_REG(tpidr),
+    {"tpidr",
+     nullptr,
+     8,
+     0,
+     lldb::eEncodingUint,
+     lldb::eFormatHex,
+     {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_REGNUM_GENERIC_TP},
+     nullptr,
+     nullptr,
+     nullptr},
     // Only present when SME is present
     DEFINE_EXTENSION_REG(tpidr2)};
 
diff --git a/lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py b/lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
index ec8eb1c05dfb8..09c2cca18f9c0 100644
--- a/lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
+++ b/lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
@@ -93,6 +93,8 @@ def check_tls_reg(self, registers):
         for register in registers:
             self.expect("p {}_was_set".format(register), substrs=["true"])
 
+        self.expect("reg read tp", substrs=[hex(set_values["tpidr"])])
+
     @skipUnlessArch("aarch64")
     @skipUnlessPlatform(["linux"])
     def test_tls_no_sme(self):
@@ -100,6 +102,7 @@ def test_tls_no_sme(self):
             self.skipTest("SME must not be present.")
 
         self.check_tls_reg(["tpidr"])
+        
 
     @skipUnlessArch("aarch64")
     @skipUnlessPlatform(["linux"])

@Jlalond Jlalond force-pushed the aarch64-tp-register branch from 789dd0d to 77689bd Compare August 20, 2025 00:08
@Jlalond Jlalond force-pushed the aarch64-tp-register branch from 77689bd to 84f48ee Compare August 20, 2025 00:09
@github-actions
Copy link

github-actions bot commented Aug 21, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Jlalond Jlalond force-pushed the aarch64-tp-register branch from 35a9f53 to 1292a0d Compare August 21, 2025 22:09
@DavidSpickett
Copy link
Collaborator

DavidSpickett commented Aug 26, 2025

Please title this AArch64 or Arm64 instead of ARM. I know that's our fault on the branding side but in this case, TLS is very different between 32-bit Arm sometimes aka "ARM" and AArch64 aka the 64-bit mode of Armv8/Armv9.

Not that it has to matter to you but to me seeing ARM makes me think 32-bit.

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't make TLS variables work (#71666), but I assume you're aware of that. Someone was working on this problem recently but I don't know how far they got.

Making the generic name available for reading is a good idea regardless.

@Jlalond Jlalond changed the title [LLDB][ARM] Make TPIDR a generic tp register [LLDB][AArch64] Make TPIDR a generic tp register Aug 27, 2025
@Jlalond
Copy link
Contributor Author

Jlalond commented Sep 3, 2025

@DavidSpickett Please take a second look when you get a chance

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Remove the @ mention in the description before merging, so that they don't get spammed when this gets merged into forks.

@Jlalond Jlalond merged commit 6505bc3 into llvm:main Sep 4, 2025
9 checks passed
@Jlalond
Copy link
Contributor Author

Jlalond commented Sep 4, 2025

Thanks @DavidSpickett!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants