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
8 changes: 6 additions & 2 deletions llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,9 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
// If we're saving LR, sign it first.
if (shouldAuthenticateLR(MF)) {
if (LLVM_UNLIKELY(!Subtarget.hasPAuth()))
report_fatal_error("arm64e LR authentication requires ptrauth");
report_fatal_error(
StringRef(Subtarget.isTargetMachO() ? "arm64e" : "aarch64") +
" LR authentication requires ptrauth");
for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
if (Info.getReg() != AArch64::LR)
continue;
Expand Down Expand Up @@ -2051,7 +2053,9 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
auto InsertAuthLROnExit = make_scope_exit([&]() {
if (shouldAuthenticateLR(MF)) {
if (LLVM_UNLIKELY(!Subtarget.hasPAuth()))
report_fatal_error("arm64e LR authentication requires ptrauth");
report_fatal_error(
StringRef(Subtarget.isTargetMachO() ? "arm64e" : "aarch64") +
" LR authentication requires ptrauth");
for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
if (Info.getReg() != AArch64::LR)
continue;
Expand Down
61 changes: 61 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,61 @@
; REQUIRES: asserts
; RUN: split-file %s %t && cd %t

;--- MOVaddrPAC.ll

; RUN: not --crash llc -debug-only=aarch64-expand-hardened-pseudos -mtriple aarch64-elf MOVaddrPAC.ll 2>&1 | \
; RUN: FileCheck MOVaddrPAC.ll

; CHECK: Expanding: MOVaddrPAC @foo
; CHECK-NEXT: {{^$}}
; CHECK-NEXT: 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-only=aarch64-expand-hardened-pseudos -mtriple aarch64-elf LOADgotPAC.ll 2>&1 | \
; RUN: FileCheck LOADgotPAC.ll

; CHECK: Expanding: LOADgotPAC @foo
; CHECK-NEXT: {{^$}}
; CHECK-NEXT: 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-only=aarch64-expand-hardened-pseudos -mtriple aarch64-elf LOADauthptrgot.ll 2>&1 | \
; RUN: FileCheck LOADauthptrgot.ll

; CHECK: Expanding: {{.*}}LOADauthptrgot @g_weak
; CHECK-NEXT: {{^$}}
; CHECK-NEXT: 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" }
86 changes: 86 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,86 @@
; 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" }

;--- ptrauth-returns.ll

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

; CHECK: LLVM ERROR: aarch64 LR authentication requires ptrauth

define i32 @bar() #0 {
ret i32 42
}

define i32 @foo() {
%tmp = call i32 @bar()
ret i32 %tmp
}

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

;--- auth-call.ll

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

; CHECK: LLVM ERROR: Cannot select:{{.*}}AArch64ISD::AUTH_CALL

define void @bar(ptr %foo) #0 {
call void %foo() [ "ptrauth"(i32 0, i64 0) ]
ret void
}

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