Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1437559
Add -Zindirect-branch-cs-prefix (from draft PR)
Darksonn May 7, 2025
5d6ec1e
Add `-Zindirect-branch-cs-prefix` option
ojeda May 7, 2025
24c770b
aarch64: Make `outline-atomics` a known target feature
tgross35 Aug 1, 2025
566cdab
Clarify `value_path_str_with_args`.
nnethercote Aug 1, 2025
b0c36dd
Rename most of the printers.
nnethercote Aug 1, 2025
d76eef4
Simplify multiple things.
nnethercote Aug 1, 2025
070425e
Add aarch64_be-unknown-none-softfloat target
Gelbpunkt Aug 5, 2025
dfd38f0
Add comments to `Printer`.
nnethercote Aug 1, 2025
69bcd79
Move `should_truncate` from trait `Printer` to sub-trait `PrettyPrint…
nnethercote Aug 3, 2025
b8adda6
Rename some `Printer` methods.
nnethercote Aug 3, 2025
42a1042
Rename some `PrettyPrinter` methods.
nnethercote Aug 3, 2025
378dd7c
Add regression test for former ICE involving malformed meta items con…
fmease Aug 11, 2025
2563e4a
[AVR] Changed data_layout
tomtor Aug 11, 2025
db1a64c
simplify stack handling, be completely lazy
lcnr Aug 5, 2025
0b855bc
Switch to a bitflags `MacroKinds` to support macros with more than on…
joshtriplett Aug 8, 2025
d7b30be
Expand documentation of `GlobDelegation`
joshtriplett Aug 9, 2025
c81fcac
Only suggest changing `#[derive(mymacro)]` to `#[mymacro]` for attrib…
joshtriplett Aug 9, 2025
ba231db
Detect and report macro kind mismatches early, and more precisely
joshtriplett Aug 9, 2025
b74e1cb
mbe: Rename macro parsing state names to use `Bang` instead of `Not`
joshtriplett Aug 9, 2025
33ba4a2
clippy: Update for switch to `MacroKinds`
joshtriplett Aug 9, 2025
e1fc89a
rustdoc: Minimal fixes to compile with `MacroKinds`
joshtriplett Aug 9, 2025
95c651d
Remove `ONLY_HOSTS` value overrides that just set the default value a…
Kobzol Aug 12, 2025
a43def7
Rename and document `ONLY_HOSTS` in bootstrap
Kobzol Aug 12, 2025
cd79c71
Correctly handle when there are no unstable items in the documented c…
GuillaumeGomez Aug 13, 2025
dc0707a
Add another example for escaped `#` character in doctest in rustdoc book
GuillaumeGomez Aug 13, 2025
6c96c94
Add missing entry in STAGE0_MISSING_TARGETS
Gelbpunkt Aug 13, 2025
945b5df
Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco
GuillaumeGomez Aug 13, 2025
2da75af
Rollup merge of #144761 - tgross35:cfg-outline-atomics, r=davidtwco
GuillaumeGomez Aug 13, 2025
e8261fb
Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwco
GuillaumeGomez Aug 13, 2025
9b5ff0e
Rollup merge of #144955 - lcnr:lazily-update-non-parent-goals, r=BoxyUwU
GuillaumeGomez Aug 13, 2025
58130ee
Rollup merge of #144962 - Gelbpunkt:aarch64_be-unknown-none-softfloat…
GuillaumeGomez Aug 13, 2025
4288e19
Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petroche…
GuillaumeGomez Aug 13, 2025
58201d2
Rollup merge of #145241 - tomtor:avr-layout, r=nikic
GuillaumeGomez Aug 13, 2025
fe29e7b
Rollup merge of #145250 - fmease:regr-test-for-attr-meta-ice, r=jdons…
GuillaumeGomez Aug 13, 2025
0531431
Rollup merge of #145324 - Kobzol:bootstrap-host-only, r=jieyouxu
GuillaumeGomez Aug 13, 2025
f66f868
Rollup merge of #145349 - GuillaumeGomez:unstable-items-search, r=lol…
GuillaumeGomez Aug 13, 2025
630e0ed
Rollup merge of #145356 - GuillaumeGomez:doctest-escaped, r=fmease
GuillaumeGomez Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

if sess.opts.unstable_opts.indirect_branch_cs_prefix {
llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Override,
"indirect_branch_cs_prefix",
1,
);
}

match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support())
{
// Set up the small-data optimization limit for architectures that use
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(hint_mostly_unused, true);
tracked!(human_readable_cgu_names, true);
tracked!(incremental_ignore_spans, true);
tracked!(indirect_branch_cs_prefix, true);
tracked!(inline_mir, Some(true));
tracked!(inline_mir_hint_threshold, Some(123));
tracked!(inline_mir_threshold, Some(123));
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ session_hexadecimal_float_literal_not_supported = hexadecimal float literal is n
session_incompatible_linker_flavor = linker flavor `{$flavor}` is incompatible with the current target
.note = compatible flavors are: {$compatible_list}

session_indirect_branch_cs_prefix_requires_x86_or_x86_64 = `-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64

session_instrumentation_not_supported = {$us} instrumentation is not supported for this target

session_int_literal_too_large = integer literal is too large
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ pub(crate) struct FunctionReturnRequiresX86OrX8664;
#[diag(session_function_return_thunk_extern_requires_non_large_code_model)]
pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel;

#[derive(Diagnostic)]
#[diag(session_indirect_branch_cs_prefix_requires_x86_or_x86_64)]
pub(crate) struct IndirectBranchCsPrefixRequiresX86OrX8664;

#[derive(Diagnostic)]
#[diag(session_unsupported_regparm)]
pub(crate) struct UnsupportedRegparm {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,8 @@ options! {
- hashes of green query instances
- hash collisions of query keys
- hash collisions when creating dep-nodes"),
indirect_branch_cs_prefix: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
"add `cs` prefix to `call` and `jmp` to indirect thunks (default: no)"),
inline_llvm: bool = (true, parse_bool, [TRACKED],
"enable LLVM inlining (default: yes)"),
inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,12 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
}
}

if sess.opts.unstable_opts.indirect_branch_cs_prefix {
if sess.target.arch != "x86" && sess.target.arch != "x86_64" {
sess.dcx().emit_err(errors::IndirectBranchCsPrefixRequiresX86OrX8664);
}
}

if let Some(regparm) = sess.opts.unstable_opts.regparm {
if regparm > 3 {
sess.dcx().emit_err(errors::UnsupportedRegparm { regparm });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `indirect-branch-cs-prefix`

The tracking issue for this feature is: https://github.com/rust-lang/rust/issues/116852.

------------------------

Option `-Zindirect-branch-cs-prefix` controls whether a `cs` prefix is added to
`call` and `jmp` to indirect thunks.

It is equivalent to [Clang]'s and [GCC]'s `-mindirect-branch-cs-prefix`. The
Linux kernel uses it for RETPOLINE builds. For details, see
[LLVM commit 6f867f910283] ("[X86] Support ``-mindirect-branch-cs-prefix`` for
call and jmp to indirect thunk") which introduces the feature.

Only x86 and x86_64 are supported.

[Clang]: https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mindirect-branch-cs-prefix
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mindirect-branch-cs-prefix
[LLVM commit 6f867f910283]: https://github.com/llvm/llvm-project/commit/6f867f9102838ebe314c1f3661fdf95700386e5a
26 changes: 26 additions & 0 deletions tests/assembly/x86_64-indirect-branch-cs-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Test that the `cs` prefix is (not) added into a `call` and a `jmp` to the
// indirect thunk when the `-Zindirect-branch-cs-prefix` flag is (not) set.

//@ revisions: unset set
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=3 -Cunsafe-allow-abi-mismatch=retpoline,retpoline-external-thunk,indirect-branch-cs-prefix -Zretpoline-external-thunk
//@ [set] compile-flags: -Zindirect-branch-cs-prefix
//@ only-x86_64

#![crate_type = "lib"]

// CHECK-LABEL: foo:
#[no_mangle]
pub fn foo(g: fn()) {
// unset-NOT: cs
// unset: callq {{__x86_indirect_thunk.*}}
// set: cs
// set-NEXT: callq {{__x86_indirect_thunk.*}}
g();

// unset-NOT: cs
// unset: jmp {{__x86_indirect_thunk.*}}
// set: cs
// set-NEXT: jmp {{__x86_indirect_thunk.*}}
g();
}
18 changes: 18 additions & 0 deletions tests/codegen/indirect-branch-cs-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Test that the `indirect_branch_cs_prefix` module attribute is (not)
// emitted when the `-Zindirect-branch-cs-prefix` flag is (not) set.

//@ add-core-stubs
//@ revisions: unset set
//@ needs-llvm-components: x86
//@ compile-flags: --target x86_64-unknown-linux-gnu
//@ [set] compile-flags: -Zindirect-branch-cs-prefix

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
#![no_core]

extern crate minicore;
use minicore::*;

// unset-NOT: !{{[0-9]+}} = !{i32 4, !"indirect_branch_cs_prefix", i32 1}
// set: !{{[0-9]+}} = !{i32 4, !"indirect_branch_cs_prefix", i32 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: `-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ revisions: x86 x86_64 aarch64

//@ compile-flags: -Zindirect-branch-cs-prefix

//@[x86] check-pass
//@[x86] needs-llvm-components: x86
//@[x86] compile-flags: --target i686-unknown-linux-gnu

//@[x86_64] check-pass
//@[x86_64] needs-llvm-components: x86
//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu

//@[aarch64] check-fail
//@[aarch64] needs-llvm-components: aarch64
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu

#![feature(no_core)]
#![no_core]
#![no_main]

//[aarch64]~? ERROR `-Zindirect-branch-cs-prefix` is only supported on x86 and x86_64