Skip to content

Commit b50c4db

Browse files
committed
Extends branch protection tests to include GCS
1 parent d2f21b8 commit b50c4db

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

tests/assembly-llvm/aarch64-pointer-auth.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Test that PAC instructions are emitted when branch-protection is specified.
22

33
//@ add-core-stubs
4-
//@ revisions: PACRET PAUTHLR_NOP PAUTHLR
4+
//@ revisions: GCS PACRET PAUTHLR_NOP PAUTHLR
55
//@ assembly-output: emit-asm
66
//@ needs-llvm-components: aarch64
77
//@ compile-flags: --target aarch64-unknown-linux-gnu
8+
//@ [GCS] compile-flags: -Z branch-protection=gcs
89
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret,leaf
910
//@ [PAUTHLR_NOP] compile-flags: -Z branch-protection=pac-ret,pc,leaf
1011
//@ [PAUTHLR] compile-flags: -C target-feature=+pauth-lr -Z branch-protection=pac-ret,pc,leaf
@@ -17,6 +18,7 @@
1718
extern crate minicore;
1819
use minicore::*;
1920

21+
// GCS: .aeabi_attribute 2, 1 // Tag_Feature_GCS
2022
// PACRET: hint #25
2123
// PACRET: hint #29
2224
// PAUTHLR_NOP: hint #25

tests/codegen-llvm/branch-protection.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Test that the correct module flags are emitted with different branch protection flags.
22

33
//@ add-core-stubs
4-
//@ revisions: BTI PACRET LEAF BKEY PAUTHLR PAUTHLR_BKEY PAUTHLR_LEAF PAUTHLR_BTI NONE
4+
//@ revisions: BTI GCS PACRET LEAF BKEY PAUTHLR PAUTHLR_BKEY PAUTHLR_LEAF PAUTHLR_BTI NONE
55
//@ needs-llvm-components: aarch64
66
//@ [BTI] compile-flags: -Z branch-protection=bti
7+
//@ [GCS] compile-flags: -Z branch-protection=gcs
78
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret
89
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
910
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
@@ -32,6 +33,9 @@ pub fn test() {}
3233
// BTI: !"sign-return-address-all", i32 0
3334
// BTI: !"sign-return-address-with-bkey", i32 0
3435

36+
// GCS: attributes [[ATTR]] = {{.*}} "guarded-control-stack"
37+
// GCS: !"guarded-control-stack", i32 1
38+
3539
// PACRET: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
3640
// PACRET-SAME: "sign-return-address-key"="a_key"
3741
// PACRET: !"branch-target-enforcement", i32 0

tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
22
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
33
// 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.
4+
// with some of its possible extra arguments (bti, gcs, pac-ret, leaf) when doing LTO.
55
// See https://github.com/rust-lang/rust/pull/88354
66

77
//@ needs-force-clang-based-tests
@@ -19,7 +19,7 @@ fn main() {
1919
clang()
2020
.arg("-v")
2121
.lto("thin")
22-
.arg("-mbranch-protection=bti+pac-ret+b-key+leaf")
22+
.arg("-mbranch-protection=bti+gcs+pac-ret+b-key+leaf")
2323
.arg("-c")
2424
.out_exe("test.o")
2525
.input("test.c")
@@ -30,7 +30,7 @@ fn main() {
3030
.opt_level("2")
3131
.linker(&env_var("CLANG"))
3232
.link_arg("-fuse-ld=lld")
33-
.arg("-Zbranch-protection=bti,pac-ret,leaf")
33+
.arg("-Zbranch-protection=bti,gcs,pac-ret,leaf")
3434
.input("test.rs")
3535
.output("test.bin")
3636
.run();

tests/run-make/pointer-auth-link-with-c/rmake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// `-Z branch protection` is an unstable compiler feature which adds pointer-authentication
22
// code (PAC), a useful hashing measure for verifying that pointers have not been modified.
33
// 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, pc, leaf, b-key).
4+
// with some of its possible extra arguments (bti, gcs, pac-ret, pc, leaf, b-key).
55
// See https://github.com/rust-lang/rust/pull/88354
66

77
//@ only-aarch64
@@ -13,17 +13,17 @@ use run_make_support::{build_native_static_lib, cc, is_windows_msvc, llvm_ar, ru
1313

1414
fn main() {
1515
build_native_static_lib("test");
16-
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
16+
rustc().arg("-Zbranch-protection=bti,gcs,pac-ret,leaf").input("test.rs").run();
1717
run("test");
1818
cc().arg("-v")
1919
.arg("-c")
2020
.out_exe("test")
2121
.input("test.c")
22-
.arg("-mbranch-protection=bti+pac-ret+leaf")
22+
.arg("-mbranch-protection=bti+gcs+pac-ret+leaf")
2323
.run();
2424
let obj_file = if is_windows_msvc() { "test.obj" } else { "test" };
2525
llvm_ar().obj_to_ar().output_input("libtest.a", &obj_file).run();
26-
rustc().arg("-Zbranch-protection=bti,pac-ret,leaf").input("test.rs").run();
26+
rustc().arg("-Zbranch-protection=bti,gcs,pac-ret,leaf").input("test.rs").run();
2727
run("test");
2828

2929
// FIXME: +pc was only recently added to LLVM
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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
1+
error: incorrect value `leaf` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf` was expected
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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
1+
error: incorrect value `pc` for unstable option `branch-protection` - a `,` separated combination of `bti`, `gcs`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf` was expected
22

0 commit comments

Comments
 (0)