-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang][PAC][darwin] Set correct default ptrauth features for arm64e-darwin #153722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0cbb084
4f7927f
e47f40f
f464c22
9f57f5d
c7e3353
1e7d828
6e869fa
0381cce
82b588f
4d80f7a
c98f3b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3291,6 +3291,39 @@ void Darwin::addClangTargetOptions( | |
if (!RequiresSubdirectorySearch) | ||
CC1Args.push_back("-fno-modulemap-allow-subdirectory-search"); | ||
} | ||
|
||
if (getTriple().isArm64e()) { | ||
auto EnsureDefaultPtrauthFlag = [&](OptSpecifier Pos, OptSpecifier Neg) { | ||
|
||
assert(Pos != Neg); | ||
if (const Arg *Opt = DriverArgs.getLastArg(Pos, Neg); | ||
Opt && Opt->getOption().matches(Neg)) | ||
return; | ||
Option PosOpt = getDriverOptTable().getOption(Pos); | ||
CC1Args.push_back(PosOpt.getPrefixedName().data()); | ||
}; | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_calls, | ||
options::OPT_fno_ptrauth_calls); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_returns, | ||
options::OPT_fno_ptrauth_returns); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_intrinsics, | ||
options::OPT_fno_ptrauth_intrinsics); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_indirect_gotos, | ||
options::OPT_fno_ptrauth_indirect_gotos); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_auth_traps, | ||
options::OPT_fno_ptrauth_auth_traps); | ||
EnsureDefaultPtrauthFlag( | ||
options::OPT_fptrauth_vtable_pointer_address_discrimination, | ||
options::OPT_fno_ptrauth_vtable_pointer_address_discrimination); | ||
EnsureDefaultPtrauthFlag( | ||
options::OPT_fptrauth_vtable_pointer_type_discrimination, | ||
options::OPT_fno_ptrauth_vtable_pointer_type_discrimination); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_objc_isa, | ||
options::OPT_fno_ptrauth_objc_isa); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_objc_class_ro, | ||
options::OPT_fno_ptrauth_objc_class_ro); | ||
EnsureDefaultPtrauthFlag(options::OPT_fptrauth_objc_interface_sel, | ||
options::OPT_fno_ptrauth_objc_interface_sel); | ||
} | ||
} | ||
|
||
void Darwin::addClangCC1ASTargetOptions( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// RUN: %clang -target arm64 -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64-apple-macosx -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64-darwin -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64-apple-darwin -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64-apple-ios-macabi -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64-linux-gnu -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64e-linux-gnu -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
|
||
// RUN: %clang -target aarch64-linux-gnu -DNO_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=no_default_ptrauth | ||
// RUN: %clang -target arm64e-apple-macosx -DDARWIN_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=darwin_ptrauth_defaults | ||
// RUN: %clang -target arm64e-apple-ios -DDARWIN_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=darwin_ptrauth_defaults | ||
// RUN: %clang -target arm64e-darwin -DDARWIN_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=darwin_ptrauth_defaults | ||
// RUN: %clang -target arm64e-apple-darwin -DDARWIN_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=darwin_ptrauth_defaults | ||
// RUN: %clang -target arm64e-apple-ios-macabi -DDARWIN_DEFAULT_PTRAUTH %s -fsyntax-only -Xclang -verify=darwin_ptrauth_defaults | ||
|
||
// A simple test case to test basic override logic | ||
// RUN: %clang -target arm64e-apple-macosx -DDARWIN_DEFAULT_PTRAUTH_OVERRIDE -fno-ptrauth-calls %s -fsyntax-only -Xclang -verify=darwin_ptrauth_override | ||
|
||
#define ASSERT_MODE_AND_KIND(feature, enabled, kind) \ | ||
_Static_assert(enabled == __has_##kind(feature), \ | ||
|
||
"Expected to have the " #feature " " #kind " enabled"); | ||
|
||
#define ASSERT_FEATURE_ENABLED(feature_name) \ | ||
ASSERT_MODE_AND_KIND(feature_name, 1, feature) | ||
#define ASSERT_FEATURE_DISABLED(feature_name) \ | ||
ASSERT_MODE_AND_KIND(feature_name, 0, feature) | ||
#define ASSERT_EXTENSION_ENABLED(extension_name) \ | ||
ASSERT_MODE_AND_KIND(extension_name, 1, extension) | ||
#define ASSERT_EXTENSION_DISABLED(extension_name) \ | ||
ASSERT_MODE_AND_KIND(extension_name, 0, extension) | ||
|
||
#if defined(DARWIN_DEFAULT_PTRAUTH) || defined(DARWIN_DEFAULT_PTRAUTH_OVERRIDE) | ||
ASSERT_FEATURE_ENABLED(ptrauth_intrinsics) | ||
ASSERT_EXTENSION_ENABLED(ptrauth_qualifier) | ||
|
||
#if defined(DARWIN_DEFAULT_PTRAUTH_OVERRIDE) | ||
ASSERT_FEATURE_DISABLED(ptrauth_calls) | ||
// These flags directly reflect the state of ptrauth_calls, but exist | ||
// for backward compatibility reasons | ||
ASSERT_FEATURE_DISABLED(ptrauth_member_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_method_list_pointer) | ||
#else | ||
ASSERT_FEATURE_ENABLED(ptrauth_calls) | ||
ASSERT_FEATURE_ENABLED(ptrauth_member_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_ENABLED(ptrauth_objc_method_list_pointer) | ||
#endif | ||
|
||
ASSERT_FEATURE_ENABLED(ptrauth_returns) | ||
ASSERT_FEATURE_ENABLED(ptrauth_vtable_pointer_address_discrimination) | ||
ASSERT_FEATURE_ENABLED(ptrauth_vtable_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_type_info_vtable_pointer_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_signed_block_descriptors) | ||
ASSERT_FEATURE_DISABLED(ptrauth_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_ENABLED(ptrauth_indirect_gotos) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini_address_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_elf_got) | ||
ASSERT_FEATURE_ENABLED(ptrauth_objc_isa) | ||
ASSERT_FEATURE_ENABLED(ptrauth_objc_interface_sel) | ||
ASSERT_FEATURE_ENABLED(ptrauth_objc_signable_class) | ||
#endif | ||
|
||
#ifdef NO_DEFAULT_PTRAUTH | ||
ASSERT_FEATURE_DISABLED(ptrauth_intrinsics) | ||
ASSERT_EXTENSION_DISABLED(ptrauth_qualifier) | ||
ASSERT_FEATURE_DISABLED(ptrauth_calls) | ||
ASSERT_FEATURE_DISABLED(ptrauth_returns) | ||
ASSERT_FEATURE_DISABLED(ptrauth_vtable_pointer_address_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_vtable_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_type_info_vtable_pointer_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_member_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_signed_block_descriptors) | ||
ASSERT_FEATURE_DISABLED(ptrauth_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_indirect_gotos) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini_address_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_elf_got) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_isa) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_interface_sel) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_signable_class) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_method_list_pointer) | ||
#endif | ||
|
||
// darwin_ptrauth_defaults-no-diagnostics | ||
// no_default_ptrauth-no-diagnostics | ||
// darwin_ptrauth_override-no-diagnostics |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: %clang_cc1 -triple arm64 %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64-apple-macosx %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64-darwin %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64-apple-darwin %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64-apple-ios-macabi %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64-linux-gnu %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-linux-gnu %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple aarch64-linux-gnu %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-apple-macosx %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-apple-ios %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-darwin %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-apple-darwin %s -fsyntax-only | ||
// RUN: %clang_cc1 -triple arm64e-apple-ios-macabi %s -fsyntax-only | ||
|
||
// The -cc1 mode should not insert default ptrauth flags | ||
|
||
#define ASSERT_MODE_AND_KIND(feature, enabled, kind) \ | ||
_Static_assert(enabled == __has_##kind(feature), \ | ||
"Expected to have the " #feature " " #kind " enabled"); | ||
|
||
#define ASSERT_FEATURE_DISABLED(feature_name) \ | ||
ASSERT_MODE_AND_KIND(feature_name, 0, feature) | ||
#define ASSERT_EXTENSION_DISABLED(extension_name) \ | ||
ASSERT_MODE_AND_KIND(extension_name, 0, extension) | ||
|
||
ASSERT_FEATURE_DISABLED(ptrauth_intrinsics) | ||
ASSERT_EXTENSION_DISABLED(ptrauth_qualifier) | ||
ASSERT_FEATURE_DISABLED(ptrauth_calls) | ||
ASSERT_FEATURE_DISABLED(ptrauth_returns) | ||
ASSERT_FEATURE_DISABLED(ptrauth_vtable_pointer_address_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_vtable_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_type_info_vtable_pointer_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_member_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_signed_block_descriptors) | ||
ASSERT_FEATURE_DISABLED(ptrauth_function_pointer_type_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_indirect_gotos) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini) | ||
ASSERT_FEATURE_DISABLED(ptrauth_init_fini_address_discrimination) | ||
ASSERT_FEATURE_DISABLED(ptrauth_elf_got) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_isa) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_interface_sel) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_signable_class) | ||
ASSERT_FEATURE_DISABLED(ptrauth_objc_method_list_pointer) | ||
|
||
// expected-no-diagnostics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a block up in
MachO::addClangTargetOptions
. But it's been committed separately from our upstreaming effort, so is definitely outdated; can you update it insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this - the out of date-ness was not bad, it was just lacking the new features that this PR was adding - but I've moved it to there as well.
I was concerned about pushing it down to MachO before, but I've realized that there is unlikely to be another platform built on MachOs targeting arm64e specifically :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I think it was moved from darwin to macho specifically for the myriad non-userland targets, which are usually obscure and not too interesting here