diff options
| author | Jamie Cunliffe <Jamie.Cunliffe@arm.com> | 2021-12-01 15:56:59 +0000 |
|---|---|---|
| committer | Jamie Cunliffe <Jamie.Cunliffe@arm.com> | 2021-12-01 15:56:59 +0000 |
| commit | 984ca4689dbceea29bbfcf54c4743b45fccf7ad1 (patch) | |
| tree | 50e979ae7eed117e44f6bce9a82003fe0270f51c /compiler/rustc_codegen_llvm/src/context.rs | |
| parent | 837cc1687f7c0d35a4e90a2f6bee377b5a2ecfd5 (diff) | |
| download | rust-984ca4689dbceea29bbfcf54c4743b45fccf7ad1.tar.gz rust-984ca4689dbceea29bbfcf54c4743b45fccf7ad1.zip | |
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>
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/context.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index da05b5c0cba..0f5487a4447 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -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 |
