[Lldb-commits] [PATCH] D141629: Run address expression argument values through ABI::FixCodeAddress to strip TBI/pointer auth bytes on AArch64

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 12 12:58:48 PST 2023


jasonmolenda created this revision.
jasonmolenda added a reviewer: DavidSpickett.
jasonmolenda added a project: LLDB.
Herald added subscribers: Michael137, kristof.beyls.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

This is a different way of accomplishing the phab @DavidSpickett put up a few months ago, https://reviews.llvm.org/D136938 , which cleared these bits specifically for breakpoints in Target::GetBreakableLoadAddress.

I don't have an actual test case for this; this phabracator includes a test, but it actually won't run and I'm undecided about committing it (@JDevlieghere thinks landing a test that can't run any time soon is a bad idea).  The llvm.org clang doesn't support generating the (not yet finalized) arm64e ABI on Darwin systems (ARMv8.3+ using a ptrauth ABI), although it can be forced to output a non-ptrauth codegen in an arm64e mach-o file.  Even if the in-tree llvm.org clang could generate correct arm64e binaries, macOS won't allow you to run them without setting a boot-arg (`-arm64e_preview_abi`) on the test system & rebooting for it to be enabled.  I included the test case in this phabracator to show an example of how it could be tested if these things weren't true. :)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141629

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/Interpreter/OptionArgParser.cpp
  lldb/test/API/macosx/ptrauth-address-expressions/Makefile
  lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
  lldb/test/API/macosx/ptrauth-address-expressions/main.c


Index: lldb/test/API/macosx/ptrauth-address-expressions/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/ptrauth-address-expressions/main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int foo () { return 10; }
+
+int main () 
+{
+  int (*fptr)() = foo;
+  printf ("%p\n", fptr); // break here
+  return fptr();
+}
Index: lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/ptrauth-address-expressions/TestPtrauthAddressExpressions.py
@@ -0,0 +1,28 @@
+"""Test that AArch64 PAC bits are stripped from address expression arguments"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestPtrauthAddressExpressions(TestBase):
+
+    NO_DEBUG_INFO_TESTCASE = True
+
+    # On Darwin systems, arch arm64e means ARMv8.3 with ptrauth
+    # ABI used.
+    @skipIf(archs=no_match(['arm64e']))
+
+    def test(self):
+
+        # Skip this test if not running on AArch64 target that supports PAC
+        if not self.isAArch64PAuth():
+            self.skipTest('Target must support pointer authentication.')
+        self.source = 'main.c'
+        self.build()
+        (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+                           "break here", lldb.SBFileSpec(self.source, False))
+
+        self.expect("p fptr", substrs=[self.source])
+        self.expect("ima loo -va fptr", substrs=[self.source])
+        self.expect("break set -a fptr", substrs=[self.source])
Index: lldb/test/API/macosx/ptrauth-address-expressions/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/macosx/ptrauth-address-expressions/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Interpreter/OptionArgParser.cpp
===================================================================
--- lldb/source/Interpreter/OptionArgParser.cpp
+++ lldb/source/Interpreter/OptionArgParser.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Interpreter/OptionArgParser.h"
 #include "lldb/DataFormatters/FormatManager.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
@@ -157,6 +158,10 @@
   if (!s.getAsInteger(0, addr)) {
     if (error_ptr)
       error_ptr->Clear();
+    Process *process = exe_ctx->GetProcessPtr();
+    if (process)
+      if (ABISP abi_sp = process->GetABI())
+        addr = abi_sp->FixCodeAddress(addr);
     return addr;
   }
 
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1243,6 +1243,8 @@
         return self.isAArch64() and "mte" in self.getCPUInfo()
 
     def isAArch64PAuth(self):
+        if self.getArchitecture() == "arm64e":
+            return True
         return self.isAArch64() and "paca" in self.getCPUInfo()
 
     def getArchitecture(self):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141629.488742.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230112/9416459f/attachment.bin>


More information about the lldb-commits mailing list