Review comments

- Changed the separator from '+' to ','.
- Moved the branch protection options from -C to -Z.
- Additional test for incorrect branch-protection option.
- Remove LLVM < 12 code.
- Style fixes.

Co-authored-by: James McGregor <james.mcgregor2@arm.com>
This commit is contained in:
Jamie Cunliffe
2021-12-01 15:56:59 +00:00
parent 837cc1687f
commit 984ca4689d
12 changed files with 57 additions and 120 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::{BranchProtection, CFGuard, CrateType, DebugInfo, PAuthKey};
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;
@@ -243,7 +243,7 @@ pub unsafe fn create_module(
}
if sess.target.arch == "aarch64" {
let BranchProtection { bti, pac_ret: pac } = sess.opts.cg.branch_protection;
let BranchProtection { bti, pac_ret: pac } = sess.opts.debugging_opts.branch_protection;
llvm::LLVMRustAddModuleFlag(
llmod,
@@ -251,27 +251,23 @@ pub unsafe fn create_module(
bti.into(),
);
if let Some(pac_opts) = pac {
llvm::LLVMRustAddModuleFlag(llmod, "sign-return-address\0".as_ptr().cast(), 1);
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address-all\0".as_ptr().cast(),
pac_opts.leaf.into(),
);
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address-with-bkey\0".as_ptr().cast(),
if pac_opts.key == PAuthKey::A { 0 } else { 1 },
);
} else {
llvm::LLVMRustAddModuleFlag(llmod, "sign-return-address\0".as_ptr().cast(), 0);
llvm::LLVMRustAddModuleFlag(llmod, "sign-return-address-all\0".as_ptr().cast(), 0);
llvm::LLVMRustAddModuleFlag(
llmod,
"sign-return-address-with-bkey\0".as_ptr().cast(),
0,
);
}
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