From d4e7b000b2ebe7db2e2e1f3d0f5d37793e6d1c59 Mon Sep 17 00:00:00 2001 From: Pablo Barrio Date: Tue, 10 Mar 2020 15:05:49 +0000 Subject: [PATCH] [AArch64] Allow PAC mnemonics in the HINT space with PAC disabled Summary: It is important to emit HINT instructions instead of PAC ones when PAC is disabled. This allows compatibility with other assemblers (e.g. GAS). This was implemented in commit da33762de853. Still, developers of assembly code will want to write code that is compatible with both pre- and post-PAC CPUs. They could use HINT mnemonics, but the new mnemonics are a lot more readable (e.g. paciaz instead of hint #24), and they will result in the same encodings. So, while LLVM should not *emit* the new mnemonics when PAC is disabled, this patch will at least make LLVM *accept* assembly code that uses them. Reviewers: danielkiss, chill, olista01, LukeCheeseman, simon_tatham Subscribers: kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78372 --- llvm/lib/Target/AArch64/AArch64InstrInfo.td | 20 ++++++++++++- llvm/test/MC/AArch64/armv8.3a-signed-pointer.s | 41 +++++++++----------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td index 91af6c7..913e23c 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td +++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td @@ -915,10 +915,28 @@ let Uses = [LR], Defs = [LR], CRm = 0b0000 in { def XPACLRI : SystemNoOperands<0b111, "hint\t#7">; } +// In order to be able to write readable assembly, LLVM should accept assembly +// inputs that use pointer authentication mnemonics, even with PA disabled. +// However, in order to be compatible with other assemblers (e.g. GAS), LLVM +// should not emit these mnemonics unless PA is enabled. +def : InstAlias<"paciaz", (PACIAZ), 0>; +def : InstAlias<"pacibz", (PACIBZ), 0>; +def : InstAlias<"autiaz", (AUTIAZ), 0>; +def : InstAlias<"autibz", (AUTIBZ), 0>; +def : InstAlias<"paciasp", (PACIASP), 0>; +def : InstAlias<"pacibsp", (PACIBSP), 0>; +def : InstAlias<"autiasp", (AUTIASP), 0>; +def : InstAlias<"autibsp", (AUTIBSP), 0>; +def : InstAlias<"pacia1716", (PACIA1716), 0>; +def : InstAlias<"pacib1716", (PACIB1716), 0>; +def : InstAlias<"autia1716", (AUTIA1716), 0>; +def : InstAlias<"autib1716", (AUTIB1716), 0>; +def : InstAlias<"xpaclri", (XPACLRI), 0>; + // These pointer authentication instructions require armv8.3a let Predicates = [HasPA] in { - // When compiling with PA, there is a better mnemonic for these instructions. + // When PA is enabled, a better mnemonic should be emitted. def : InstAlias<"paciaz", (PACIAZ), 1>; def : InstAlias<"pacibz", (PACIBZ), 1>; def : InstAlias<"autiaz", (AUTIAZ), 1>; diff --git a/llvm/test/MC/AArch64/armv8.3a-signed-pointer.s b/llvm/test/MC/AArch64/armv8.3a-signed-pointer.s index b804889..dad4bc6 100644 --- a/llvm/test/MC/AArch64/armv8.3a-signed-pointer.s +++ b/llvm/test/MC/AArch64/armv8.3a-signed-pointer.s @@ -2,7 +2,7 @@ // RUN: FileCheck --check-prefixes=CHECK,ALL %s // RUN: not llvm-mc -triple aarch64-none-linux-gnu -show-encoding %s -o - > %t.1 2>%t.2 -// RUN: FileCheck --check-prefixes=ALL %s < %t.1 +// RUN: FileCheck --check-prefixes=NO83,ALL %s < %t.1 // RUN: FileCheck --check-prefix=CHECK-REQ %s < %t.2 // ALL: .text @@ -98,56 +98,43 @@ // ALL-EMPTY: paciasp // CHECK-NEXT: paciasp // encoding: [0x3f,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: paciasp +// NO83-NEXT: hint #25 // encoding: [0x3f,0x23,0x03,0xd5] autiasp // CHECK-NEXT: autiasp // encoding: [0xbf,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autiasp +// NO83-NEXT: hint #29 // encoding: [0xbf,0x23,0x03,0xd5] paciaz // CHECK-NEXT: paciaz // encoding: [0x1f,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: paciaz +// NO83-NEXT: hint #24 // encoding: [0x1f,0x23,0x03,0xd5] autiaz // CHECK-NEXT: autiaz // encoding: [0x9f,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autiaz +// NO83-NEXT: hint #28 // encoding: [0x9f,0x23,0x03,0xd5] pacia1716 // CHECK-NEXT: pacia1716 // encoding: [0x1f,0x21,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: pacia1716 +// NO83-NEXT: hint #8 // encoding: [0x1f,0x21,0x03,0xd5] autia1716 // CHECK-NEXT: autia1716 // encoding: [0x9f,0x21,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autia1716 +// NO83-NEXT: hint #12 // encoding: [0x9f,0x21,0x03,0xd5] pacibsp // CHECK-NEXT: pacibsp // encoding: [0x7f,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: pacibsp +// NO83-NEXT: hint #27 // encoding: [0x7f,0x23,0x03,0xd5] autibsp // CHECK-NEXT: autibsp // encoding: [0xff,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autibsp +// NO83-NEXT: hint #31 // encoding: [0xff,0x23,0x03,0xd5] pacibz // CHECK-NEXT: pacibz // encoding: [0x5f,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: pacibz +// NO83-NEXT: hint #26 // encoding: [0x5f,0x23,0x03,0xd5] autibz // CHECK-NEXT: autibz // encoding: [0xdf,0x23,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autibz +// NO83-NEXT: hint #30 // encoding: [0xdf,0x23,0x03,0xd5] pacib1716 // CHECK-NEXT: pacib1716 // encoding: [0x5f,0x21,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: pacib1716 +// NO83-NEXT: hint #10 // encoding: [0x5f,0x21,0x03,0xd5] autib1716 // CHECK-NEXT: autib1716 // encoding: [0xdf,0x21,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: autib1716 +// NO83-NEXT: hint #14 // encoding: [0xdf,0x21,0x03,0xd5] xpaclri // CHECK-NEXT: xpaclri // encoding: [0xff,0x20,0x03,0xd5] -// CHECK-REQ: error: instruction requires: pa -// CHECK-REQ-NEXT: xpaclri +// NO83-NEXT: hint #7 // encoding: [0xff,0x20,0x03,0xd5] // ALL-EMPTY: pacia x0, x1 -- 2.7.4