diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2022-01-31 21:47:07 +0200 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2022-02-19 17:31:40 +0200 |
| commit | b995dc944ce60087d77accd091e6ffb103030603 (patch) | |
| tree | bdcf39076b9bc04b7db8b211d3ff0c1dd1203750 /src/test | |
| parent | cb4ee81ef555126e49b3e9f16ca6f12a3264a451 (diff) | |
No branch protection metadata unless enabled
Even if we emit metadata disabling branch protection, this metadata may conflict with other modules (e.g. during LTO) that have different branch protection metadata set. This is an unstable flag and feature, so ideally the flag not being specified should act as if the feature wasn't implemented in the first place. Additionally this PR also ensures we emit an error if `-Zbranch-protection` is set on targets other than the supported aarch64. For now the error is being output from codegen, but ideally it should be moved to earlier in the pipeline before stabilization.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/codegen/branch-protection.rs | 53 | ||||
| -rw-r--r-- | src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADFLAGS.stderr (renamed from src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.stderr) | 0 | ||||
| -rw-r--r-- | src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs | 15 |
4 files changed, 47 insertions, 25 deletions
diff --git a/src/test/codegen/branch-protection.rs b/src/test/codegen/branch-protection.rs index 106c9b148ee..b23073778c0 100644 --- a/src/test/codegen/branch-protection.rs +++ b/src/test/codegen/branch-protection.rs @@ -1,12 +1,12 @@ // Test that the correct module flags are emitted with different branch protection flags. -// revisions: bti pac-ret leaf b-key +// revisions: BTI PACRET LEAF BKEY NONE // min-llvm-version: 12.0.0 // needs-llvm-components: aarch64 -// [bti] compile-flags: -Z branch-protection=bti -// [pac-ret] compile-flags: -Z branch-protection=pac-ret -// [leaf] compile-flags: -Z branch-protection=pac-ret,leaf -// [b-key] compile-flags: -Z branch-protection=pac-ret,b-key +// [BTI] compile-flags: -Z branch-protection=bti +// [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 // compile-flags: --target aarch64-unknown-linux-gnu #![crate_type = "lib"] @@ -20,22 +20,27 @@ trait Sized { } pub fn test() { } -// bti: !"branch-target-enforcement", i32 1 -// bti: !"sign-return-address", i32 0 -// bti: !"sign-return-address-all", i32 0 -// bti: !"sign-return-address-with-bkey", i32 0 - -// pac-ret: !"branch-target-enforcement", i32 0 -// pac-ret: !"sign-return-address", i32 1 -// pac-ret: !"sign-return-address-all", i32 0 -// pac-ret: !"sign-return-address-with-bkey", i32 0 - -// leaf: !"branch-target-enforcement", i32 0 -// leaf: !"sign-return-address", i32 1 -// leaf: !"sign-return-address-all", i32 1 -// leaf: !"sign-return-address-with-bkey", i32 0 - -// b-key: !"branch-target-enforcement", i32 0 -// b-key: !"sign-return-address", i32 1 -// b-key: !"sign-return-address-all", i32 0 -// b-key: !"sign-return-address-with-bkey", i32 1 +// BTI: !"branch-target-enforcement", i32 1 +// BTI: !"sign-return-address", i32 0 +// BTI: !"sign-return-address-all", i32 0 +// BTI: !"sign-return-address-with-bkey", i32 0 + +// PACRET: !"branch-target-enforcement", i32 0 +// PACRET: !"sign-return-address", i32 1 +// PACRET: !"sign-return-address-all", i32 0 +// PACRET: !"sign-return-address-with-bkey", i32 0 + +// LEAF: !"branch-target-enforcement", i32 0 +// LEAF: !"sign-return-address", i32 1 +// LEAF: !"sign-return-address-all", i32 1 +// LEAF: !"sign-return-address-with-bkey", i32 0 + +// BKEY: !"branch-target-enforcement", i32 0 +// BKEY: !"sign-return-address", i32 1 +// BKEY: !"sign-return-address-all", i32 0 +// BKEY: !"sign-return-address-with-bkey", i32 1 + +// NONE-NOT: branch-target-enforcement +// NONE-NOT: sign-return-address +// NONE-NOT: sign-return-address-all +// NONE-NOT: sign-return-address-with-bkey diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.stderr b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADFLAGS.stderr index 5528d2a0729..5528d2a0729 100644 --- a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.stderr +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADFLAGS.stderr diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr new file mode 100644 index 00000000000..6bd9c6a0276 --- /dev/null +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.BADTARGET.stderr @@ -0,0 +1,4 @@ +error: -Zbranch-protection is only supported on aarch64 + +error: aborting due to previous error + diff --git a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs index 4f39d223a2e..4bc4919bc93 100644 --- a/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs +++ b/src/test/ui/invalid-compile-flags/branch-protection-missing-pac-ret.rs @@ -1 +1,14 @@ -// compile-flags: -Z branch-protection=leaf +// revisions: BADFLAGS BADTARGET +// [BADFLAGS] compile-flags: --target=aarch64-unknown-linux-gnu -Zbranch-protection=leaf +// [BADFLAGS] check-fail +// [BADFLAGS] needs-llvm-components: aarch64 +// [BADTARGET] compile-flags: --target=x86_64-unknown-linux-gnu -Zbranch-protection=bti +// [BADTARGET] build-fail +// [BADTARGET] needs-llvm-components: x86 + +#![crate_type = "lib"] +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized { } |
