Rollup merge of #105932 - MasterAwesome:aarch64-bti-llvm-15, r=nikic
Correct branch-protection ModFlagBehavior for Aarch64 on LLVM-15
When building with Fat LTO and BTI enabled on aarch64, the BTI is set to `Module::Min` for alloc shim but is set to `Module::Error` for the crate. This was fine when we were using LLVM-14 but LLVM-15 changes it's behaviour to support for compiling with different `mbranch-protection` flags.
Refer:
b0343a38a5
fixes https://github.com/rust-lang/rust/issues/102162
This commit is contained in:
commit
924a1d4a7a
@ -280,29 +280,35 @@ pub unsafe fn create_module<'ll>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
let behavior = if llvm_version >= (15, 0, 0) {
|
||||||
|
llvm::LLVMModFlagBehavior::Min
|
||||||
|
} else {
|
||||||
|
llvm::LLVMModFlagBehavior::Error
|
||||||
|
};
|
||||||
|
|
||||||
if sess.target.arch == "aarch64" {
|
if sess.target.arch == "aarch64" {
|
||||||
llvm::LLVMRustAddModuleFlag(
|
llvm::LLVMRustAddModuleFlag(
|
||||||
llmod,
|
llmod,
|
||||||
llvm::LLVMModFlagBehavior::Error,
|
behavior,
|
||||||
"branch-target-enforcement\0".as_ptr().cast(),
|
"branch-target-enforcement\0".as_ptr().cast(),
|
||||||
bti.into(),
|
bti.into(),
|
||||||
);
|
);
|
||||||
llvm::LLVMRustAddModuleFlag(
|
llvm::LLVMRustAddModuleFlag(
|
||||||
llmod,
|
llmod,
|
||||||
llvm::LLVMModFlagBehavior::Error,
|
behavior,
|
||||||
"sign-return-address\0".as_ptr().cast(),
|
"sign-return-address\0".as_ptr().cast(),
|
||||||
pac_ret.is_some().into(),
|
pac_ret.is_some().into(),
|
||||||
);
|
);
|
||||||
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
|
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
|
||||||
llvm::LLVMRustAddModuleFlag(
|
llvm::LLVMRustAddModuleFlag(
|
||||||
llmod,
|
llmod,
|
||||||
llvm::LLVMModFlagBehavior::Error,
|
behavior,
|
||||||
"sign-return-address-all\0".as_ptr().cast(),
|
"sign-return-address-all\0".as_ptr().cast(),
|
||||||
pac_opts.leaf.into(),
|
pac_opts.leaf.into(),
|
||||||
);
|
);
|
||||||
llvm::LLVMRustAddModuleFlag(
|
llvm::LLVMRustAddModuleFlag(
|
||||||
llmod,
|
llmod,
|
||||||
llvm::LLVMModFlagBehavior::Error,
|
behavior,
|
||||||
"sign-return-address-with-bkey\0".as_ptr().cast(),
|
"sign-return-address-with-bkey\0".as_ptr().cast(),
|
||||||
u32::from(pac_opts.key == PAuthKey::B),
|
u32::from(pac_opts.key == PAuthKey::B),
|
||||||
);
|
);
|
||||||
|
@ -79,6 +79,7 @@ pub enum LLVMModFlagBehavior {
|
|||||||
Append = 5,
|
Append = 5,
|
||||||
AppendUnique = 6,
|
AppendUnique = 6,
|
||||||
Max = 7,
|
Max = 7,
|
||||||
|
Min = 8,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consts for the LLVM CallConv type, pre-cast to usize.
|
// Consts for the LLVM CallConv type, pre-cast to usize.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user