-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[PAC][Driver] Support pauthtest
ABI for AArch64 Linux triples
#97237
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 all commits
3b4b1b1
c923eb1
fcd090c
0579818
a8dadc1
1d81b91
2608617
3067c93
501a43b
a3dff30
f06bc88
a37bd92
2615131
eae6f7c
f498b76
4f3da9e
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 |
---|---|---|
|
@@ -1484,6 +1484,41 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) { | |
} | ||
} | ||
|
||
// Each combination of options here forms a signing schema, and in most cases | ||
// each signing schema is its own incompatible ABI. The default values of the | ||
// options represent the default signing schema. | ||
static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args) { | ||
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics, | ||
options::OPT_fno_ptrauth_intrinsics)) | ||
CC1Args.push_back("-fptrauth-intrinsics"); | ||
|
||
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_auth_traps, | ||
options::OPT_fno_ptrauth_auth_traps)) | ||
CC1Args.push_back("-fptrauth-auth-traps"); | ||
|
||
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"); | ||
|
||
if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini, | ||
options::OPT_fno_ptrauth_init_fini)) | ||
CC1Args.push_back("-fptrauth-init-fini"); | ||
} | ||
|
||
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, | ||
ArgStringList &CmdArgs, bool isAArch64) { | ||
const Arg *A = isAArch64 | ||
|
@@ -1546,16 +1581,30 @@ static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, | |
|
||
CmdArgs.push_back( | ||
Args.MakeArgString(Twine("-msign-return-address=") + Scope)); | ||
if (Scope != "none") | ||
if (Scope != "none") { | ||
if (Triple.getEnvironment() == llvm::Triple::PAuthTest) | ||
D.Diag(diag::err_drv_unsupported_opt_for_target) | ||
<< A->getAsString(Args) << Triple.getTriple(); | ||
CmdArgs.push_back( | ||
Args.MakeArgString(Twine("-msign-return-address-key=") + Key)); | ||
if (BranchProtectionPAuthLR) | ||
} | ||
if (BranchProtectionPAuthLR) { | ||
if (Triple.getEnvironment() == llvm::Triple::PAuthTest) | ||
D.Diag(diag::err_drv_unsupported_opt_for_target) | ||
<< A->getAsString(Args) << Triple.getTriple(); | ||
CmdArgs.push_back( | ||
Args.MakeArgString(Twine("-mbranch-protection-pauth-lr"))); | ||
} | ||
if (IndirectBranches) | ||
CmdArgs.push_back("-mbranch-target-enforce"); | ||
if (GuardedControlStack) | ||
// GCS is currently untested with PAuthABI, but enabling this could be allowed | ||
// in future after testing with a suitable system. | ||
if (GuardedControlStack) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think GuardedControlStack should be compatible with PAuthABI but there won't be hardware available for some time so we could retrospectively support it later after testing it. Perhaps worth a comment that GCS is untested with PAuthABI, but could be enabled after testing with a suitable system. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment, thanks! See 4f3da9e |
||
if (Triple.getEnvironment() == llvm::Triple::PAuthTest) | ||
D.Diag(diag::err_drv_unsupported_opt_for_target) | ||
<< A->getAsString(Args) << Triple.getTriple(); | ||
CmdArgs.push_back("-mguarded-control-stack"); | ||
} | ||
} | ||
|
||
void Clang::AddARMTargetArgs(const llvm::Triple &Triple, const ArgList &Args, | ||
|
@@ -1699,6 +1748,8 @@ void RenderAArch64ABI(const llvm::Triple &Triple, const ArgList &Args, | |
ABIName = A->getValue(); | ||
else if (Triple.isOSDarwin()) | ||
ABIName = "darwinpcs"; | ||
else if (Triple.getEnvironment() == llvm::Triple::PAuthTest) | ||
ABIName = "pauthtest"; | ||
else | ||
ABIName = "aapcs"; | ||
|
||
|
@@ -1735,6 +1786,9 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, | |
// Enable/disable return address signing and indirect branch targets. | ||
CollectARMPACBTIOptions(getToolChain(), Args, CmdArgs, true /*isAArch64*/); | ||
|
||
if (Triple.getEnvironment() == llvm::Triple::PAuthTest) | ||
handlePAuthABI(Args, CmdArgs); | ||
|
||
// Handle -msve_vector_bits=<bits> | ||
if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) { | ||
StringRef Val = A->getValue(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RUN: %clang --target=aarch64-linux-pauthtest --sysroot=%S/Inputs/multilib_aarch64_linux_tree -### -c %s 2>&1 | FileCheck %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks this is not used: "clang/test/Driver/Inputs/multilib_aarch64_linux_tree/usr/include/aarch64-linux-gnu/.keep" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's not directly used in this test, but I've added that in order to have a choice between two directories (one with default triple, one with pauthtest) and check that the pauthtest directory is chosen. Is this considered unneeded?
Yes, that's possible, thanks for suggestion! But I've followed convention with already present multilib_arm_linux_tree (see clang/test/Driver/arm-multilibs.c test). I'm not sure what's better - stick with old existing conventions or not clutter source tree with empty directories which can be created on demand during test. So, I'll leave this "as is" currently and change this if there are more requests. If you actually have a strong preference for not keeping empty multilib folders in source tree and just creating directories during test - please let me know. |
||
// RUN: %clang --target=aarch64-linux -mabi=pauthtest --sysroot=%S/Inputs/multilib_aarch64_linux_tree -### -c %s 2>&1 | FileCheck %s | ||
|
||
// CHECK: "-internal-externc-isystem" "{{.*}}/usr/include/aarch64-linux-pauthtest" |
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.
See addOptInFlag.
But the implementation seems quite different from the title/description.
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.
Do you mean that we need to replace
with
...?
If so, this does not look correct -
addOptInFlag
would add the flag present (if any) inDriverArgs
toCC1Args
, but we want to append a list of ptrauth flags to cc1 args unconditionally ifpauthabi
is passed as branch protection.Do I miss smth? I suppose I might have misunderstood you point.
Hmm, it actually looks consistent to me, the implementation seems matching the description from my point of view - we want to add a bunch of arguments with
-mbranch-protection=pauthabi
used as a shortcut, we do that. Could you please describe what is inconsistent between description and implementation in a bit more detail?