Skip to content

Commit 3c4236f

Browse files
committed
Transform LOADgot in addition to LOADgotAUTH
1 parent 3af1146 commit 3c4236f

File tree

3 files changed

+113
-23
lines changed

3 files changed

+113
-23
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,8 @@ AArch64TargetLowering::tryRewritingPAC(MachineInstr &MI,
32183218
return BB;
32193219

32203220
unsigned NewOpcode;
3221-
if (AddrDefInstr->getOpcode() == AArch64::LOADgotAUTH)
3221+
if (AddrDefInstr->getOpcode() == AArch64::LOADgot ||
3222+
AddrDefInstr->getOpcode() == AArch64::LOADgotAUTH)
32223223
NewOpcode = AArch64::LOADgotPAC;
32233224
else if (AddrDefInstr->getOpcode() == AArch64::MOVaddr)
32243225
NewOpcode = AArch64::MOVaddrPAC;

llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-constant-in-code.ll

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ define void @store_signed_const_got(ptr %dest) {
138138
; ISEL-MIR-ELF-LABEL: name: store_signed_const_got
139139
; ISEL-MIR-ELF: body:
140140
; ISEL-MIR-ELF: %0:gpr64common = COPY $x0
141-
; ISEL-MIR-ELF-NEXT: %7:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got
141+
; ISEL-MIR-ELF-NEXT: %7:gpr64common = LOADgot target-flags(aarch64-got) @const_table_got
142142
; ISEL-MIR-ELF-NEXT: %6:gpr64common = ADDXri %7, 8, 0
143143
; ISEL-MIR-ELF-NEXT: %2:gpr64noip = MOVKXi %0, 1234, 48
144144
; ISEL-MIR-ELF-NEXT: %12:gpr64noip = COPY %0
@@ -150,16 +150,8 @@ define void @store_signed_const_got(ptr %dest) {
150150
;
151151
; ISEL-ASM-ELF-LABEL: store_signed_const_got:
152152
; ISEL-ASM-ELF-NEXT: .cfi_startproc
153-
; ISEL-ASM-ELF-NEXT: adrp x17, :got_auth:const_table_got
154-
; ISEL-ASM-ELF-NEXT: add x17, x17, :got_auth_lo12:const_table_got
155-
; ISEL-ASM-ELF-NEXT: ldr x16, [x17]
156-
; ISEL-ASM-ELF-NEXT: autda x16, x17
157-
; ISEL-ASM-ELF-NEXT: mov x17, x16
158-
; ISEL-ASM-ELF-NEXT: xpacd x17
159-
; ISEL-ASM-ELF-NEXT: cmp x16, x17
160-
; ISEL-ASM-ELF-NEXT: b.eq .Lauth_success_0
161-
; ISEL-ASM-ELF-NEXT: brk #0xc472
162-
; ISEL-ASM-ELF-NEXT: .Lauth_success_0:
153+
; ISEL-ASM-ELF-NEXT: adrp x16, :got:const_table_got
154+
; ISEL-ASM-ELF-NEXT: ldr x16, [x16, :got_lo12:const_table_got]
163155
; ISEL-ASM-ELF-NEXT: add x16, x16, #8
164156
; ISEL-ASM-ELF-NEXT: mov x17, x0
165157
; ISEL-ASM-ELF-NEXT: movk x17, #1234, lsl #48
@@ -205,6 +197,60 @@ define void @store_signed_arg(ptr %dest, ptr %p) {
205197
ret void
206198
}
207199

200+
;--- finalize-isel-elf-got.ll
201+
202+
; RUN: llc < finalize-isel-elf-got.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=1 \
203+
; RUN: -verify-machineinstrs -global-isel-abort=1 -stop-after=finalize-isel | \
204+
; RUN: FileCheck --check-prefixes=ISEL-ELF-GOT-MIR %s
205+
; RUN: llc < finalize-isel-elf-got.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=1 \
206+
; RUN: -verify-machineinstrs -global-isel-abort=1 -asm-verbose=0 | \
207+
; RUN: FileCheck --check-prefixes=ISEL-ELF-GOT-ASM %s
208+
209+
@const_table_got = constant [3 x ptr] [ptr null, ptr null, ptr null]
210+
211+
; Similar to finalize-isel.ll, but tests conversion of LOADgotAUTH to LOADgotPAC.
212+
; This requires module-level attribute, thus a separate sub-file.
213+
214+
define void @store_signed_const_got(ptr %dest) {
215+
; ISEL-ELF-GOT-MIR-LABEL: name: store_signed_const_got
216+
; ISEL-ELF-GOT-MIR: body:
217+
; ISEL-ELF-GOT-MIR: %0:gpr64common = COPY $x0
218+
; ISEL-ELF-GOT-MIR-NEXT: %7:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got
219+
; ISEL-ELF-GOT-MIR-NEXT: %6:gpr64common = ADDXri %7, 8, 0
220+
; ISEL-ELF-GOT-MIR-NEXT: %2:gpr64noip = MOVKXi %0, 1234, 48
221+
; ISEL-ELF-GOT-MIR-NEXT: %12:gpr64noip = COPY %0
222+
; ISEL-ELF-GOT-MIR-NEXT: LOADgotPAC target-flags(aarch64-got) @const_table_got + 8, 2, %12, 1234, implicit-def $x16, implicit-def $x17, implicit-def $nzcv
223+
; ISEL-ELF-GOT-MIR-NEXT: %4:gpr64 = COPY $x16
224+
; ISEL-ELF-GOT-MIR-NEXT: %10:gpr64 = COPY %4
225+
; ISEL-ELF-GOT-MIR-NEXT: STRXui %10, %0, 0 :: (store (p0) into %ir.dest)
226+
; ISEL-ELF-GOT-MIR-NEXT: RET_ReallyLR
227+
;
228+
; ISEL-ELF-GOT-ASM-LABEL: store_signed_const_got:
229+
; ISEL-ELF-GOT-ASM-NEXT: .cfi_startproc
230+
; ISEL-ELF-GOT-ASM-NEXT: adrp x17, :got_auth:const_table_got
231+
; ISEL-ELF-GOT-ASM-NEXT: add x17, x17, :got_auth_lo12:const_table_got
232+
; ISEL-ELF-GOT-ASM-NEXT: ldr x16, [x17]
233+
; ISEL-ELF-GOT-ASM-NEXT: autda x16, x17
234+
; ISEL-ELF-GOT-ASM-NEXT: mov x17, x16
235+
; ISEL-ELF-GOT-ASM-NEXT: xpacd x17
236+
; ISEL-ELF-GOT-ASM-NEXT: cmp x16, x17
237+
; ISEL-ELF-GOT-ASM-NEXT: b.eq .Lauth_success_0
238+
; ISEL-ELF-GOT-ASM-NEXT: brk #0xc472
239+
; ISEL-ELF-GOT-ASM-NEXT: .Lauth_success_0:
240+
; ISEL-ELF-GOT-ASM-NEXT: add x16, x16, #8
241+
; ISEL-ELF-GOT-ASM-NEXT: mov x17, x0
242+
; ISEL-ELF-GOT-ASM-NEXT: movk x17, #1234, lsl #48
243+
; ISEL-ELF-GOT-ASM-NEXT: pacda x16, x17
244+
; ISEL-ELF-GOT-ASM-NEXT: str x16, [x0]
245+
; ISEL-ELF-GOT-ASM-NEXT: ret
246+
%dest.i = ptrtoint ptr %dest to i64
247+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
248+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_got, i32 0, i32 1) to i64), i32 2, i64 %discr)
249+
%signed.ptr = inttoptr i64 %signed.i to ptr
250+
store ptr %signed.ptr, ptr %dest
251+
ret void
252+
}
253+
208254
!llvm.module.flags = !{!0}
209255
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
210256

llvm/test/CodeGen/AArch64/ptrauth-constant-in-code.ll

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ define void @store_signed_const_got(ptr %dest) {
125125
; ISEL-MIR-ELF: body:
126126
; ISEL-MIR-ELF: %0:gpr64common = COPY $x0
127127
; ISEL-MIR-ELF-NEXT: %1:gpr64noip = MOVKXi %0, 1234, 48
128-
; ISEL-MIR-ELF-NEXT: %2:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got, implicit-def dead $x16, implicit-def dead $x17, implicit-def dead $nzcv
128+
; ISEL-MIR-ELF-NEXT: %2:gpr64common = LOADgot target-flags(aarch64-got) @const_table_got
129129
; ISEL-MIR-ELF-NEXT: %3:gpr64common = ADDXri killed %2, 8, 0
130130
; ISEL-MIR-ELF-NEXT: %5:gpr64noip = COPY %0
131131
; ISEL-MIR-ELF-NEXT: LOADgotPAC target-flags(aarch64-got) @const_table_got + 8, 2, %5, 1234, implicit-def $x16, implicit-def $x17, implicit-def $nzcv
@@ -135,16 +135,8 @@ define void @store_signed_const_got(ptr %dest) {
135135
;
136136
; ISEL-ASM-ELF-LABEL: store_signed_const_got:
137137
; ISEL-ASM-ELF-NEXT: .cfi_startproc
138-
; ISEL-ASM-ELF-NEXT: adrp x17, :got_auth:const_table_got
139-
; ISEL-ASM-ELF-NEXT: add x17, x17, :got_auth_lo12:const_table_got
140-
; ISEL-ASM-ELF-NEXT: ldr x16, [x17]
141-
; ISEL-ASM-ELF-NEXT: autda x16, x17
142-
; ISEL-ASM-ELF-NEXT: mov x17, x16
143-
; ISEL-ASM-ELF-NEXT: xpacd x17
144-
; ISEL-ASM-ELF-NEXT: cmp x16, x17
145-
; ISEL-ASM-ELF-NEXT: b.eq .Lauth_success_0
146-
; ISEL-ASM-ELF-NEXT: brk #0xc472
147-
; ISEL-ASM-ELF-NEXT: .Lauth_success_0:
138+
; ISEL-ASM-ELF-NEXT: adrp x16, :got:const_table_got
139+
; ISEL-ASM-ELF-NEXT: ldr x16, [x16, :got_lo12:const_table_got]
148140
; ISEL-ASM-ELF-NEXT: add x16, x16, #8
149141
; ISEL-ASM-ELF-NEXT: mov x17, x0
150142
; ISEL-ASM-ELF-NEXT: movk x17, #1234, lsl #48
@@ -189,6 +181,57 @@ define void @store_signed_arg(ptr %dest, ptr %p) {
189181
ret void
190182
}
191183

184+
;--- finalize-isel-elf-got.ll
185+
186+
; RUN: llc < finalize-isel-elf-got.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=0 \
187+
; RUN: -verify-machineinstrs -stop-after=finalize-isel | FileCheck --check-prefixes=ISEL-ELF-GOT-MIR %s
188+
; RUN: llc < finalize-isel-elf-got.ll -mtriple aarch64-elf -mattr=+pauth -global-isel=0 \
189+
; RUN: -verify-machineinstrs -asm-verbose=0 | FileCheck --check-prefixes=ISEL-ELF-GOT-ASM %s
190+
191+
@const_table_got = constant [3 x ptr] [ptr null, ptr null, ptr null]
192+
193+
; Similar to finalize-isel.ll, but tests conversion of LOADgotAUTH to LOADgotPAC.
194+
; This requires module-level attribute, thus a separate sub-file.
195+
196+
define void @store_signed_const_got(ptr %dest) {
197+
; ISEL-ELF-GOT-MIR-LABEL: name: store_signed_const_got
198+
; ISEL-ELF-GOT-MIR: body:
199+
; ISEL-ELF-GOT-MIR: %0:gpr64common = COPY $x0
200+
; ISEL-ELF-GOT-MIR-NEXT: %1:gpr64noip = MOVKXi %0, 1234, 48
201+
; ISEL-ELF-GOT-MIR-NEXT: %2:gpr64common = LOADgotAUTH target-flags(aarch64-got) @const_table_got, implicit-def dead $x16, implicit-def dead $x17, implicit-def dead $nzcv
202+
; ISEL-ELF-GOT-MIR-NEXT: %3:gpr64common = ADDXri killed %2, 8, 0
203+
; ISEL-ELF-GOT-MIR-NEXT: %5:gpr64noip = COPY %0
204+
; ISEL-ELF-GOT-MIR-NEXT: LOADgotPAC target-flags(aarch64-got) @const_table_got + 8, 2, %5, 1234, implicit-def $x16, implicit-def $x17, implicit-def $nzcv
205+
; ISEL-ELF-GOT-MIR-NEXT: %4:gpr64 = COPY $x16
206+
; ISEL-ELF-GOT-MIR-NEXT: STRXui killed %4, %0, 0 :: (store (s64) into %ir.dest)
207+
; ISEL-ELF-GOT-MIR-NEXT: RET_ReallyLR
208+
;
209+
; ISEL-ELF-GOT-ASM-LABEL: store_signed_const_got:
210+
; ISEL-ELF-GOT-ASM-NEXT: .cfi_startproc
211+
; ISEL-ELF-GOT-ASM-NEXT: adrp x17, :got_auth:const_table_got
212+
; ISEL-ELF-GOT-ASM-NEXT: add x17, x17, :got_auth_lo12:const_table_got
213+
; ISEL-ELF-GOT-ASM-NEXT: ldr x16, [x17]
214+
; ISEL-ELF-GOT-ASM-NEXT: autda x16, x17
215+
; ISEL-ELF-GOT-ASM-NEXT: mov x17, x16
216+
; ISEL-ELF-GOT-ASM-NEXT: xpacd x17
217+
; ISEL-ELF-GOT-ASM-NEXT: cmp x16, x17
218+
; ISEL-ELF-GOT-ASM-NEXT: b.eq .Lauth_success_0
219+
; ISEL-ELF-GOT-ASM-NEXT: brk #0xc472
220+
; ISEL-ELF-GOT-ASM-NEXT: .Lauth_success_0:
221+
; ISEL-ELF-GOT-ASM-NEXT: add x16, x16, #8
222+
; ISEL-ELF-GOT-ASM-NEXT: mov x17, x0
223+
; ISEL-ELF-GOT-ASM-NEXT: movk x17, #1234, lsl #48
224+
; ISEL-ELF-GOT-ASM-NEXT: pacda x16, x17
225+
; ISEL-ELF-GOT-ASM-NEXT: str x16, [x0]
226+
; ISEL-ELF-GOT-ASM-NEXT: ret
227+
%dest.i = ptrtoint ptr %dest to i64
228+
%discr = call i64 @llvm.ptrauth.blend(i64 %dest.i, i64 1234)
229+
%signed.i = call i64 @llvm.ptrauth.sign(i64 ptrtoint (ptr getelementptr ([2 x ptr], ptr @const_table_got, i32 0, i32 1) to i64), i32 2, i64 %discr)
230+
%signed.ptr = inttoptr i64 %signed.i to ptr
231+
store ptr %signed.ptr, ptr %dest
232+
ret void
233+
}
234+
192235
!llvm.module.flags = !{!0}
193236
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
194237

0 commit comments

Comments
 (0)