Skip to content

Commit cff5a43

Browse files
authored
[AArch64][PAC][GISel] Add missing clobbering info to LOADgotAUTH (#157433)
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 machine passes to take them into account. This patch fixes miscompilation possibility observed when compiling with GlobalISel enabled or at -O0 optimization level.
1 parent 1d8568c commit cff5a43

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,10 +2914,10 @@ 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 IsGOTSigned = MF.getInfo<AArch64FunctionInfo>()->hasELFSignedGOT();
2918+
I.setDesc(TII.get(IsGOTSigned ? AArch64::LOADgotAUTH : AArch64::LOADgot));
29202919
I.getOperand(1).setTargetFlags(OpFlags);
2920+
I.addImplicitDefUseOperands(MF);
29212921
} else if (TM.getCodeModel() == CodeModel::Large &&
29222922
!TM.isPositionIndependent()) {
29232923
// 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)