Auto merge of #146338 - CrooseGit:dev/reucru01/AArch64-enable-GCS, r=Urgau,davidtwco
Extends AArch64 branch protection support to include GCS Extends existing support for AArch64 branch protection to include support for [Guarded Control Stacks](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022#guarded-control-stack-gcs:~:text=Extraction%20or%20tracking.-,Guarded%20Control%20Stack%20(GCS),-With%20the%202022).
This commit is contained in:
@@ -407,13 +407,16 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
|
||||
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
|
||||
|
||||
// For non-naked functions, set branch protection attributes on aarch64.
|
||||
if let Some(BranchProtection { bti, pac_ret }) =
|
||||
if let Some(BranchProtection { bti, pac_ret, gcs }) =
|
||||
cx.sess().opts.unstable_opts.branch_protection
|
||||
{
|
||||
assert!(cx.sess().target.arch == "aarch64");
|
||||
if bti {
|
||||
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
|
||||
}
|
||||
if gcs {
|
||||
to_add.push(llvm::CreateAttrString(cx.llcx, "guarded-control-stack"));
|
||||
}
|
||||
if let Some(PacRet { leaf, pc, key }) = pac_ret {
|
||||
if pc {
|
||||
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-protection-pauth-lr"));
|
||||
|
||||
@@ -370,7 +370,8 @@ pub(crate) unsafe fn create_module<'ll>(
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
|
||||
if let Some(BranchProtection { bti, pac_ret, gcs }) = sess.opts.unstable_opts.branch_protection
|
||||
{
|
||||
if sess.target.arch == "aarch64" {
|
||||
llvm::add_module_flag_u32(
|
||||
llmod,
|
||||
@@ -403,6 +404,12 @@ pub(crate) unsafe fn create_module<'ll>(
|
||||
"sign-return-address-with-bkey",
|
||||
u32::from(pac_opts.key == PAuthKey::B),
|
||||
);
|
||||
llvm::add_module_flag_u32(
|
||||
llmod,
|
||||
llvm::ModuleFlagMergeBehavior::Min,
|
||||
"guarded-control-stack",
|
||||
gcs.into(),
|
||||
);
|
||||
} else {
|
||||
bug!(
|
||||
"branch-protection used on non-AArch64 target; \
|
||||
|
||||
Reference in New Issue
Block a user