Skip to content

Commit da33762

Browse files
committed
[AArch64] Emit HINT instead of PAC insns in Armv8.2-A or below
Summary: The Pointer Authentication Extension (PAC) was added in Armv8.3-A. Some instructions are implemented in the HINT space to allow compiling code common to CPUs regardless of whether they feature PAC or not, and still benefit from PAC protection in the PAC-enabled CPUs. The 8.3-specific mnemonics were currently enabled in any architecture, and LLVM was emitting them in assembly files when PAC code generation was enabled. This was ok for compilations where both LLVM codegen and the integrated assembler were used. However, the LLVM codegen was not compatible with other assemblers (e.g. GAS). Given the fact that the approach from these assemblers (i.e. to disallow Armv8.3-A mnemonics if compiling for Armv8.2-A or lower) is entirely reasonable, this patch makes LLVM to emit HINT when building for Armv8.2-A and below, instead of PACIASP, AUTIASP and friends. Then, LLVM assembly should be compatible with other assemblers. Reviewers: samparker, chill, LukeCheeseman Subscribers: kristof.beyls, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71658
1 parent 8e8ccf4 commit da33762

13 files changed

+247
-130
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

+33-15
Original file line numberDiff line numberDiff line change
@@ -815,38 +815,56 @@ let Predicates = [HasComplxNum, HasNEON] in {
815815

816816
// v8.3a Pointer Authentication
817817
// These instructions inhabit part of the hint space and so can be used for
818-
// armv8 targets
818+
// armv8 targets. Keeping the old HINT mnemonic when compiling without PA is
819+
// important for compatibility with other assemblers (e.g. GAS) when building
820+
// software compatible with both CPUs that do or don't implement PA.
819821
let Uses = [LR], Defs = [LR] in {
820-
def PACIAZ : SystemNoOperands<0b000, "paciaz">;
821-
def PACIBZ : SystemNoOperands<0b010, "pacibz">;
822+
def PACIAZ : SystemNoOperands<0b000, "hint #24">;
823+
def PACIBZ : SystemNoOperands<0b010, "hint #26">;
822824
let isAuthenticated = 1 in {
823-
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
824-
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
825+
def AUTIAZ : SystemNoOperands<0b100, "hint #28">;
826+
def AUTIBZ : SystemNoOperands<0b110, "hint #30">;
825827
}
826828
}
827829
let Uses = [LR, SP], Defs = [LR] in {
828-
def PACIASP : SystemNoOperands<0b001, "paciasp">;
829-
def PACIBSP : SystemNoOperands<0b011, "pacibsp">;
830+
def PACIASP : SystemNoOperands<0b001, "hint #25">;
831+
def PACIBSP : SystemNoOperands<0b011, "hint #27">;
830832
let isAuthenticated = 1 in {
831-
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
832-
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
833+
def AUTIASP : SystemNoOperands<0b101, "hint #29">;
834+
def AUTIBSP : SystemNoOperands<0b111, "hint #31">;
833835
}
834836
}
835837
let Uses = [X16, X17], Defs = [X17], CRm = 0b0001 in {
836-
def PACIA1716 : SystemNoOperands<0b000, "pacia1716">;
837-
def PACIB1716 : SystemNoOperands<0b010, "pacib1716">;
838+
def PACIA1716 : SystemNoOperands<0b000, "hint #8">;
839+
def PACIB1716 : SystemNoOperands<0b010, "hint #10">;
838840
let isAuthenticated = 1 in {
839-
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
840-
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
841+
def AUTIA1716 : SystemNoOperands<0b100, "hint #12">;
842+
def AUTIB1716 : SystemNoOperands<0b110, "hint #14">;
841843
}
842844
}
843845

844846
let Uses = [LR], Defs = [LR], CRm = 0b0000 in {
845-
def XPACLRI : SystemNoOperands<0b111, "xpaclri">;
847+
def XPACLRI : SystemNoOperands<0b111, "hint #7">;
846848
}
847849

848-
// These pointer authentication isntructions require armv8.3a
850+
// These pointer authentication instructions require armv8.3a
849851
let Predicates = [HasPA] in {
852+
853+
// When compiling with PA, there is a better mnemonic for these instructions.
854+
def : InstAlias<"paciaz", (PACIAZ), 1>;
855+
def : InstAlias<"pacibz", (PACIBZ), 1>;
856+
def : InstAlias<"autiaz", (AUTIAZ), 1>;
857+
def : InstAlias<"autibz", (AUTIBZ), 1>;
858+
def : InstAlias<"paciasp", (PACIASP), 1>;
859+
def : InstAlias<"pacibsp", (PACIBSP), 1>;
860+
def : InstAlias<"autiasp", (AUTIASP), 1>;
861+
def : InstAlias<"autibsp", (AUTIBSP), 1>;
862+
def : InstAlias<"pacia1716", (PACIA1716), 1>;
863+
def : InstAlias<"pacib1716", (PACIB1716), 1>;
864+
def : InstAlias<"autia1716", (AUTIA1716), 1>;
865+
def : InstAlias<"autib1716", (AUTIB1716), 1>;
866+
def : InstAlias<"xpaclri", (XPACLRI), 1>;
867+
850868
multiclass SignAuth<bits<3> prefix, bits<3> prefix_z, string asm> {
851869
def IA : SignAuthOneData<prefix, 0b00, !strconcat(asm, "ia")>;
852870
def IB : SignAuthOneData<prefix, 0b01, !strconcat(asm, "ib")>;

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-cfi.ll

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
2-
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s
2+
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s --check-prefixes CHECK,V8A
3+
; RUN-V83A: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
4+
; RUN-V83A: aarch64-arm-none-eabi -mattr=+v8.3a %s -o - > %t
5+
; RUN-V83A: FileCheck --check-prefixes CHECK,V83A < %t %s
36

47
; Function a's outlining candidate contains a sp modifying add without a
58
; corresponsing sub, so we shouldn't outline it.
69
define void @a() "sign-return-address"="all" "sign-return-address-key"="b_key" {
7-
; CHECK-LABEL: a: // @a
8-
; CHECK: // %bb.0:
9-
; CHECK-NEXT: .cfi_b_key_frame
10-
; CHECK-NEXT: pacibsp
11-
; CHECK-NEXT: .cfi_negate_ra_state
10+
; CHECK-LABEL: a: // @a
11+
; CHECK: // %bb.0:
12+
; CHECK-NEXT: .cfi_b_key_frame
13+
; V8A-NEXT: hint #27
14+
; V83A-NEXT: pacibsp
15+
; V8A-NEXT, V83A-NEXT: .cfi_negate_ra_state
1216
%1 = alloca i32, align 4
1317
%2 = alloca i32, align 4
1418
%3 = alloca i32, align 4
@@ -22,15 +26,17 @@ define void @a() "sign-return-address"="all" "sign-return-address-key"="b_key" {
2226
store i32 5, i32* %5, align 4
2327
store i32 6, i32* %6, align 4
2428
; CHECK-NOT: bl OUTLINED_FUNCTION_{{[0-9]+}}
25-
; CHECK: autibsp
26-
; CECK-NEXT: ret
29+
; V8A: hint #31
30+
; V83A: autibsp
31+
; CHECK-NEXT: ret
2732
ret void
2833
}
2934

3035
define void @b() "sign-return-address"="all" "sign-return-address-key"="b_key" nounwind {
3136
; CHECK-LABEL: b: // @b
3237
; CHECK-NEXT: // %bb.0:
33-
; CHECK-NEXT: pacibsp
38+
; V8A-NEXT: hint #27
39+
; V83A-NEXT: pacibsp
3440
%1 = alloca i32, align 4
3541
%2 = alloca i32, align 4
3642
%3 = alloca i32, align 4
@@ -44,15 +50,17 @@ define void @b() "sign-return-address"="all" "sign-return-address-key"="b_key" n
4450
store i32 5, i32* %5, align 4
4551
store i32 6, i32* %6, align 4
4652
; CHECK: bl [[OUTLINED_FUNC:OUTLINED_FUNCTION_[0-9]+]]
47-
; CHECK: autibsp
48-
; CHECK-NEXT: ret
53+
; V8A: hint #31
54+
; V83A: autibsp
55+
; V8A-NEXT, V83A-NEXT: ret
4956
ret void
5057
}
5158

5259
define void @c() "sign-return-address"="all" "sign-return-address-key"="b_key" nounwind {
5360
; CHECK-LABEL: c: // @c
5461
; CHECK-NEXT: // %bb.0:
55-
; CHECK-NEXT: pacibsp
62+
; V8A-NEXT: hint #27
63+
; V83A-NEXT: pacibsp
5664
%1 = alloca i32, align 4
5765
%2 = alloca i32, align 4
5866
%3 = alloca i32, align 4
@@ -66,15 +74,18 @@ define void @c() "sign-return-address"="all" "sign-return-address-key"="b_key" n
6674
store i32 5, i32* %5, align 4
6775
store i32 6, i32* %6, align 4
6876
; CHECK: bl [[OUTLINED_FUNC]]
69-
; CHECK: autibsp
70-
; CHECK-NEXT: ret
77+
; V8A: hint #31
78+
; V83A: autibsp
79+
; V8A-NEXT, V83A-NEXT: ret
7180
ret void
7281
}
7382

7483
; CHECK: [[OUTLINED_FUNC]]
7584
; CHECK: // %bb.0:
7685
; CHECK-NEXT: .cfi_b_key_frame
77-
; CHECK-NEXT: pacibsp
86+
; V8A-NEXT: hint #27
87+
; V83A-NEXT: pacibsp
7888
; CHECK-NEXT: .cfi_negate_ra_state
79-
; CHECK: autibsp
80-
; CHECK-NEXT: ret
89+
; V8A: hint #31
90+
; V83A: autibsp
91+
; V8A-NEXT, V83A-NEXT: ret

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-diff-scope-same-key.ll

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
2-
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s
2+
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s --check-prefixes CHECK,V8A
3+
; RUN-V83A: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
4+
; RUN-V83A: aarch64-arm-none-eabi -mattr=+v8.3a %s -o - > %t
5+
; RUN-V83A: FileCheck --check-prefixes CHECK,V83A < %t %s
36

47
define void @a() "sign-return-address"="all" {
58
; CHECK-LABEL: a: // @a
6-
; CHECK: paciasp
9+
; V8A: hint #25
10+
; V83A: paciasp
711
; CHECK-NEXT: .cfi_negate_ra_state
812
%1 = alloca i32, align 4
913
%2 = alloca i32, align 4
@@ -17,14 +21,16 @@ define void @a() "sign-return-address"="all" {
1721
store i32 4, i32* %4, align 4
1822
store i32 5, i32* %5, align 4
1923
store i32 6, i32* %6, align 4
20-
; CHECK: autiasp
24+
; V8A: hint #29
25+
; V83A: autiasp
2126
ret void
2227
; CHECK: .cfi_endproc
2328
}
2429

2530
define void @b() "sign-return-address"="non-leaf" {
26-
; CHECK-LABEL: b: // @b
27-
; CHECK-NOT: paciasp
31+
; CHECK-LABE: b: // @b
32+
; V8A-NOT: hint #25
33+
; V83A-NOT: paciasp
2834
; CHECK-NOT: .cfi_negate_ra_state
2935
%1 = alloca i32, align 4
3036
%2 = alloca i32, align 4
@@ -38,15 +44,17 @@ define void @b() "sign-return-address"="non-leaf" {
3844
store i32 4, i32* %4, align 4
3945
store i32 5, i32* %5, align 4
4046
store i32 6, i32* %6, align 4
41-
; CHECK-NOT: autiasp
47+
; V8A-NOT: hint #29
48+
; V83A-NOT: autiasp
4249
ret void
4350
; CHECK: .cfi_endproc
4451
}
4552

4653
define void @c() "sign-return-address"="all" {
47-
; CHECK-LABEL: c: // @c
48-
; CHECK: paciasp
49-
; CHECK-NEXT: .cfi_negate_ra_state
54+
; CHECK-LABEL: c: // @c
55+
; V8A: hint #25
56+
; V83A: paciasp
57+
; V8A-NEXT, V83A-NEXT: .cfi_negate_ra_state
5058
%1 = alloca i32, align 4
5159
%2 = alloca i32, align 4
5260
%3 = alloca i32, align 4
@@ -59,7 +67,8 @@ define void @c() "sign-return-address"="all" {
5967
store i32 4, i32* %4, align 4
6068
store i32 5, i32* %5, align 4
6169
store i32 6, i32* %6, align 4
62-
; CHECK: autiasp
70+
; V8A: hint #29
71+
; V83A: autiasp
6372
ret void
6473
; CHECK: .cfi_endproc
6574
}

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-non-leaf.ll

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
2-
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s
2+
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s --check-prefixes CHECK,V8A
3+
; RUN-V83A: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
4+
; RUN-V83A: aarch64-arm-none-eabi -mattr=+v8.3a %s -o - > %t
5+
; RUN-V83A: FileCheck --check-prefixes CHECK,V83A < %t %s
36

47
define i64 @a(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"="b_key" {
58
; CHECK-LABEL: a: // @a
69
; CHECK: .cfi_b_key_frame
7-
; CHECK-NEXT: pacibsp
10+
; V8A-NEXT: hint #27
11+
; V83A-NEXT: pacibsp
812
; CHECK-NEXT: .cfi_negate_ra_state
913
%1 = alloca i32, align 4
1014
%2 = alloca i32, align 4
@@ -25,7 +29,8 @@ define i64 @a(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"
2529
define i64 @b(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"="b_key" {
2630
; CHECK-LABEL: b: // @b
2731
; CHECK: .cfi_b_key_frame
28-
; CHECK-NEXT: pacibsp
32+
; V8A-NEXT: hint #27
33+
; V83A-NEXT: pacibsp
2934
; CHECK-NEXT: .cfi_negate_ra_state
3035
%1 = alloca i32, align 4
3136
%2 = alloca i32, align 4
@@ -46,7 +51,8 @@ define i64 @b(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"
4651
define i64 @c(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"="b_key" {
4752
; CHECK-LABEL: c: // @c
4853
; CHECK: .cfi_b_key_frame
49-
; CHECK-NEXT: pacibsp
54+
; V8A-NEXT: hint #27
55+
; V83A-NEXT: pacibsp
5056
; CHECK-NEXT: .cfi_negate_ra_state
5157
%1 = alloca i32, align 4
5258
%2 = alloca i32, align 4
@@ -68,5 +74,6 @@ define i64 @c(i64 %x) "sign-return-address"="non-leaf" "sign-return-address-key"
6874
; CHECK-LABEL: OUTLINED_FUNCTION_0:
6975
; CHECK-NOT: .cfi_b_key_frame
7076
; CHECK-NOT: paci{{[a,b]}}sp
77+
; CHECK-NOT: hint #2{{[5,7]}}
7178
; CHECK-NOT: .cfi_negate_ra_state
7279
; CHECK-NOT: auti{{[a,b]}}sp

llvm/test/CodeGen/AArch64/machine-outliner-retaddr-sign-same-scope-diff-key.ll

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
; RUN: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
2-
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s
2+
; RUN: aarch64-arm-none-eabi %s -o - | FileCheck %s --check-prefixes CHECK,V8A
3+
; RUN-V83A: llc -verify-machineinstrs -enable-machine-outliner -mtriple \
4+
; RUN-V83A: aarch64-arm-none-eabi -mattr=+v8.3a %s -o - > %t
5+
; RUN-V83A: FileCheck --check-prefixes CHECK,V83A < %t %s
36

47
define void @a() "sign-return-address"="all" {
58
; CHECK-LABEL: a: // @a
6-
; CHECK: paciasp
9+
; V8A: hint #25
10+
; V83A: paciasp
711
; CHECK-NEXT: .cfi_negate_ra_state
812
%1 = alloca i32, align 4
913
%2 = alloca i32, align 4
@@ -17,15 +21,17 @@ define void @a() "sign-return-address"="all" {
1721
store i32 4, i32* %4, align 4
1822
store i32 5, i32* %5, align 4
1923
store i32 6, i32* %6, align 4
20-
; CHECK: autiasp
24+
; V8A: hint #29
25+
; V83A: autiasp
2126
ret void
2227
; CHECK: .cfi_endproc
2328
}
2429

2530
define void @b() "sign-return-address"="all" "sign-return-address-key"="b_key" {
2631
; CHECK-LABEL: b: // @b
2732
; CHECK: .cfi_b_key_frame
28-
; CHECK-NEXT: pacibsp
33+
; V8A-NEXT: hint #27
34+
; V83A-NEXT: pacibsp
2935
; CHECK-NEXT: .cfi_negate_ra_state
3036
%1 = alloca i32, align 4
3137
%2 = alloca i32, align 4
@@ -39,14 +45,16 @@ define void @b() "sign-return-address"="all" "sign-return-address-key"="b_key" {
3945
store i32 4, i32* %4, align 4
4046
store i32 5, i32* %5, align 4
4147
store i32 6, i32* %6, align 4
42-
; CHECK-NOT: autiasp
48+
; V8A-NOT: hint #29
49+
; V83A-NOT: autiasp
4350
ret void
4451
; CHECK: .cfi_endproc
4552
}
4653

4754
define void @c() "sign-return-address"="all" {
4855
; CHECK-LABEL: c: // @c
49-
; CHECK: paciasp
56+
; V8A: hint #25
57+
; V83A: paciasp
5058
; CHECK-NEXT: .cfi_negate_ra_state
5159
%1 = alloca i32, align 4
5260
%2 = alloca i32, align 4
@@ -60,7 +68,8 @@ define void @c() "sign-return-address"="all" {
6068
store i32 4, i32* %4, align 4
6169
store i32 5, i32* %5, align 4
6270
store i32 6, i32* %6, align 4
63-
; CHECK: autiasp
71+
; V8A: hint #29
72+
; V83A: autiasp
6473
ret void
6574
; CHECK: .cfi_endproc
6675
}

0 commit comments

Comments
 (0)