From 49f3c0b73689eed49df9ef822f9fd437db93ce9e Mon Sep 17 00:00:00 2001 From: Jacob Bramley Date: Mon, 21 Nov 2022 16:05:51 +0000 Subject: Check AArch64 branch-protection earlier in the pipeline. As suggested in #93516. --- compiler/rustc_codegen_llvm/src/context.rs | 8 +++----- compiler/rustc_codegen_llvm/src/errors.rs | 4 ---- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 4dcc7cd5447..a22a67ad7d3 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -3,7 +3,6 @@ use crate::back::write::to_llvm_code_model; use crate::callee::get_fn; use crate::coverageinfo; use crate::debuginfo; -use crate::errors::BranchProtectionRequiresAArch64; use crate::llvm; use crate::llvm_util; use crate::type_::Type; @@ -275,10 +274,9 @@ pub unsafe fn create_module<'ll>( } } - if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection { - if sess.target.arch != "aarch64" { - sess.emit_err(BranchProtectionRequiresAArch64); - } else { + // AArch64-only options (checked in rustc_session). + if sess.target.arch == "aarch64" { + if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection { llvm::LLVMRustAddModuleFlag( llmod, llvm::LLVMModFlagBehavior::Error, diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index fddfbb23c67..de508f917f3 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -51,10 +51,6 @@ pub(crate) struct SymbolAlreadyDefined<'a> { pub symbol_name: &'a str, } -#[derive(Diagnostic)] -#[diag(codegen_llvm_branch_protection_requires_aarch64)] -pub(crate) struct BranchProtectionRequiresAArch64; - #[derive(Diagnostic)] #[diag(codegen_llvm_invalid_minimum_alignment)] pub(crate) struct InvalidMinimumAlignment { -- cgit 1.4.1-3-g733a5 From 73d374f3e7d5fe9635a23937cdc2f7e1d1c29224 Mon Sep 17 00:00:00 2001 From: Jacob Bramley Date: Tue, 13 Dec 2022 17:04:02 +0000 Subject: bug! if branch-protection makes it to non-AArch64 codegen. --- compiler/rustc_codegen_llvm/src/context.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index a22a67ad7d3..f6fcdc90cb6 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -274,9 +274,8 @@ pub unsafe fn create_module<'ll>( } } - // AArch64-only options (checked in rustc_session). - if sess.target.arch == "aarch64" { - if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection { + if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection { + if sess.target.arch == "aarch64" { llvm::LLVMRustAddModuleFlag( llmod, llvm::LLVMModFlagBehavior::Error, @@ -302,6 +301,11 @@ pub unsafe fn create_module<'ll>( "sign-return-address-with-bkey\0".as_ptr().cast(), u32::from(pac_opts.key == PAuthKey::B), ); + } else { + bug!( + "branch-protection used on non-AArch64 target; \ + this should be checked in rustc_session." + ); } } -- cgit 1.4.1-3-g733a5