mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
tests: add pac-ret + cross-language lto test
Add a test confirming that `-Zbranch-protection=pac-ret` and cross-language LTO work together.
This commit is contained in:
parent
105961ecb4
commit
352b505f80
36
tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs
Normal file
36
tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
|
||||
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
|
||||
// This test checks that compilation and execution is successful when this feature is activated,
|
||||
// with some of its possible extra arguments (bti, pac-ret, leaf) when doing LTO.
|
||||
// See https://github.com/rust-lang/rust/pull/88354
|
||||
|
||||
//@ needs-force-clang-based-tests
|
||||
//@ only-aarch64
|
||||
// Reason: branch protection is not supported on other architectures
|
||||
//@ ignore-cross-compile
|
||||
// Reason: the compiled binary is executed
|
||||
|
||||
use run_make_support::{clang, env_var, llvm_ar, run, rustc, static_lib_name};
|
||||
|
||||
fn main() {
|
||||
clang()
|
||||
.arg("-v")
|
||||
.lto("thin")
|
||||
.arg("-mbranch-protection=bti+pac-ret+leaf")
|
||||
.arg("-O2")
|
||||
.arg("-c")
|
||||
.out_exe("test.o")
|
||||
.input("test.c")
|
||||
.run();
|
||||
llvm_ar().obj_to_ar().output_input(static_lib_name("test"), "test.o").run();
|
||||
rustc()
|
||||
.linker_plugin_lto("on")
|
||||
.opt_level("2")
|
||||
.linker(&env_var("CLANG"))
|
||||
.link_arg("-fuse-ld=lld")
|
||||
.arg("-Zbranch-protection=bti,pac-ret,leaf")
|
||||
.input("test.rs")
|
||||
.output("test.bin")
|
||||
.run();
|
||||
run("test.bin");
|
||||
}
|
1
tests/run-make/pointer-auth-link-with-c-lto-clang/test.c
Normal file
1
tests/run-make/pointer-auth-link-with-c-lto-clang/test.c
Normal file
@ -0,0 +1 @@
|
||||
int foo() { return 0; }
|
10
tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs
Normal file
10
tests/run-make/pointer-auth-link-with-c-lto-clang/test.rs
Normal file
@ -0,0 +1,10 @@
|
||||
#[link(name = "test")]
|
||||
extern "C" {
|
||||
fn foo() -> i32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
foo();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user