Skip to content

Commit 352b505

Browse files
committed
tests: add pac-ret + cross-language lto test
Add a test confirming that `-Zbranch-protection=pac-ret` and cross-language LTO work together.
1 parent 105961e commit 352b505

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
2+
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
3+
// This test checks that compilation and execution is successful when this feature is activated,
4+
// with some of its possible extra arguments (bti, pac-ret, leaf) when doing LTO.
5+
// See https://github.com/rust-lang/rust/pull/88354
6+
7+
//@ needs-force-clang-based-tests
8+
//@ only-aarch64
9+
// Reason: branch protection is not supported on other architectures
10+
//@ ignore-cross-compile
11+
// Reason: the compiled binary is executed
12+
13+
use run_make_support::{clang, env_var, llvm_ar, run, rustc, static_lib_name};
14+
15+
fn main() {
16+
clang()
17+
.arg("-v")
18+
.lto("thin")
19+
.arg("-mbranch-protection=bti+pac-ret+leaf")
20+
.arg("-O2")
21+
.arg("-c")
22+
.out_exe("test.o")
23+
.input("test.c")
24+
.run();
25+
llvm_ar().obj_to_ar().output_input(static_lib_name("test"), "test.o").run();
26+
rustc()
27+
.linker_plugin_lto("on")
28+
.opt_level("2")
29+
.linker(&env_var("CLANG"))
30+
.link_arg("-fuse-ld=lld")
31+
.arg("-Zbranch-protection=bti,pac-ret,leaf")
32+
.input("test.rs")
33+
.output("test.bin")
34+
.run();
35+
run("test.bin");
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[link(name = "test")]
2+
extern "C" {
3+
fn foo() -> i32;
4+
}
5+
6+
fn main() {
7+
unsafe {
8+
foo();
9+
}
10+
}

0 commit comments

Comments
 (0)