mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Auto merge of #105421 - jacobbramley:jb/branch-prot-check, r=nagisa
Check AArch64 branch-protection earlier in the pipeline. As suggested in #93516. r? `@nagisa`
This commit is contained in:
commit
aef17b7ae6
@ -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;
|
||||
@ -281,9 +280,7 @@ 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 {
|
||||
if sess.target.arch == "aarch64" {
|
||||
llvm::LLVMRustAddModuleFlag(
|
||||
llmod,
|
||||
llvm::LLVMModFlagBehavior::Error,
|
||||
@ -309,6 +306,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."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -17,9 +17,6 @@ codegen_llvm_instrument_coverage_requires_llvm_12 =
|
||||
codegen_llvm_symbol_already_defined =
|
||||
symbol `{$symbol_name}` is already defined
|
||||
|
||||
codegen_llvm_branch_protection_requires_aarch64 =
|
||||
-Zbranch-protection is only supported on aarch64
|
||||
|
||||
codegen_llvm_invalid_minimum_alignment =
|
||||
invalid minimum global alignment: {$err}
|
||||
|
||||
|
@ -41,6 +41,8 @@ session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is
|
||||
|
||||
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
|
||||
|
||||
session_branch_protection_requires_aarch64 = `-Zbranch-protection` is only supported on aarch64
|
||||
|
||||
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform
|
||||
|
||||
session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions
|
||||
|
@ -115,6 +115,10 @@ pub struct StackProtectorNotSupportedForTarget<'a> {
|
||||
pub target_triple: &'a TargetTriple,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(session_branch_protection_requires_aarch64)]
|
||||
pub(crate) struct BranchProtectionRequiresAArch64;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(session_split_debuginfo_unstable_platform)]
|
||||
pub struct SplitDebugInfoUnstablePlatform {
|
||||
|
@ -3,10 +3,10 @@ use crate::code_stats::CodeStats;
|
||||
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
||||
use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, SwitchWithOptPath};
|
||||
use crate::errors::{
|
||||
CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers, LinkerPluginToWindowsNotSupported,
|
||||
NotCircumventFeature, ProfileSampleUseFileDoesNotExist, ProfileUseFileDoesNotExist,
|
||||
SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported, SkippingConstChecks,
|
||||
SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
|
||||
BranchProtectionRequiresAArch64, CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers,
|
||||
LinkerPluginToWindowsNotSupported, NotCircumventFeature, ProfileSampleUseFileDoesNotExist,
|
||||
ProfileUseFileDoesNotExist, SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported,
|
||||
SkippingConstChecks, SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
|
||||
TargetRequiresUnwindTables, UnleashedFeatureHelp, UnstableVirtualFunctionElimination,
|
||||
UnsupportedDwarfVersion,
|
||||
};
|
||||
@ -1565,6 +1565,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
|
||||
}
|
||||
}
|
||||
|
||||
if sess.opts.unstable_opts.branch_protection.is_some() && sess.target.arch != "aarch64" {
|
||||
sess.emit_err(BranchProtectionRequiresAArch64);
|
||||
}
|
||||
|
||||
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
|
||||
if dwarf_version > 5 {
|
||||
sess.emit_err(UnsupportedDwarfVersion { dwarf_version });
|
||||
|
@ -1,7 +1,7 @@
|
||||
# `branch-protection`
|
||||
|
||||
This option lets you enable branch authentication instructions on AArch64.
|
||||
This option is ignored for non-AArch64 architectures.
|
||||
This option is only accepted when targeting AArch64 architectures.
|
||||
It takes some combination of the following values, separated by a `,`.
|
||||
|
||||
- `pac-ret` - Enable pointer authentication for non-leaf functions.
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: -Zbranch-protection is only supported on aarch64
|
||||
error: `-Zbranch-protection` is only supported on aarch64
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// [BADFLAGS] check-fail
|
||||
// [BADFLAGS] needs-llvm-components: aarch64
|
||||
// [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti
|
||||
// [BADTARGET] build-fail
|
||||
// [BADTARGET] check-fail
|
||||
// [BADTARGET] needs-llvm-components: x86
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
Loading…
Reference in New Issue
Block a user