|
9 | 9 | #include "AArch64.h"
|
10 | 10 | #include "AArch64RegisterInfo.h"
|
11 | 11 |
|
| 12 | +#if defined(__aarch64__) && defined(__linux__) |
| 13 | +#include <linux/prctl.h> // For PR_PAC_* constants |
| 14 | +#include <sys/prctl.h> |
| 15 | +#ifndef PR_PAC_SET_ENABLED_KEYS |
| 16 | +#define PR_PAC_SET_ENABLED_KEYS 60 |
| 17 | +#endif |
| 18 | +#ifndef PR_PAC_GET_ENABLED_KEYS |
| 19 | +#define PR_PAC_GET_ENABLED_KEYS 61 |
| 20 | +#endif |
| 21 | +#endif |
| 22 | + |
12 | 23 | #define GET_AVAILABLE_OPCODE_CHECKER
|
13 | 24 | #include "AArch64GenInstrInfo.inc"
|
14 | 25 |
|
15 | 26 | namespace llvm {
|
16 | 27 | namespace exegesis {
|
17 | 28 |
|
| 29 | +bool isPointerAuth(unsigned Opcode) { |
| 30 | + switch (Opcode) { |
| 31 | + default: |
| 32 | + return false; |
| 33 | + |
| 34 | + // FIXME: Pointer Authentication instructions. |
| 35 | + // We would like to measure these instructions, but they can behave |
| 36 | + // differently on different platforms, and maybe the snippets need to look |
| 37 | + // different for these instructions, |
| 38 | + // Platform-specific handling: On Linux, we disable authentication, may |
| 39 | + // interfere with measurements. On non-Linux platforms, disable opcodes for |
| 40 | + // now. |
| 41 | + case AArch64::AUTDA: |
| 42 | + case AArch64::AUTDB: |
| 43 | + case AArch64::AUTDZA: |
| 44 | + case AArch64::AUTDZB: |
| 45 | + case AArch64::AUTIA: |
| 46 | + case AArch64::AUTIA1716: |
| 47 | + case AArch64::AUTIASP: |
| 48 | + case AArch64::AUTIAZ: |
| 49 | + case AArch64::AUTIB: |
| 50 | + case AArch64::AUTIB1716: |
| 51 | + case AArch64::AUTIBSP: |
| 52 | + case AArch64::AUTIBZ: |
| 53 | + case AArch64::AUTIZA: |
| 54 | + case AArch64::AUTIZB: |
| 55 | + return true; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +bool isLoadTagMultiple(unsigned Opcode) { |
| 60 | + switch (Opcode) { |
| 61 | + default: |
| 62 | + return false; |
| 63 | + |
| 64 | + // Load tag multiple instruction |
| 65 | + case AArch64::LDGM: |
| 66 | + return true; |
| 67 | + } |
| 68 | +} |
| 69 | + |
18 | 70 | static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) {
|
19 | 71 | switch (RegBitWidth) {
|
20 | 72 | case 32:
|
@@ -134,6 +186,35 @@ class ExegesisAArch64Target : public ExegesisTarget {
|
134 | 186 | // Function return is a pseudo-instruction that needs to be expanded
|
135 | 187 | PM.add(createAArch64ExpandPseudoPass());
|
136 | 188 | }
|
| 189 | + |
| 190 | + const char *getIgnoredOpcodeReasonOrNull(const LLVMState &State, |
| 191 | + unsigned Opcode) const override { |
| 192 | + if (const char *Reason = |
| 193 | + ExegesisTarget::getIgnoredOpcodeReasonOrNull(State, Opcode)) |
| 194 | + return Reason; |
| 195 | + |
| 196 | + if (isPointerAuth(Opcode)) { |
| 197 | +#if defined(__aarch64__) && defined(__linux__) |
| 198 | + // Disable all PAC keys. Note that while we expect the measurements to |
| 199 | + // be the same with PAC keys disabled, they could potentially be lower |
| 200 | + // since authentication checks are bypassed. |
| 201 | + if (prctl(PR_PAC_SET_ENABLED_KEYS, |
| 202 | + PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY | |
| 203 | + PR_PAC_APDBKEY, // all keys |
| 204 | + 0, // disable all |
| 205 | + 0, 0) < 0) { |
| 206 | + return "Failed to disable PAC keys"; |
| 207 | + } |
| 208 | +#else |
| 209 | + return "Unsupported opcode: isPointerAuth"; |
| 210 | +#endif |
| 211 | + } |
| 212 | + |
| 213 | + if (isLoadTagMultiple(Opcode)) |
| 214 | + return "Unsupported opcode: load tag multiple"; |
| 215 | + |
| 216 | + return nullptr; |
| 217 | + } |
137 | 218 | };
|
138 | 219 |
|
139 | 220 | } // namespace
|
|
0 commit comments