[clang][PAC][darwin] Set correct default ptrauth features for arm64e-darwin (#153722)
This PR makes sure that when targeting arm64e on darwin platforms the correct flags are set for the userspace platform ABI. (cherry picked from commit 19c4e86f3e8582c3f087a9fec5ac036838e58ec4)
This commit is contained in:
parent
41cf77340d
commit
993c5643ce
@ -163,7 +163,7 @@ FEATURE(ptrauth_elf_got, LangOpts.PointerAuthELFGOT)
|
||||
|
||||
FEATURE(ptrauth_objc_isa, LangOpts.PointerAuthObjcIsa)
|
||||
FEATURE(ptrauth_objc_interface_sel, LangOpts.PointerAuthObjcInterfaceSel)
|
||||
FEATURE(ptrauth_objc_signable_class, true)
|
||||
FEATURE(ptrauth_objc_signable_class, LangOpts.PointerAuthIntrinsics)
|
||||
FEATURE(ptrauth_objc_method_list_pointer, LangOpts.PointerAuthCalls)
|
||||
|
||||
EXTENSION(swiftcc,
|
||||
|
@ -3187,28 +3187,46 @@ void MachO::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
||||
|
||||
ToolChain::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
|
||||
|
||||
// On arm64e, enable pointer authentication (for the return address and
|
||||
// indirect calls), as well as usage of the intrinsics.
|
||||
if (getArchName() == "arm64e") {
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
|
||||
options::OPT_fno_ptrauth_returns))
|
||||
CC1Args.push_back("-fptrauth-returns");
|
||||
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
|
||||
options::OPT_fno_ptrauth_intrinsics))
|
||||
CC1Args.push_back("-fptrauth-intrinsics");
|
||||
|
||||
// On arm64e, we enable all the features required for the Darwin userspace
|
||||
// ABI
|
||||
if (getTriple().isArm64e()) {
|
||||
// Core platform ABI
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
|
||||
options::OPT_fno_ptrauth_calls))
|
||||
CC1Args.push_back("-fptrauth-calls");
|
||||
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
|
||||
options::OPT_fno_ptrauth_returns))
|
||||
CC1Args.push_back("-fptrauth-returns");
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
|
||||
options::OPT_fno_ptrauth_intrinsics))
|
||||
CC1Args.push_back("-fptrauth-intrinsics");
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
|
||||
options::OPT_fno_ptrauth_indirect_gotos))
|
||||
CC1Args.push_back("-fptrauth-indirect-gotos");
|
||||
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
|
||||
options::OPT_fno_ptrauth_auth_traps))
|
||||
CC1Args.push_back("-fptrauth-auth-traps");
|
||||
|
||||
// C++ v-table ABI
|
||||
if (!DriverArgs.hasArg(
|
||||
options::OPT_fptrauth_vtable_pointer_address_discrimination,
|
||||
options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
|
||||
CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
|
||||
if (!DriverArgs.hasArg(
|
||||
options::OPT_fptrauth_vtable_pointer_type_discrimination,
|
||||
options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
|
||||
CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
|
||||
|
||||
// Objective-C ABI
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_objc_isa,
|
||||
options::OPT_fno_ptrauth_objc_isa))
|
||||
CC1Args.push_back("-fptrauth-objc-isa");
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_objc_class_ro,
|
||||
options::OPT_fno_ptrauth_objc_class_ro))
|
||||
CC1Args.push_back("-fptrauth-objc-class-ro");
|
||||
if (!DriverArgs.hasArg(options::OPT_fptrauth_objc_interface_sel,
|
||||
options::OPT_fno_ptrauth_objc_interface_sel))
|
||||
CC1Args.push_back("-fptrauth-objc-interface-sel");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,20 @@
|
||||
|
||||
// RUN: %clang -target arm64-apple-darwin -c %s -### 2>&1 | FileCheck %s --check-prefix NONE
|
||||
// NONE: "-cc1"
|
||||
// NONE-NOT: "-fptrauth-intrinsics"
|
||||
|
||||
// NONE-NOT: "-fptrauth-calls"
|
||||
// NONE-NOT: "-fptrauth-returns"
|
||||
// NONE-NOT: "-fptrauth-intrinsics"
|
||||
// NONE-NOT: "-fptrauth-indirect-gotos"
|
||||
// NONE-NOT: "-fptrauth-auth-traps"
|
||||
// NONE-NOT: "-fptrauth-vtable-pointer-address-discrimination"
|
||||
// NONE-NOT: "-fptrauth-vtable-pointer-type-discrimination"
|
||||
// NONE-NOT: "-fptrauth-objc-isa"
|
||||
// NONE-NOT: "-fptrauth-objc-class-ro"
|
||||
// NONE-NOT: "-fptrauth-objc-interface-sel"
|
||||
|
||||
// Final catch all if any new flags are added
|
||||
// NONE-NOT: "-fptrauth"
|
||||
|
||||
// RUN: %clang -target arm64-apple-darwin -fptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix CALL
|
||||
// CALL: "-cc1"{{.*}} {{.*}} "-fptrauth-calls"
|
||||
@ -23,39 +32,39 @@
|
||||
// RUN: %clang -target arm64-apple-darwin -fptrauth-auth-traps -c %s -### 2>&1 | FileCheck %s --check-prefix TRAPS
|
||||
// TRAPS: "-cc1"{{.*}} {{.*}} "-fptrauth-auth-traps"
|
||||
|
||||
|
||||
// Check the arm64e defaults.
|
||||
|
||||
// RUN: %clang -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
|
||||
// RUN: %clang -target arm64e-apple-macos -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULTMAC
|
||||
// RUN: %if system-darwin && target={{.*}}-{{darwin|macos}}{{.*}} %{ %clang -target arm64e-apple-macos -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULTARCH %}
|
||||
// RUN: %clang -mkernel -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
|
||||
// RUN: %clang -fapple-kext -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
|
||||
// DEFAULT: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
|
||||
// DEFAULT: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"{{.*}}
|
||||
// DEFAULTMAC: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-m1"{{.*}}
|
||||
// DEFAULTARCH: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel"
|
||||
|
||||
// RUN: %clang -target arm64e-apple-none-macho -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-MACHO
|
||||
// DEFAULT-MACHO: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
|
||||
// DEFAULT-MACHO: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"{{.*}}
|
||||
|
||||
|
||||
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
|
||||
// RUN: %clang -mkernel -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
|
||||
// RUN: %clang -fapple-kext -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
|
||||
// DEFAULT-NOCALL-NOT: "-fptrauth-calls"
|
||||
// DEFAULT-NOCALL: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"
|
||||
// DEFAULT-NOCALL: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"
|
||||
|
||||
|
||||
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-returns -c %s -### 2>&1 | FileCheck %s --check-prefix NORET
|
||||
|
||||
// NORET-NOT: "-fptrauth-returns"
|
||||
// NORET: "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"
|
||||
// NORET: "-fptrauth-calls" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"
|
||||
|
||||
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-intrinsics -c %s -### 2>&1 | FileCheck %s --check-prefix NOINTRIN
|
||||
|
||||
// NOINTRIN: "-fptrauth-returns"
|
||||
// NOINTRIN-NOT: "-fptrauth-intrinsics"
|
||||
// NOINTRIN: "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
|
||||
// NOINTRIN: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"
|
||||
|
||||
|
||||
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-auth-traps -c %s -### 2>&1 | FileCheck %s --check-prefix NOTRAP
|
||||
// NOTRAP: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" {{.*}}"-target-cpu" "apple-a12"
|
||||
// NOTRAP: "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-objc-isa" "-fptrauth-objc-class-ro" "-fptrauth-objc-interface-sel" {{.*}}"-target-cpu" "apple-a12"
|
||||
|
||||
|
||||
// Check the CPU defaults and overrides.
|
||||
|
@ -130,3 +130,11 @@ void has_ptrauth_elf_got() {}
|
||||
// NOELFGOT: no_ptrauth_elf_got
|
||||
void no_ptrauth_elf_got() {}
|
||||
#endif
|
||||
|
||||
#if __has_feature(ptrauth_objc_signable_class)
|
||||
// INTRIN: has_ptrauth_objc_signable_class
|
||||
void has_ptrauth_objc_signable_class(){}
|
||||
#else
|
||||
// NOINTRIN: no_ptrauth_objc_signable_class
|
||||
void no_ptrauth_objc_signable_class(){}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user