Skip to content

Commit 1cf7af3

Browse files
Darksonnojeda
authored andcommitted
Add -Zindirect-branch-cs-prefix (from draft PR)
1 parent 2c1ac85 commit 1cf7af3

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
@@ -463,6 +463,15 @@ pub(crate) unsafe fn create_module<'ll>(
463463
}
464464
}
465465

466+
if sess.opts.unstable_opts.indirect_branch_cs_prefix {
467+
llvm::add_module_flag_u32(
468+
llmod,
469+
llvm::ModuleFlagMergeBehavior::Override,
470+
"indirect_branch_cs_prefix",
471+
1,
472+
);
473+
}
474+
466475
match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
467476
{
468477
// 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
@@ -807,6 +807,7 @@ fn test_unstable_options_tracking_hash() {
807807
tracked!(hint_mostly_unused, true);
808808
tracked!(human_readable_cgu_names, true);
809809
tracked!(incremental_ignore_spans, true);
810+
tracked!(indirect_branch_cs_prefix, true);
810811
tracked!(inline_mir, Some(true));
811812
tracked!(inline_mir_hint_threshold, Some(123));
812813
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
@@ -2295,6 +2295,8 @@ options! {
22952295
- hashes of green query instances
22962296
- hash collisions of query keys
22972297
- hash collisions when creating dep-nodes"),
2298+
indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2299+
"add cs prefix to call and jmp to indirect thunk (default: no)"),
22982300
inline_llvm: bool = (true, parse_bool, [TRACKED],
22992301
"enable LLVM inlining (default: yes)"),
23002302
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)