Skip to content

Commit fa0e75e

Browse files
Darksonnojeda
authored andcommitted
Add -Zindirect-branch-cs-prefix
1 parent fcb32d7 commit fa0e75e

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+9
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,15 @@ pub(crate) unsafe fn create_module<'ll>(
443443
}
444444
}
445445

446+
if sess.opts.unstable_opts.indirect_branch_cs_prefix {
447+
llvm::add_module_flag_u32(
448+
llmod,
449+
llvm::ModuleFlagMergeBehavior::Override,
450+
"indirect_branch_cs_prefix",
451+
1,
452+
);
453+
}
454+
446455
match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
447456
{
448457
// Set up the small-data optimization limit for architectures that use

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ fn test_unstable_options_tracking_hash() {
802802
tracked!(function_sections, Some(false));
803803
tracked!(human_readable_cgu_names, true);
804804
tracked!(incremental_ignore_spans, true);
805+
tracked!(indirect_branch_cs_prefix, true);
805806
tracked!(inline_mir, Some(true));
806807
tracked!(inline_mir_hint_threshold, Some(123));
807808
tracked!(inline_mir_threshold, Some(123));

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,8 @@ options! {
22862286
- hashes of green query instances
22872287
- hash collisions of query keys
22882288
- hash collisions when creating dep-nodes"),
2289+
indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2290+
"add cs prefix to call and jmp to indirect thunk (default: no)"),
22892291
inline_llvm: bool = (true, parse_bool, [TRACKED],
22902292
"enable LLVM inlining (default: yes)"),
22912293
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that the `indirect_branch_cs_prefix` module attribute is (not) emitted when the
2+
// `-Zindirect-branch-cs-prefix` flag is (not) set.
3+
4+
//@ add-core-stubs
5+
//@ revisions: unset set
6+
//@ needs-llvm-components: x86
7+
//@ compile-flags: --target x86_64-unknown-linux-gnu
8+
//@ [set] compile-flags: -Zindirect-branch-cs-prefix
9+
10+
#![crate_type = "lib"]
11+
#![feature(no_core, lang_items)]
12+
#![no_core]
13+
14+
#[lang = "sized"]
15+
trait Sized {}
16+
17+
// unset-NOT: !{{[0-9]+}} = !{i32 4, !"indirect_branch_cs_prefix", i32 1}
18+
// set: !{{[0-9]+}} = !{i32 4, !"indirect_branch_cs_prefix", i32 1}

0 commit comments

Comments
 (0)