[llvm] [llvm-exegesis][AArch64] Check for PAC keys before disabling them (PR #138643)

Anatoly Trosinenko via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 04:41:00 PDT 2025


================
@@ -207,18 +216,38 @@ class ExegesisAArch64Target : public ExegesisTarget {
 
     if (isPointerAuth(Opcode)) {
 #if defined(__aarch64__) && defined(__linux__)
+      // For some systems with existing PAC keys set, it is better to
+      // check the existing state of the key before setting it.
+      // For systems without PAC, this is a No-op but with PAC, it is
+      // better to check the existing key state and then disable/enable them
+      // to avoid runtime crashes owing to unsupported prctl opcodes or if the
+      // CPU implements FEAT_PAuth with FEAT_FPAC (in which case this method
+      // would silently return.).
+      // Hence the guard for switching.
+      errno = 0;
+      unsigned long PacKeys = prctl_wrapper(PR_PAC_GET_ENABLED_KEYS);
+      if (static_cast<long> PacKeys < 0 || errno == EINVAL)
----------------
atrosinenko wrote:

A simple `long` type could probably be used here, eliminating `static_cast<long>` here and below.

https://github.com/llvm/llvm-project/pull/138643


More information about the llvm-commits mailing list