Skip to content

Commit e642e09

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 3c91be7 commit e642e09

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
@@ -208,7 +208,7 @@ fn instrument_function_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'ll Attr
208208
}
209209

210210
fn nojumptables_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute> {
211-
if !cx.sess().opts.unstable_opts.no_jump_tables {
211+
if cx.sess().opts.unstable_opts.jump_tables {
212212
return None;
213213
}
214214

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ fn test_unstable_options_tracking_hash() {
813813
tracked!(inline_mir_threshold, Some(123));
814814
tracked!(instrument_mcount, true);
815815
tracked!(instrument_xray, Some(InstrumentXRay::default()));
816+
tracked!(jump_tables, false);
816817
tracked!(link_directives, false);
817818
tracked!(link_only, true);
818819
tracked!(lint_llvm_ir, true);
@@ -830,7 +831,6 @@ fn test_unstable_options_tracking_hash() {
830831
tracked!(mutable_noalias, false);
831832
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
832833
tracked!(no_generate_arange_section, true);
833-
tracked!(no_jump_tables, true);
834834
tracked!(no_link, true);
835835
tracked!(no_profiler_runtime, true);
836836
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
@@ -2324,6 +2324,8 @@ options! {
23242324
`=skip-entry`
23252325
`=skip-exit`
23262326
Multiple options can be combined with commas."),
2327+
jump_tables: bool = (true, parse_bool, [TRACKED],
2328+
"Allow jump table and lookup table generation from switch case lowering (default: yes)"),
23272329
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
23282330
"seed layout randomization"),
23292331
link_directives: bool = (true, parse_bool, [TRACKED],
@@ -2404,8 +2406,6 @@ options! {
24042406
"omit DWARF address ranges that give faster lookups"),
24052407
no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
24062408
"disable the compatibility version of the `implied_bounds_ty` query"),
2407-
no_jump_tables: bool = (false, parse_no_value, [TRACKED],
2408-
"disable the jump tables and lookup tables that can be generated from a switch case lowering"),
24092409
no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
24102410
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
24112411
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)