Skip to content

Commit 924a1d4

Browse files
authored
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: rust-lang/llvm-project@b0343a3 fixes #102162
2 parents 3eccc29 + 5480ac5 commit 924a1d4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -280,29 +280,35 @@ pub unsafe fn create_module<'ll>(
280280
}
281281

282282
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
283+
let behavior = if llvm_version >= (15, 0, 0) {
284+
llvm::LLVMModFlagBehavior::Min
285+
} else {
286+
llvm::LLVMModFlagBehavior::Error
287+
};
288+
283289
if sess.target.arch == "aarch64" {
284290
llvm::LLVMRustAddModuleFlag(
285291
llmod,
286-
llvm::LLVMModFlagBehavior::Error,
292+
behavior,
287293
"branch-target-enforcement\0".as_ptr().cast(),
288294
bti.into(),
289295
);
290296
llvm::LLVMRustAddModuleFlag(
291297
llmod,
292-
llvm::LLVMModFlagBehavior::Error,
298+
behavior,
293299
"sign-return-address\0".as_ptr().cast(),
294300
pac_ret.is_some().into(),
295301
);
296302
let pac_opts = pac_ret.unwrap_or(PacRet { leaf: false, key: PAuthKey::A });
297303
llvm::LLVMRustAddModuleFlag(
298304
llmod,
299-
llvm::LLVMModFlagBehavior::Error,
305+
behavior,
300306
"sign-return-address-all\0".as_ptr().cast(),
301307
pac_opts.leaf.into(),
302308
);
303309
llvm::LLVMRustAddModuleFlag(
304310
llmod,
305-
llvm::LLVMModFlagBehavior::Error,
311+
behavior,
306312
"sign-return-address-with-bkey\0".as_ptr().cast(),
307313
u32::from(pac_opts.key == PAuthKey::B),
308314
);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub enum LLVMModFlagBehavior {
7979
Append = 5,
8080
AppendUnique = 6,
8181
Max = 7,
82+
Min = 8,
8283
}
8384

8485
// Consts for the LLVM CallConv type, pre-cast to usize.

0 commit comments

Comments
 (0)