Skip to content

Commit 147ee4a

Browse files
ahmedbougachallvmbot
authored andcommitted
[clang] Implement -fptrauth-auth-traps. (llvm#102417)
This provides -fptrauth-auth-traps, which at the frontend level only controls the addition of the "ptrauth-auth-traps" function attribute. The attribute in turn controls various aspects of backend codegen, by providing the guarantee that every "auth" operation generated will trap on failure. This can either be delegated to the hardware (if AArch64 FPAC is known to be available), in which case this attribute doesn't change codegen. Otherwise, if FPAC isn't available, this asks the backend to emit additional instructions to check and trap on auth failure. (cherry picked from commit d179acd)
1 parent 4fd6b32 commit 147ee4a

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
@@ -162,6 +162,9 @@ struct PointerAuthOptions {
162162
/// Should return addresses be authenticated?
163163
bool ReturnAddresses = false;
164164

165+
/// Do authentication failures cause a trap?
166+
bool AuthTraps = false;
167+
165168
/// Do indirect goto label addresses need to be authenticated?
166169
bool IndirectGotos = false;
167170

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
@@ -1504,16 +1504,17 @@ void CompilerInvocation::setDefaultPointerAuthOptions(
15041504
Opts.CXXMemberFunctionPointers =
15051505
PointerAuthSchema(Key::ASIA, false, Discrimination::Type);
15061506
}
1507-
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
15081507
Opts.ReturnAddresses = LangOpts.PointerAuthReturns;
1508+
Opts.AuthTraps = LangOpts.PointerAuthAuthTraps;
1509+
Opts.IndirectGotos = LangOpts.PointerAuthIndirectGotos;
15091510
}
15101511

15111512
static void parsePointerAuthOptions(PointerAuthOptions &Opts,
15121513
const LangOptions &LangOpts,
15131514
const llvm::Triple &Triple,
15141515
DiagnosticsEngine &Diags) {
1515-
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthIndirectGotos &&
1516-
!LangOpts.PointerAuthReturns)
1516+
if (!LangOpts.PointerAuthCalls && !LangOpts.PointerAuthReturns &&
1517+
!LangOpts.PointerAuthAuthTraps && !LangOpts.PointerAuthIndirectGotos)
15171518
return;
15181519

15191520
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)