Extends branch protection tests to include GCS

This commit is contained in:
Reuben Cruise 2025-09-02 16:13:51 +01:00
parent 6f813e887a
commit 06819d95c0
6 changed files with 23 additions and 11 deletions

View file

@ -1,10 +1,13 @@
// Test that PAC instructions are emitted when branch-protection is specified.
//@ add-core-stubs
//@ revisions: PACRET PAUTHLR_NOP PAUTHLR
//@ revisions: GCS PACRET PAUTHLR_NOP PAUTHLR
//@ assembly-output: emit-asm
//@ needs-llvm-components: aarch64
//@ compile-flags: --target aarch64-unknown-linux-gnu
//@ [GCS] min-llvm-version: 21
//@ [GCS] ignore-apple (XCode version needs updating)
//@ [GCS] compile-flags: -Z branch-protection=gcs
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret,leaf
//@ [PAUTHLR_NOP] compile-flags: -Z branch-protection=pac-ret,pc,leaf
//@ [PAUTHLR] compile-flags: -C target-feature=+pauth-lr -Z branch-protection=pac-ret,pc,leaf
@ -17,6 +20,7 @@
extern crate minicore;
use minicore::*;
// GCS: .aeabi_attribute 2, 1 // Tag_Feature_GCS
// PACRET: hint #25
// PACRET: hint #29
// PAUTHLR_NOP: hint #25

View file

@ -1,9 +1,10 @@
// Test that the correct module flags are emitted with different branch protection flags.
//@ add-core-stubs
//@ revisions: BTI PACRET LEAF BKEY PAUTHLR PAUTHLR_BKEY PAUTHLR_LEAF PAUTHLR_BTI NONE
//@ revisions: BTI GCS PACRET LEAF BKEY PAUTHLR PAUTHLR_BKEY PAUTHLR_LEAF PAUTHLR_BTI NONE
//@ needs-llvm-components: aarch64
//@ [BTI] compile-flags: -Z branch-protection=bti
//@ [GCS] compile-flags: -Z branch-protection=gcs
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
@ -32,6 +33,9 @@ pub fn test() {}
// BTI: !"sign-return-address-all", i32 0
// BTI: !"sign-return-address-with-bkey", i32 0
// GCS: attributes [[ATTR]] = {{.*}} "guarded-control-stack"
// GCS: !"guarded-control-stack", i32 1
// PACRET: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
// PACRET-SAME: "sign-return-address-key"="a_key"
// PACRET: !"branch-target-enforcement", i32 0

View file

@ -1,12 +1,14 @@
// `-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.
// with some of its possible extra arguments (bti, gcs, 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-apple
// Reason: XCode needs updating to support gcs
//@ ignore-cross-compile
// Reason: the compiled binary is executed
@ -19,7 +21,7 @@ fn main() {
clang()
.arg("-v")
.lto("thin")
.arg("-mbranch-protection=bti+pac-ret+b-key+leaf")
.arg("-mbranch-protection=bti+gcs+pac-ret+b-key+leaf")
.arg("-c")
.out_exe("test.o")
.input("test.c")
@ -30,7 +32,7 @@ fn main() {
.opt_level("2")
.linker(&env_var("CLANG"))
.link_arg("-fuse-ld=lld")
.arg("-Zbranch-protection=bti,pac-ret,leaf")
.arg("-Zbranch-protection=bti,gcs,pac-ret,leaf")
.input("test.rs")
.output("test.bin")
.run();

View file

@ -1,11 +1,13 @@
// `-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, pc, leaf, b-key).
// with some of its possible extra arguments (bti, gcs, pac-ret, pc, leaf, b-key).
// See https://github.com/rust-lang/rust/pull/88354
//@ only-aarch64
// Reason: branch protection is not supported on other architectures
//@ ignore-apple
// Reason: XCode needs updating to support gcs
//@ ignore-cross-compile
// Reason: the compiled binary is executed
@ -13,17 +15,17 @@ use run_make_support::{build_native_static_lib, cc, is_windows_msvc, llvm_ar, ru
fn main() {
build_native_static_lib("test");
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
rustc().arg("-Zbranch-protection=bti,gcs,pac-ret,leaf").input("test.rs").run();
run("test");
cc().arg("-v")
.arg("-c")
.out_exe("test")
.input("test.c")
.arg("-mbranch-protection=bti+pac-ret+leaf")
.arg("-mbranch-protection=bti+gcs+pac-ret+leaf")
.run();
let obj_file = if is_windows_msvc() { "test.obj" } else { "test" };
llvm_ar().obj_to_ar().output_input("libtest.a", &obj_file).run();
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
rustc().arg("-Zbranch-protection=bti,gcs,pac-ret,leaf").input("test.rs").run();
run("test");
// FIXME: +pc was only recently added to LLVM

View file

@ -1,2 +1,2 @@
error: incorrect value `leaf` for unstable option `branch-protection` - a `,` separated combination of `bti`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf` was expected
error: incorrect value `leaf` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected

View file

@ -1,2 +1,2 @@
error: incorrect value `pc` for unstable option `branch-protection` - a `,` separated combination of `bti`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf` was expected
error: incorrect value `pc` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set) was expected