Stabilize -Zjump-tables=<bool> into -Cjump-table=<bool>

This commit is contained in:
Paul Murphy 2025-08-28 15:22:35 -05:00
parent 4959d18a97
commit bb9d800b78
7 changed files with 22 additions and 28 deletions

View file

@ -229,7 +229,7 @@ fn instrument_function_attr<'ll>(
}
fn nojumptables_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll Attribute> {
if sess.opts.unstable_opts.jump_tables {
if sess.opts.cg.jump_tables {
return None;
}

View file

@ -620,6 +620,7 @@ fn test_codegen_options_tracking_hash() {
tracked!(force_frame_pointers, FramePointer::Always);
tracked!(force_unwind_tables, Some(true));
tracked!(instrument_coverage, InstrumentCoverage::Yes);
tracked!(jump_tables, false);
tracked!(link_dead_code, Some(true));
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
@ -814,7 +815,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(inline_mir_threshold, Some(123));
tracked!(instrument_mcount, true);
tracked!(instrument_xray, Some(InstrumentXRay::default()));
tracked!(jump_tables, false);
tracked!(link_directives, false);
tracked!(link_only, true);
tracked!(lint_llvm_ir, true);

View file

@ -2093,6 +2093,8 @@ options! {
"instrument the generated code to support LLVM source-based code coverage reports \
(note, the compiler build config must include `profiler = true`); \
implies `-C symbol-mangling-version=v0`"),
jump_tables: bool = (true, parse_bool, [TRACKED],
"allow jump table and lookup table generation from switch case lowering (default: yes)"),
link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
"a single extra argument to append to the linker invocation (can be used several times)"),
link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
@ -2395,8 +2397,6 @@ options! {
`=skip-entry`
`=skip-exit`
Multiple options can be combined with commas."),
jump_tables: bool = (true, parse_bool, [TRACKED],
"allow jump table and lookup table generation from switch case lowering (default: yes)"),
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
"seed layout randomization"),
link_directives: bool = (true, parse_bool, [TRACKED],

View file

@ -209,6 +209,19 @@ Note that while the `-C instrument-coverage` option is stable, the profile data
format produced by the resulting instrumentation may change, and may not work
with coverage tools other than those built and shipped with the compiler.
## jump-tables
This option is used to allow or prevent the LLVM codegen backend from creating
jump tables when lowering switches.
* `y`, `yes`, `on`, `true` or no value: allow jump tables (the default).
* `n`, `no`, `off` or `false`: disable jump tables.
Disabling jump tables can be used to help provide protection against
jump-oriented-programming (JOP) attacks. However, this option makes
no guarantee any precompiled or external dependencies are compiled
with or without jump tables.
## link-arg
This flag lets you append a single extra argument to the linker invocation.

View file

@ -1,19 +0,0 @@
# `jump-tables`
The tracking issue for this feature is [#116592](https://github.com/rust-lang/rust/issues/116592)
---
When set to no, this option enables the `-fno-jump-tables` flag for LLVM, which makes the
codegen backend avoid generating jump tables when lowering switches.
When set to no, this option adds the LLVM `no-jump-tables=true` attribute to every function.
Disabling jump tables can be used to help provide protection against
jump-oriented-programming (JOP) attacks, such as with the linux kernel's [IBT].
```sh
RUSTFLAGS="-Zjump-tables=no" cargo +nightly build -Z build-std
```
[IBT]: https://www.phoronix.com/news/Linux-IBT-By-Default-Tip

View file

@ -1,10 +1,10 @@
// Test that jump tables are (not) emitted when the `-Zjump-tables=no`
// Test that jump tables are (not) emitted when the `-Cjump-tables=no`
// flag is (not) set.
//@ revisions: unset set
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=3
//@ [set] compile-flags: -Zjump-tables=no
//@ [set] compile-flags: -Cjump-tables=no
//@ only-x86_64
//@ ignore-sgx

View file

@ -1,12 +1,12 @@
// Test that the `no-jump-tables` function attribute are (not) emitted when
// the `-Zjump-tables=no` flag is (not) set.
// the `-Cjump-tables=no` flag is (not) set.
//@ add-minicore
//@ revisions: unset set_no set_yes
//@ needs-llvm-components: x86
//@ compile-flags: --target x86_64-unknown-linux-gnu
//@ [set_no] compile-flags: -Zjump-tables=no
//@ [set_yes] compile-flags: -Zjump-tables=yes
//@ [set_no] compile-flags: -Cjump-tables=no
//@ [set_yes] compile-flags: -Cjump-tables=yes
#![crate_type = "lib"]
#![feature(no_core, lang_items)]