[llvm] 258a5d4 - [ORC][arm64e] Add PAC signing/stripping support to ExecutorAddr toPtr/fromPtr.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 17:41:57 PST 2024


Author: Lang Hames
Date: 2024-11-21T12:41:51+11:00
New Revision: 258a5d499e87dc85109d97d1708abef61893a5a0

URL: https://github.com/llvm/llvm-project/commit/258a5d499e87dc85109d97d1708abef61893a5a0
DIFF: https://github.com/llvm/llvm-project/commit/258a5d499e87dc85109d97d1708abef61893a5a0.diff

LOG: [ORC][arm64e] Add PAC signing/stripping support to ExecutorAddr toPtr/fromPtr.

On arm64e, uses the "wrap" and "unwrap" operations introduced in f14cb494a34d to
sign and strip pointers by default. Signing / striping can be overriden at the
toPtr / fromPtr callside by passing an explicit wrap / unwrap operation.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
index b7b98d55cc65b6..c9595ed4d99e72 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
@@ -20,6 +20,9 @@
 #include "llvm/Support/raw_ostream.h"
 
 #include <cassert>
+#if __has_feature(ptrauth_calls)
+#include <ptrauth.h>
+#endif
 #include <type_traits>
 
 namespace llvm {
@@ -33,12 +36,40 @@ class ExecutorAddr {
   /// A wrap/unwrap function that leaves pointers unmodified.
   template <typename T> using rawPtr = llvm::identity<T *>;
 
+#if __has_feature(ptrauth_calls)
+  template <typename T> class PtrauthSignDefault {
+  public:
+    constexpr T *operator()(T *P) {
+      if (std::is_function_v<T>)
+        return ptrauth_sign_unauthenticated(P, ptrauth_key_function_pointer, 0);
+      else
+        return P;
+    }
+  };
+
+  template <typename T> class PtrauthStripDefault {
+  public:
+    constexpr T *operator()(T *P) {
+      return ptrauth_strip(P, ptrauth_key_function_pointer);
+    }
+  };
+
+  /// Default wrap function to use on this host.
+  template <typename T> using defaultWrap = PtrauthSignDefault<T>;
+
+  /// Default unwrap function to use on this host.
+  template <typename T> using defaultUnwrap = PtrauthStripDefault<T>;
+
+#else
+
   /// Default wrap function to use on this host.
   template <typename T> using defaultWrap = rawPtr<T>;
 
   /// Default unwrap function to use on this host.
   template <typename T> using defaultUnwrap = rawPtr<T>;
 
+#endif
+
   /// Merges a tag into the raw address value:
   ///   P' = P | (TagValue << TagOffset).
   class Tag {


        


More information about the llvm-commits mailing list