[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
Mon Jan 23 10:44:26 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG484bc2bcc799: Run cmdline address expressions through ABI's FixAddress (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141629/new/

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.491451.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230123/a15339b0/attachment-0001.bin>


More information about the lldb-commits mailing list