Auto merge of #88354 - Jmc18134:hint-space-pauth-opt, r=nagisa

Add codegen option for branch protection and pointer authentication on AArch64

The branch-protection codegen option enables the use of hint-space pointer
authentication code for AArch64 targets.
This commit is contained in:
bors 2021-12-29 22:35:11 +00:00
commit d331cb710f
13 changed files with 202 additions and 6 deletions

View file

@ -21,7 +21,7 @@ use rustc_middle::ty::layout::{
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
use rustc_session::config::{BranchProtection, CFGuard, CrateType, DebugInfo, PAuthKey, PacRet};
use rustc_session::Session;
use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
@ -242,6 +242,34 @@ pub unsafe fn create_module<'ll>(
}
}
if sess.target.arch == "aarch64" {
let BranchProtection { bti, pac_ret: pac } = sess.opts.debugging_opts.branch_protection;
llvm::LLVMRustAddModuleFlag(
llmod,
"branch-target-enforcement\0".as_ptr().cast(),
bti.into(),
);
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address\0".as_ptr().cast(),
pac.is_some().into(),
);
let pac_opts = pac.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address-all\0".as_ptr().cast(),
pac_opts.leaf.into(),
);
let is_bkey = if pac_opts.key == PAuthKey::A { false } else { true };
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address-with-bkey\0".as_ptr().cast(),
is_bkey.into(),
);
}
llmod
}