1
Fork 0

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:
James McGregor 2021-07-13 12:14:26 +01:00 committed by Jamie Cunliffe
parent 2446a21595
commit 837cc1687f
12 changed files with 266 additions and 7 deletions

View file

@ -842,6 +842,30 @@ impl Passes {
}
}
#[derive(Clone, Copy, Hash, Debug, PartialEq)]
pub enum PAuthKey {
A,
B,
}
#[derive(Clone, Copy, Hash, Debug, PartialEq)]
pub struct PacRet {
pub leaf: bool,
pub key: PAuthKey,
}
#[derive(Clone, Copy, Hash, Debug, PartialEq)]
pub struct BranchProtection {
pub bti: bool,
pub pac_ret: Option<PacRet>,
}
impl Default for BranchProtection {
fn default() -> Self {
BranchProtection { bti: false, pac_ret: None }
}
}
pub const fn default_lib_output() -> CrateType {
CrateType::Rlib
}
@ -2487,9 +2511,9 @@ impl PpMode {
crate mod dep_tracking {
use super::LdImpl;
use super::{
CFGuard, CrateType, DebugInfo, ErrorOutputType, InstrumentCoverage, LinkerPluginLto,
LocationDetail, LtoCli, OptLevel, OutputType, OutputTypes, Passes, SourceFileHashAlgorithm,
SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
BranchProtection, CFGuard, CrateType, DebugInfo, ErrorOutputType, InstrumentCoverage,
LinkerPluginLto, LocationDetail, LtoCli, OptLevel, OutputType, OutputTypes, Passes,
SourceFileHashAlgorithm, SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
};
use crate::lint;
use crate::options::WasiExecModel;
@ -2583,6 +2607,7 @@ crate mod dep_tracking {
OutputType,
RealFileName,
LocationDetail,
BranchProtection,
);
impl<T1, T2> DepTrackingHash for (T1, T2)

View file

@ -389,6 +389,8 @@ mod desc {
pub const parse_gcc_ld: &str = "one of: no value, `lld`";
pub const parse_stack_protector: &str =
"one of (`none` (default), `basic`, `strong`, or `all`)";
pub const parse_branch_protection: &str =
"a `+` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
}
mod parse {
@ -929,6 +931,33 @@ mod parse {
}
true
}
crate fn parse_branch_protection(slot: &mut BranchProtection, v: Option<&str>) -> bool {
match v {
Some(s) => {
for opt in s.split('+') {
match opt {
"bti" => slot.bti = true,
"pac-ret" if slot.pac_ret.is_none() => {
slot.pac_ret = Some(PacRet { leaf: false, key: PAuthKey::A })
}
"leaf" => match slot.pac_ret.as_mut() {
Some(pac) => pac.leaf = true,
_ => return false,
},
"b-key" => match slot.pac_ret.as_mut() {
Some(pac) => pac.key = PAuthKey::B,
_ => return false,
},
_ => return false,
};
}
}
_ => return false,
}
true
}
}
options! {
@ -942,6 +971,8 @@ options! {
ar: String = (String::new(), parse_string, [UNTRACKED],
"this option is deprecated and does nothing"),
branch_protection: BranchProtection = (BranchProtection::default(), parse_branch_protection, [TRACKED],
"set options for branch target identification and pointer authentication on AArch64"),
code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
"choose the code model to use (`rustc --print code-models` for details)"),
codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],