Skip to content

Commit 056ca5d

Browse files
committed
Stabilize -Zjump-tables=<bool> into -Cjump-table=<bool>
1 parent ab4a887 commit 056ca5d

File tree

7 files changed

+22
-28
lines changed

7 files changed

+22
-28
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.jump_tables {
231+
if sess.opts.cg.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
@@ -621,6 +621,7 @@ fn test_codegen_options_tracking_hash() {
621621
tracked!(force_frame_pointers, FramePointer::Always);
622622
tracked!(force_unwind_tables, Some(true));
623623
tracked!(instrument_coverage, InstrumentCoverage::Yes);
624+
tracked!(jump_tables, false);
624625
tracked!(link_dead_code, Some(true));
625626
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
626627
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
@@ -815,7 +816,6 @@ fn test_unstable_options_tracking_hash() {
815816
tracked!(inline_mir_threshold, Some(123));
816817
tracked!(instrument_mcount, true);
817818
tracked!(instrument_xray, Some(InstrumentXRay::default()));
818-
tracked!(jump_tables, false);
819819
tracked!(link_directives, false);
820820
tracked!(link_only, true);
821821
tracked!(lint_llvm_ir, true);

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ options! {
20932093
"instrument the generated code to support LLVM source-based code coverage reports \
20942094
(note, the compiler build config must include `profiler = true`); \
20952095
implies `-C symbol-mangling-version=v0`"),
2096+
jump_tables: bool = (true, parse_bool, [TRACKED],
2097+
"Allow jump table and lookup table generation from switch case lowering (default: yes)"),
20962098
link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
20972099
"a single extra argument to append to the linker invocation (can be used several times)"),
20982100
link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
@@ -2395,8 +2397,6 @@ options! {
23952397
`=skip-entry`
23962398
`=skip-exit`
23972399
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)"),
24002400
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
24012401
"seed layout randomization"),
24022402
link_directives: bool = (true, parse_bool, [TRACKED],

src/doc/rustc/src/codegen-options/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ Note that while the `-C instrument-coverage` option is stable, the profile data
209209
format produced by the resulting instrumentation may change, and may not work
210210
with coverage tools other than those built and shipped with the compiler.
211211

212+
## jump-tables
213+
214+
This option is used to allow or prevent the LLVM codegen backend from creating
215+
jump tables when lowering switches.
216+
217+
* `y`, `yes`, `on`, `true` or no value: allow jump tables (the default).
218+
* `n`, `no`, `off` or `false`: disable jump tables.
219+
220+
Disabling jump tables can be used to help provide protection against
221+
jump-oriented-programming (JOP) attacks. However, this option makes
222+
no guarantee any precompiled or external dependencies are compiled
223+
with or without jump tables.
224+
212225
## link-arg
213226

214227
This flag lets you append a single extra argument to the linker invocation.

src/doc/unstable-book/src/compiler-flags/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 `-Zjump-tables=no`
1+
// Test that jump tables are (not) emitted when the `-Cjump-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: -Zjump-tables=no
7+
//@ [set] compile-flags: -Cjump-tables=no
88
//@ only-x86_64
99
//@ ignore-sgx
1010

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

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

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

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

0 commit comments

Comments
 (0)