Skip to content

Commit

Permalink
[AArch64] Allow PAC mnemonics in the HINT space with PAC disabled
Browse files Browse the repository at this point in the history
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 da33762.

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
  • Loading branch information
pbarrio committed Apr 24, 2020
1 parent 6121122 commit d4e7b00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
20 changes: 19 additions & 1 deletion llvm/lib/Target/AArch64/AArch64InstrInfo.td
Expand Up @@ -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>;
Expand Down
41 changes: 14 additions & 27 deletions llvm/test/MC/AArch64/armv8.3a-signed-pointer.s
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d4e7b00

Please sign in to comment.