diff options
| author | Miguel Ojeda <ojeda@kernel.org> | 2023-10-18 16:58:17 +0200 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2023-11-30 20:21:31 +0100 |
| commit | 2d476222e8458aa873e6760aac189b5e9d0a9930 (patch) | |
| tree | e6bbad1f875d945ccaf1abb5f67d35b7f57a761a /tests/codegen/function-return.rs | |
| parent | d3c9964c2037034b42dac7ad40e9950de3063fd8 (diff) | |
| download | rust-2d476222e8458aa873e6760aac189b5e9d0a9930.tar.gz rust-2d476222e8458aa873e6760aac189b5e9d0a9930.zip | |
Add `-Zfunction-return={keep,thunk-extern}` option
This is intended to be used for Linux kernel RETHUNK builds. With this commit (optionally backported to Rust 1.73.0), plus a patched Linux kernel to pass the flag, I get a RETHUNK build with Rust enabled that is `objtool`-warning-free and is able to boot in QEMU and load a sample Rust kernel module. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'tests/codegen/function-return.rs')
| -rw-r--r-- | tests/codegen/function-return.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/codegen/function-return.rs b/tests/codegen/function-return.rs new file mode 100644 index 00000000000..d832d19ac39 --- /dev/null +++ b/tests/codegen/function-return.rs @@ -0,0 +1,28 @@ +// Test that the `fn_ret_thunk_extern` function attribute is (not) emitted when +// the `-Zfunction-return={keep,thunk-extern}` flag is (not) set. + +// revisions: unset keep thunk-extern keep-thunk-extern thunk-extern-keep +// needs-llvm-components: x86 +// compile-flags: --target x86_64-unknown-linux-gnu +// [keep] compile-flags: -Zfunction-return=keep +// [thunk-extern] compile-flags: -Zfunction-return=thunk-extern +// [keep-thunk-extern] compile-flags: -Zfunction-return=keep -Zfunction-return=thunk-extern +// [thunk-extern-keep] compile-flags: -Zfunction-return=thunk-extern -Zfunction-return=keep + +#![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: fn_ret_thunk_extern + // keep-NOT: fn_ret_thunk_extern + // thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} } + // keep-thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} } + // thunk-extern-keep-NOT: fn_ret_thunk_extern +} |
