Skip to content
6 changes: 6 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ExpandHardenedPseudos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ bool AArch64ExpandHardenedPseudos::expandPtrAuthPseudo(MachineInstr &MI) {
if (MI.getOpcode() == AArch64::LOADauthptrgot) {
LLVM_DEBUG(dbgs() << "Expanding: " << MI << "\n");

if (!STI.hasPAuth())
report_fatal_error("pac instructions require ptrauth target feature");

const TargetMachine &TM = MF.getTarget();
MachineModuleInfo &MMI = MF.getMMI();

Expand Down Expand Up @@ -223,6 +226,9 @@ bool AArch64ExpandHardenedPseudos::expandPtrAuthPseudo(MachineInstr &MI) {

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

if (!STI.hasPAuth())
report_fatal_error("pac instructions require ptrauth target feature");

const bool IsGOTLoad = MI.getOpcode() == AArch64::LOADgotPAC;
MachineOperand GAOp = MI.getOperand(0);
auto Key = (AArch64PACKey::ID)MI.getOperand(1).getImm();
Expand Down
58 changes: 58 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-lowering-err-debug.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
; REQUIRES: asserts
; RUN: split-file %s %t && cd %t

;--- MOVaddrPAC.ll

; RUN: not --crash llc -debug -mtriple aarch64-elf MOVaddrPAC.ll 2>&1 | \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-debug may be replaced with -debug-only=aarch64-expand-hardened-pseudos for less verbose debug output (not sure which is more canonical in tests, though).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 52afe42

; RUN: FileCheck MOVaddrPAC.ll

; CHECK: Expanding: MOVaddrPAC @foo
; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

@foo.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @foo, i32 0, i64 0, i64 0 }, section "llvm.ptrauth", align 8

define ptr @bar() #0 {
ret ptr @foo.ptrauth
}

define private void @foo() {
ret void
}

attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }

;--- LOADgotPAC.ll

; RUN: not --crash llc -debug -mtriple aarch64-elf LOADgotPAC.ll 2>&1 | \
; RUN: FileCheck LOADgotPAC.ll

; CHECK: Expanding: LOADgotPAC @foo
; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

@foo.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @foo, i32 0, i64 0, i64 0 }, section "llvm.ptrauth", align 8

define ptr @bar() #0 {
ret ptr @foo.ptrauth
}

declare void @foo()

attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }

;--- LOADauthptrgot.ll

; RUN: not --crash llc -debug -mtriple aarch64-elf LOADauthptrgot.ll 2>&1 | \
; RUN: FileCheck LOADauthptrgot.ll

; CHECK: Expanding: {{.*}}LOADauthptrgot @g_weak
; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

define i8* @foo() #0 {
%tmp = bitcast { i8*, i32, i64, i64 }* @g_weak.ptrauth to i8*
ret i8* %tmp
}

@g_weak = extern_weak global i32
@g_weak.ptrauth = private constant { i8*, i32, i64, i64 } { i8* bitcast (i32* @g_weak to i8*), i32 0, i64 0, i64 0 }, section "llvm.ptrauth"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8e30a83


attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }
54 changes: 54 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-lowering-err.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
; RUN: split-file %s %t && cd %t

;--- MOVaddrPAC.ll

; RUN: not --crash llc -mtriple aarch64-elf MOVaddrPAC.ll 2>&1 | \
; RUN: FileCheck MOVaddrPAC.ll

; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

@foo.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @foo, i32 0, i64 0, i64 0 }, section "llvm.ptrauth", align 8

define ptr @bar() #0 {
ret ptr @foo.ptrauth
}

define private void @foo() {
ret void
}

attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }

;--- LOADgotPAC.ll

; RUN: not --crash llc -mtriple aarch64-elf LOADgotPAC.ll 2>&1 | \
; RUN: FileCheck LOADgotPAC.ll

; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

@foo.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @foo, i32 0, i64 0, i64 0 }, section "llvm.ptrauth", align 8

define ptr @bar() #0 {
ret ptr @foo.ptrauth
}

declare void @foo()

attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }

;--- LOADauthptrgot.ll

; RUN: not --crash llc -mtriple aarch64-elf LOADauthptrgot.ll 2>&1 | \
; RUN: FileCheck LOADauthptrgot.ll

; CHECK: LLVM ERROR: pac instructions require ptrauth target feature

define i8* @foo() #0 {
%tmp = bitcast { i8*, i32, i64, i64 }* @g_weak.ptrauth to i8*
ret i8* %tmp
}

@g_weak = extern_weak global i32
@g_weak.ptrauth = private constant { i8*, i32, i64, i64 } { i8* bitcast (i32* @g_weak to i8*), i32 0, i64 0, i64 0 }, section "llvm.ptrauth"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typed pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8e30a83


attributes #0 = { "ptrauth-calls" "target-cpu"="generic" }