Skip to content

Commit 241ecf4

Browse files
committed
[clang] Enable pointer authentication auth-failure traps.
1 parent 2eb6e30 commit 241ecf4

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
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
/// Should return addresses be authenticated?
167167
bool ReturnAddresses = false;
168168

169+
/// Do authentication failures cause a trap?
170+
bool AuthTraps = false;
171+
169172
/// Do indirect goto label addresses need to be authenticated?
170173
bool IndirectGotos = false;
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-returns");
885885
if (CodeGenOpts.PointerAuth.FunctionPointers)
886886
Fn->addFnAttr("ptrauth-calls");
887+
if (CodeGenOpts.PointerAuth.AuthTraps)
888+
Fn->addFnAttr("ptrauth-auth-traps");
887889
if (CodeGenOpts.PointerAuth.IndirectGotos)
888890
Fn->addFnAttr("ptrauth-indirect-gotos");
889891

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,16 +1510,17 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
15101510
Discrimination::Constant, InitFiniPointerConstantDiscriminator);
15111511
}
15121512
}
1513-
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
15141513
Opts.ReturnAddresses = LangOpts.PointerAuthReturns;
1514+
Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
1515+
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
15151516
}
15161517

15171518
static void parsePointerAuthOptions(PointerAuthOptions &Opts,
15181519
const LangOptions &LangOpts,
15191520
const llvm::Triple &Triple,
15201521
DiagnosticsEngine &Diags) {
1521-
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthIndirectGotos &&
1522-
!LangOpts.PointerAuthReturns)
1522+
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthReturns &&
1523+
!LangOpts.PointerAuthAuthTraps && !LangOpts.PointerAuthIndirectGotos)
15231524
return;
15241525

15251526
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 arm64-apple-ios -fptrauth-returns -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,RETS
99
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-returns -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,RETS
1010

11+
// RUN: %clang_cc1 -triple arm64-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
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-indirect-gotos -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,GOTOS
1215
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-indirect-gotos -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,GOTOS
1316

@@ -19,6 +22,8 @@ void test() {
1922

2023
// RETS: attributes #0 = {{{.*}} "ptrauth-returns" {{.*}}}
2124

25+
// TRAPS: attributes #0 = {{{.*}} "ptrauth-auth-traps" {{.*}}}
26+
2227
// GOTOS: attributes #0 = {{{.*}} "ptrauth-indirect-gotos" {{.*}}}
2328

2429
// OFF-NOT: attributes {{.*}} "ptrauth-

0 commit comments

Comments
 (0)