Skip to content

Commit bf3b529

Browse files
committed
[AArch64] Add ptrauth + BTI support.
1 parent 2cd04c6 commit bf3b529

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,8 @@ let Group = f_Group in {
38893889
HelpText<"Enable type discrimination of vtable pointers">;
38903890
def fptrauth_soft : Flag<["-"], "fptrauth-soft">,
38913891
HelpText<"Enable software lowering of pointer authentication">;
3892+
def fbranch_target_identification : Flag<["-"], "fbranch-target-identification">,
3893+
HelpText<"Emit branch target identification instructions for indirect branch destinations">;
38923894
def fptrauth_block_descriptor_pointers : Flag<["-"], "fptrauth-block-descriptor-pointers">,
38933895
HelpText<"enable signing block descriptors">;
38943896
def fptrauth_function_pointer_type_discrimination : Flag<["-"], "fptrauth-function-pointer-type-discrimination">,
@@ -3910,6 +3912,7 @@ let Group = f_Group in {
39103912
def fno_ptrauth_objc_isa : Flag<["-"], "fno-ptrauth-objc-isa">;
39113913
def fno_ptrauth_block_descriptor_pointers : Flag<["-"], "fno-ptrauth-block-descriptor-pointers">;
39123914
def fno_ptrauth_function_pointer_type_discrimination : Flag<["-"], "fno-ptrauth-function-pointer-type-discrimination">;
3915+
def fno_branch_target_identification : Flag<["-"], "fno-branch-target-identification">;
39133916
}
39143917

39153918
let Group = f_Group in {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7023,6 +7023,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70237023
options::OPT_fno_ptrauth_function_pointer_type_discrimination, false))
70247024
CmdArgs.push_back("-fptrauth-function-pointer-type-discrimination");
70257025

7026+
if (Args.hasArg(options::OPT_fbranch_target_identification,
7027+
options::OPT_fno_branch_target_identification, false))
7028+
CmdArgs.push_back("-mbranch-target-enforce");
7029+
70267030

70277031
// -fsigned-bitfields is default, and clang doesn't yet support
70287032
// -funsigned-bitfields.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
// RUN: %clang_cc1 -triple arm64e-apple-ios -fptrauth-auth-traps -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,TRAPS
1313
// RUN: %clang_cc1 -triple arm64e-apple-ios -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,OFF
1414

15+
// RUN: %clang_cc1 -triple arm64e-apple-ios -mbranch-target-enforce -emit-llvm %s -o - | FileCheck %s --check-prefixes=ALL,BTI
16+
1517
// ALL-LABEL: define void @test() #0
1618
void test() {
1719
}
1820

1921
// RETS: attributes #0 = {{{.*}} "ptrauth-returns" {{.*}}}
2022
// CALLS: attributes #0 = {{{.*}} "ptrauth-calls" {{.*}}}
2123
// TRAPS: attributes #0 = {{{.*}} "ptrauth-auth-traps" {{.*}}}
24+
// BTI: !1 = !{i32 8, !"branch-target-enforcement", i32 1}
2225
// OFF-NOT: attributes {{.*}} "ptrauth-
26+
// OFF-NOT: !"branch-target-enforcement"

clang/test/Driver/arch-arm64e.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// NONE-NOT: "-fptrauth-returns"
88
// NONE-NOT: "-fptrauth-auth-traps"
99
// NONE-NOT: "-fptrauth-soft"
10+
// NONE-NOT: "-mbranch-target-enforce"
1011

1112
// RUN: %clang -target arm64-apple-ios -fptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix CALL
1213
// CALL: "-cc1"{{.*}} {{.*}} "-fptrauth-calls"
@@ -23,6 +24,9 @@
2324
// RUN: %clang -target arm64-apple-ios -fptrauth-soft -c %s -### 2>&1 | FileCheck %s --check-prefix SOFT
2425
// SOFT: "-cc1"{{.*}} {{.*}} "-fptrauth-soft"
2526

27+
// RUN: %clang -target arm64-apple-ios -fbranch-target-identification -c %s -### 2>&1 | FileCheck %s --check-prefix BTI
28+
// BTI: "-cc1"{{.*}} {{.*}} "-mbranch-target-enforce"
29+
2630

2731
// Check the arm64e defaults.
2832
// isa signing is configurable at cmake time, so it's not useful to check the default.

0 commit comments

Comments
 (0)