-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This flag mimics GCC/Clang's `-fno-jump-tables` [1][2], which makes the codegen backend avoid generating jump tables when lowering switches. In the case of LLVM, the `"no-jump-tables"="true"` function attribute is added to every function. The kernel currently needs it for x86 when enabling IBT [3], as well as for Alpha (plus VDSO objects in MIPS/LoongArch). [1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fno-jump-tables [2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fjump-tables [3] https://github.com/torvalds/linux/blob/v6.1/arch/x86/Makefile#L75-L83 Signed-off-by: Miguel Ojeda <[email protected]>
- Loading branch information
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Test that jump tables are (not) emitted when the `-Zno-jump-tables` | ||
// flag is (not) set. | ||
|
||
// revisions: unset set | ||
// assembly-output: emit-asm | ||
// compile-flags: -O | ||
// [set] compile-flags: -Zno-jump-tables | ||
// only-x86_64 | ||
|
||
#![crate_type = "lib"] | ||
|
||
extern "C" { | ||
fn bar1(); | ||
fn bar2(); | ||
fn bar3(); | ||
fn bar4(); | ||
fn bar5(); | ||
fn bar6(); | ||
} | ||
|
||
// CHECK-LABEL: foo: | ||
#[no_mangle] | ||
pub unsafe fn foo(x: i32) { | ||
// unset: LJTI0_0 | ||
// set-NOT: LJTI0_0 | ||
match x { | ||
1 => bar1(), | ||
2 => bar2(), | ||
3 => bar3(), | ||
4 => bar4(), | ||
5 => bar5(), | ||
_ => bar6(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Test that the `no-jump-tables` function attribute are (not) emitted when | ||
// the `-Zno-jump-tables` flag is (not) set. | ||
|
||
// revisions: unset set | ||
// needs-llvm-components: x86 | ||
// compile-flags: --target x86_64-unknown-linux-gnu | ||
// [set] compile-flags: -Zno-jump-tables | ||
|
||
#![crate_type = "lib"] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[no_mangle] | ||
pub fn foo() { | ||
// CHECK: @foo() unnamed_addr #0 | ||
|
||
// unset-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} } | ||
// set: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters