Skip to content

Commit 1437559

Browse files
Darksonnojeda
authored andcommitted
Add -Zindirect-branch-cs-prefix (from draft PR)
1 parent 75e7cf5 commit 1437559

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,15 @@ pub(crate) unsafe fn create_module<'ll>(
451451
}
452452
}
453453

454+
if sess.opts.unstable_opts.indirect_branch_cs_prefix {
455+
llvm::add_module_flag_u32(
456+
llmod,
457+
llvm::ModuleFlagMergeBehavior::Override,
458+
"indirect_branch_cs_prefix",
459+
1,
460+
);
461+
}
462+
454463
match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
455464
{
456465
// Set up the small-data optimization limit for architectures that use

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ fn test_unstable_options_tracking_hash() {
804804
tracked!(function_sections, Some(false));
805805
tracked!(human_readable_cgu_names, true);
806806
tracked!(incremental_ignore_spans, true);
807+
tracked!(indirect_branch_cs_prefix, true);
807808
tracked!(inline_mir, Some(true));
808809
tracked!(inline_mir_hint_threshold, Some(123));
809810
tracked!(inline_mir_threshold, Some(123));

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,8 @@ options! {
22572257
- hashes of green query instances
22582258
- hash collisions of query keys
22592259
- hash collisions when creating dep-nodes"),
2260+
indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2261+
"add cs prefix to call and jmp to indirect thunk (default: no)"),
22602262
inline_llvm: bool = (true, parse_bool, [TRACKED],
22612263
"enable LLVM inlining (default: yes)"),
22622264
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
Lines changed: 18 additions & 0 deletions
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)