Skip to content

Commit 49f3c0b

Browse files
committed
Check AArch64 branch-protection earlier in the pipeline.
As suggested in rust-lang#93516.
1 parent 203c876 commit 49f3c0b

File tree

8 files changed

+19
-18
lines changed

8 files changed

+19
-18
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::back::write::to_llvm_code_model;
33
use crate::callee::get_fn;
44
use crate::coverageinfo;
55
use crate::debuginfo;
6-
use crate::errors::BranchProtectionRequiresAArch64;
76
use crate::llvm;
87
use crate::llvm_util;
98
use crate::type_::Type;
@@ -275,10 +274,9 @@ pub unsafe fn create_module<'ll>(
275274
}
276275
}
277276

278-
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
279-
if sess.target.arch != "aarch64" {
280-
sess.emit_err(BranchProtectionRequiresAArch64);
281-
} else {
277+
// AArch64-only options (checked in rustc_session).
278+
if sess.target.arch == "aarch64" {
279+
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
282280
llvm::LLVMRustAddModuleFlag(
283281
llmod,
284282
llvm::LLVMModFlagBehavior::Error,

compiler/rustc_codegen_llvm/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ pub(crate) struct SymbolAlreadyDefined<'a> {
5151
pub symbol_name: &'a str,
5252
}
5353

54-
#[derive(Diagnostic)]
55-
#[diag(codegen_llvm_branch_protection_requires_aarch64)]
56-
pub(crate) struct BranchProtectionRequiresAArch64;
57-
5854
#[derive(Diagnostic)]
5955
#[diag(codegen_llvm_invalid_minimum_alignment)]
6056
pub(crate) struct InvalidMinimumAlignment {

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ codegen_llvm_instrument_coverage_requires_llvm_12 =
1717
codegen_llvm_symbol_already_defined =
1818
symbol `{$symbol_name}` is already defined
1919
20-
codegen_llvm_branch_protection_requires_aarch64 =
21-
-Zbranch-protection is only supported on aarch64
22-
2320
codegen_llvm_invalid_minimum_alignment =
2421
invalid minimum global alignment: {$err}
2522

compiler/rustc_error_messages/locales/en-US/session.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is
4141
4242
session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored
4343
44+
session_branch_protection_requires_aarch64 = `-Zbranch-protection` is only supported on aarch64
45+
4446
session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform
4547
4648
session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions

compiler/rustc_session/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ pub struct StackProtectorNotSupportedForTarget<'a> {
115115
pub target_triple: &'a TargetTriple,
116116
}
117117

118+
#[derive(Diagnostic)]
119+
#[diag(session_branch_protection_requires_aarch64)]
120+
pub(crate) struct BranchProtectionRequiresAArch64;
121+
118122
#[derive(Diagnostic)]
119123
#[diag(session_split_debuginfo_unstable_platform)]
120124
pub struct SplitDebugInfoUnstablePlatform {

compiler/rustc_session/src/session.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::code_stats::CodeStats;
33
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
44
use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, SwitchWithOptPath};
55
use crate::errors::{
6-
CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers, LinkerPluginToWindowsNotSupported,
7-
NotCircumventFeature, ProfileSampleUseFileDoesNotExist, ProfileUseFileDoesNotExist,
8-
SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported, SkippingConstChecks,
9-
SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
6+
BranchProtectionRequiresAArch64, CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers,
7+
LinkerPluginToWindowsNotSupported, NotCircumventFeature, ProfileSampleUseFileDoesNotExist,
8+
ProfileUseFileDoesNotExist, SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported,
9+
SkippingConstChecks, SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
1010
TargetRequiresUnwindTables, UnleashedFeatureHelp, UnstableVirtualFunctionElimination,
1111
UnsupportedDwarfVersion,
1212
};
@@ -1542,6 +1542,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
15421542
}
15431543
}
15441544

1545+
if sess.opts.unstable_opts.branch_protection.is_some() && sess.target.arch != "aarch64" {
1546+
sess.emit_err(BranchProtectionRequiresAArch64);
1547+
}
1548+
15451549
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
15461550
if dwarf_version > 5 {
15471551
sess.emit_err(UnsupportedDwarfVersion { dwarf_version });
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: -Zbranch-protection is only supported on aarch64
1+
error: `-Zbranch-protection` is only supported on aarch64
22

33
error: aborting due to previous error
44

src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// [BADFLAGS] check-fail
44
// [BADFLAGS] needs-llvm-components: aarch64
55
// [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti
6-
// [BADTARGET] build-fail
6+
// [BADTARGET] check-fail
77
// [BADTARGET] needs-llvm-components: x86
88

99
#![crate_type = "lib"]

0 commit comments

Comments
 (0)