Skip to content

Commit ab4a887

Browse files
committed
Rename -Zno-jump-tables to -Zjump-tables=<bool>
Both gcc and llvm accept -fjump-tables as well as -fno-jump-tables. For consistency, allow rustc to accept -Zjump-tables=yes too.
1 parent dc2c356 commit ab4a887

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn instrument_function_attr<'ll>(
228228
}
229229

230230
fn nojumptables_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll Attribute> {
231-
if !sess.opts.unstable_opts.no_jump_tables {
231+
if sess.opts.unstable_opts.jump_tables {
232232
return None;
233233
}
234234

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ fn test_unstable_options_tracking_hash() {
815815
tracked!(inline_mir_threshold, Some(123));
816816
tracked!(instrument_mcount, true);
817817
tracked!(instrument_xray, Some(InstrumentXRay::default()));
818+
tracked!(jump_tables, false);
818819
tracked!(link_directives, false);
819820
tracked!(link_only, true);
820821
tracked!(lint_llvm_ir, true);
@@ -832,7 +833,6 @@ fn test_unstable_options_tracking_hash() {
832833
tracked!(mutable_noalias, false);
833834
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
834835
tracked!(no_generate_arange_section, true);
835-
tracked!(no_jump_tables, true);
836836
tracked!(no_link, true);
837837
tracked!(no_profiler_runtime, true);
838838
tracked!(no_trait_vptr, true);

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,8 @@ options! {
23952395
`=skip-entry`
23962396
`=skip-exit`
23972397
Multiple options can be combined with commas."),
2398+
jump_tables: bool = (true, parse_bool, [TRACKED],
2399+
"Allow jump table and lookup table generation from switch case lowering (default: yes)"),
23982400
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
23992401
"seed layout randomization"),
24002402
link_directives: bool = (true, parse_bool, [TRACKED],
@@ -2475,8 +2477,6 @@ options! {
24752477
"omit DWARF address ranges that give faster lookups"),
24762478
no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
24772479
"disable the compatibility version of the `implied_bounds_ty` query"),
2478-
no_jump_tables: bool = (false, parse_no_value, [TRACKED],
2479-
"disable the jump tables and lookup tables that can be generated from a switch case lowering"),
24802480
no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
24812481
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
24822482
no_link: bool = (false, parse_no_value, [TRACKED],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# `jump-tables`
2+
3+
The tracking issue for this feature is [#116592](https://github.com/rust-lang/rust/issues/116592)
4+
5+
---
6+
7+
When set to no, this option enables the `-fno-jump-tables` flag for LLVM, which makes the
8+
codegen backend avoid generating jump tables when lowering switches.
9+
10+
When set to no, this option adds the LLVM `no-jump-tables=true` attribute to every function.
11+
12+
Disabling jump tables can be used to help provide protection against
13+
jump-oriented-programming (JOP) attacks, such as with the linux kernel's [IBT].
14+
15+
```sh
16+
RUSTFLAGS="-Zjump-tables=no" cargo +nightly build -Z build-std
17+
```
18+
19+
[IBT]: https://www.phoronix.com/news/Linux-IBT-By-Default-Tip

src/doc/unstable-book/src/compiler-flags/no-jump-tables.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/assembly-llvm/x86_64-no-jump-tables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Test that jump tables are (not) emitted when the `-Zno-jump-tables`
1+
// Test that jump tables are (not) emitted when the `-Zjump-tables=no`
22
// flag is (not) set.
33

44
//@ revisions: unset set
55
//@ assembly-output: emit-asm
66
//@ compile-flags: -Copt-level=3
7-
//@ [set] compile-flags: -Zno-jump-tables
7+
//@ [set] compile-flags: -Zjump-tables=no
88
//@ only-x86_64
99
//@ ignore-sgx
1010

tests/codegen-llvm/no-jump-tables.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Test that the `no-jump-tables` function attribute are (not) emitted when
2-
// the `-Zno-jump-tables` flag is (not) set.
2+
// the `-Zjump-tables=no` flag is (not) set.
33

44
//@ add-core-stubs
5-
//@ revisions: unset set
5+
//@ revisions: unset set_no set_yes
66
//@ needs-llvm-components: x86
77
//@ compile-flags: --target x86_64-unknown-linux-gnu
8-
//@ [set] compile-flags: -Zno-jump-tables
8+
//@ [set_no] compile-flags: -Zjump-tables=no
9+
//@ [set_yes] compile-flags: -Zjump-tables=yes
910

1011
#![crate_type = "lib"]
1112
#![feature(no_core, lang_items)]
@@ -19,5 +20,6 @@ pub fn foo() {
1920
// CHECK: @foo() unnamed_addr #0
2021

2122
// unset-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
22-
// set: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
23+
// set_yes-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
24+
// set_no: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
2325
}

0 commit comments

Comments
 (0)