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