Skip to content

Commit bffc609

Browse files
committed
Add error messages for emitting LDRA* pseudos without PAuth subtarget feature
1 parent 9ed8fc6 commit bffc609

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

llvm/lib/Target/AArch64/AArch64ExpandHardenedPseudos.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ bool AArch64ExpandHardenedPseudos::expandAuthLoad(MachineInstr &MI) {
338338

339339
LLVM_DEBUG(dbgs() << "Expanding: " << MI << "\n");
340340

341+
// LDRA and LDRApre preudos are emitted in AArch64DAGToDAGISel::tryAuthLoad
342+
// and AArch64InstructionSelector::selectAuthLoad with prior checks against
343+
// ptrauth subtarget feature
344+
assert(STI.hasPAuth());
345+
341346
bool IsPre = MI.getOpcode() == AArch64::LDRApre;
342347

343348
MachineOperand DstOp = MI.getOperand(0);

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,9 @@ bool AArch64DAGToDAGISel::tryAuthLoad(SDNode *N) {
17231723
return false;
17241724
}
17251725

1726+
if (!Subtarget->hasPAuth())
1727+
report_fatal_error("pac instructions require ptrauth target feature");
1728+
17261729
// We have 2 main isel alternatives:
17271730
// - LDRAA/LDRAB, writeback or indexed. Zero disc, small offsets, D key.
17281731
// - LDRA/LDRApre. Pointer needs to be in X16.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,6 +2856,9 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
28562856

28572857
case AArch64::G_LDRA:
28582858
case AArch64::G_LDRApre:
2859+
// TODO: implement a test case for this error
2860+
if (!STI.hasPAuth())
2861+
report_fatal_error("pac instructions require ptrauth target feature");
28592862
return selectAuthLoad(I, MRI);
28602863

28612864
case TargetOpcode::G_ZEXTLOAD:

llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-lowering-err.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,20 @@ define void @bar(ptr %foo) #0 {
8484
}
8585

8686
attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }
87+
88+
;--- tryAuthLoad.ll
89+
90+
; RUN: not --crash llc -mtriple aarch64-elf tryAuthLoad.ll 2>&1 | \
91+
; RUN: FileCheck tryAuthLoad.ll
92+
93+
; CHECK: LLVM ERROR: pac instructions require ptrauth target feature
94+
95+
define i64 @test(i64* %ptr) {
96+
%tmp0 = ptrtoint i64* %ptr to i64
97+
%tmp1 = call i64 @llvm.ptrauth.auth(i64 %tmp0, i32 2, i64 0)
98+
%tmp2 = inttoptr i64 %tmp1 to i64*
99+
%tmp3 = load i64, i64* %tmp2
100+
ret i64 %tmp3
101+
}
102+
103+
declare i64 @llvm.ptrauth.auth(i64, i32, i64)

0 commit comments

Comments
 (0)