Skip to content

Commit ab05f92

Browse files
committed
[clang] Enable pointer authentication auth-failure traps.
1 parent 9d315bc commit ab05f92

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

clang/include/clang/Basic/PointerAuthOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ struct PointerAuthOptions {
166166
/// Do indirect goto label addresses need to be authenticated?
167167
bool IndirectGotos = false;
168168

169+
/// Do authentication failures cause a trap?
170+
bool AuthTraps = false;
171+
169172
/// The ABI for C function pointers.
170173
PointerAuthSchema FunctionPointers;
171174

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
884884
Fn->addFnAttr("ptrauth-calls");
885885
if (CodeGenOpts.PointerAuth.IndirectGotos)
886886
Fn->addFnAttr("ptrauth-indirect-gotos");
887+
if (CodeGenOpts.PointerAuth.AuthTraps)
888+
Fn->addFnAttr("ptrauth-auth-traps");
887889

888890
// Apply xray attributes to the function (as a string, for now)
889891
bool AlwaysXRayAttr = false;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,13 +1511,15 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
15111511
}
15121512
}
15131513
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
1514+
Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
15141515
}
15151516

15161517
static void parsePointerAuthOptions(PointerAuthOptions &Opts,
15171518
const LangOptions &LangOpts,
15181519
const llvm::Triple &Triple,
15191520
DiagnosticsEngine &Diags) {
1520-
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthIndirectGotos)
1521+
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthIndirectGotos &&
1522+
!LangOpts.PointerAuthAuthTraps)
15211523
return;
15221524

15231525
CompilerInvocation::setDefaultPointerAuthOptions(Opts, LangOpts, Triple);

clang/test/CodeGen/ptrauth-function-attributes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-indirect-gotos -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,GOTOS
99
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-indirect-gotos -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,GOTOS
1010

11+
// RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-auth-traps -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,TRAPS
12+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-auth-traps -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,TRAPS
13+
1114
// ALL: define {{(dso_local )?}}void @test() #0
1215
void test() {
1316
}
@@ -16,4 +19,6 @@ void test() {
1619

1720
// GOTOS: attributes #0 = {{{.*}} "ptrauth-indirect-gotos" {{.*}}}
1821

22+
// TRAPS: attributes #0 = {{{.*}} "ptrauth-auth-traps" {{.*}}}
23+
1924
// OFF-NOT: attributes {{.*}} "ptrauth-

0 commit comments

Comments
 (0)