Skip to content

Commit 245a456

Browse files
committed
[AArch64][PAC][GISel] Add missing clobbering info to LOADgotAUTH
When LOADgotAUTH is selected by GlobalISel, the existing MachineInstr is updated in-place instead of constructing a fresh instance by calling MIB.buildInstr(). This way, implicit-def operands have to be added manually for register allocator to take them into account. This patch fixes miscompilation possibility observed when compiling with GlobalISel enabled or at -O0 optimization level.
1 parent 7731ecf commit 245a456

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,10 +2914,15 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
29142914
}
29152915

29162916
if (OpFlags & AArch64II::MO_GOT) {
2917-
I.setDesc(TII.get(MF.getInfo<AArch64FunctionInfo>()->hasELFSignedGOT()
2918-
? AArch64::LOADgotAUTH
2919-
: AArch64::LOADgot));
2917+
bool GOTIsSigned = MF.getInfo<AArch64FunctionInfo>()->hasELFSignedGOT();
2918+
I.setDesc(TII.get(GOTIsSigned ? AArch64::LOADgotAUTH : AArch64::LOADgot));
29202919
I.getOperand(1).setTargetFlags(OpFlags);
2920+
if (GOTIsSigned) {
2921+
MachineInstrBuilder MIB(MF, I);
2922+
MIB.addDef(AArch64::X16, RegState::Implicit);
2923+
MIB.addDef(AArch64::X17, RegState::Implicit);
2924+
MIB.addDef(AArch64::NZCV, RegState::Implicit);
2925+
}
29212926
} else if (TM.getCodeModel() == CodeModel::Large &&
29222927
!TM.isPositionIndependent()) {
29232928
// Materialize the global using movz/movk instructions.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
2+
# RUN: llc -O0 -mtriple=aarch64-linux-gnu -relocation-model=pic -run-pass=instruction-select -global-isel-abort=1 -verify-machineinstrs %s -o - | FileCheck %s
3+
4+
--- |
5+
@var_got = external global i8
6+
define ptr @loadgotauth_implicit_defs() { ret ptr null }
7+
8+
!llvm.module.flags = !{!0}
9+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}
10+
...
11+
12+
---
13+
name: loadgotauth_implicit_defs
14+
legalized: true
15+
regBankSelected: true
16+
body: |
17+
bb.0:
18+
; CHECK-LABEL: name: loadgotauth_implicit_defs
19+
; CHECK: [[LOADgotAUTH:%[0-9]+]]:gpr64common = LOADgotAUTH target-flags(aarch64-got) @var_got, implicit-def $x16, implicit-def $x17, implicit-def $nzcv
20+
; CHECK-NEXT: $x0 = COPY [[LOADgotAUTH]]
21+
%0:gpr(p0) = G_GLOBAL_VALUE @var_got
22+
$x0 = COPY %0(p0)
23+
...

0 commit comments

Comments
 (0)