about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-30 18:43:48 +0000
committerbors <bors@rust-lang.org>2020-09-30 18:43:48 +0000
commit867bd42c38bac3870388765f65386b18cf1d9c5f (patch)
tree4323cb7195b1b266abd5d7460b25a15ba532c282 /src/test/ui
parentd92d28e523bf056ab4eb752510ec52fe4f1c6311 (diff)
parent2588287deffd92c4ca0b5b39f92b9cca894a3983 (diff)
Auto merge of #75810 - hug-dev:cmse-nonsecure-entry, r=jonas-schievink
Add support for cmse_nonsecure_entry attribute

This pull request adds the `cmse_nonsecure_entry` attribute under an unstable feature.

I was not sure if it was fine for me to send directly the pull-request or if I should submit a RFC first. I was told on Zulip that it was fine to do so but please close it if I need first submit a RFC or follow another process instead.

The `cmse_nonsecure_entry` attribute is a LLVM attribute that will be available in LLVM 11. I plan to rebase on the [upgrade PR](https://github.com/rust-lang/rust/pull/73526) once merged to make this one compile.

This attribute modifies code generation of the function as explained [here](https://developer.arm.com/documentation/ecm0359818/latest/) to make it work with the TrustZone-M hardware feature. This feature is only available on `thumbv8m` targets so I created an error for that if one tries to use this attribute for another target.

I added this attribute in Rust as any other LLVM attribute are added but since this one is target-dependent I am not sure if it was the best thing to do. Please indicate me if you think of other ways, like isolating target-dependent attributes together.

----------------

Tracking issue: https://github.com/rust-lang/rust/issues/75835
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/cmse-nonsecure-entry/gate_test.rs11
-rw-r--r--src/test/ui/cmse-nonsecure-entry/gate_test.stderr19
-rw-r--r--src/test/ui/cmse-nonsecure-entry/params-on-registers.rs11
-rw-r--r--src/test/ui/cmse-nonsecure-entry/params-on-stack.rs10
-rw-r--r--src/test/ui/cmse-nonsecure-entry/params-on-stack.stderr5
-rw-r--r--src/test/ui/cmse-nonsecure-entry/trustzone-only.rs10
-rw-r--r--src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr9
-rw-r--r--src/test/ui/cmse-nonsecure-entry/wrong-abi.rs10
-rw-r--r--src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr9
9 files changed, 94 insertions, 0 deletions
diff --git a/src/test/ui/cmse-nonsecure-entry/gate_test.rs b/src/test/ui/cmse-nonsecure-entry/gate_test.rs
new file mode 100644
index 00000000000..02d5f20febc
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/gate_test.rs
@@ -0,0 +1,11 @@
+// gate-test-cmse_nonsecure_entry
+
+#[no_mangle]
+#[cmse_nonsecure_entry]
+//~^ ERROR [E0775]
+//~| ERROR [E0658]
+pub extern "C" fn entry_function(input: u32) -> u32 {
+    input + 6
+}
+
+fn main() {}
diff --git a/src/test/ui/cmse-nonsecure-entry/gate_test.stderr b/src/test/ui/cmse-nonsecure-entry/gate_test.stderr
new file mode 100644
index 00000000000..75a29b317df
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/gate_test.stderr
@@ -0,0 +1,19 @@
+error[E0658]: the `#[cmse_nonsecure_entry]` attribute is an experimental feature
+  --> $DIR/gate_test.rs:4:1
+   |
+LL | #[cmse_nonsecure_entry]
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #75835 <https://github.com/rust-lang/rust/issues/75835> for more information
+   = help: add `#![feature(cmse_nonsecure_entry)]` to the crate attributes to enable
+
+error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
+  --> $DIR/gate_test.rs:4:1
+   |
+LL | #[cmse_nonsecure_entry]
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0658, E0775.
+For more information about an error, try `rustc --explain E0658`.
diff --git a/src/test/ui/cmse-nonsecure-entry/params-on-registers.rs b/src/test/ui/cmse-nonsecure-entry/params-on-registers.rs
new file mode 100644
index 00000000000..a723eb73473
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/params-on-registers.rs
@@ -0,0 +1,11 @@
+// build-pass
+// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+// only-thumbv8m.main-none-eabi
+#![feature(cmse_nonsecure_entry)]
+#![no_std]
+
+#[no_mangle]
+#[cmse_nonsecure_entry]
+pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32) -> u32 {
+    a + b + c + d
+}
diff --git a/src/test/ui/cmse-nonsecure-entry/params-on-stack.rs b/src/test/ui/cmse-nonsecure-entry/params-on-stack.rs
new file mode 100644
index 00000000000..553d3a8cb0b
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/params-on-stack.rs
@@ -0,0 +1,10 @@
+// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+// only-thumbv8m.main-none-eabi
+#![feature(cmse_nonsecure_entry)]
+#![no_std]
+
+#[no_mangle]
+#[cmse_nonsecure_entry]
+pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 { //~ ERROR
+    a + b + c + d + e
+}
diff --git a/src/test/ui/cmse-nonsecure-entry/params-on-stack.stderr b/src/test/ui/cmse-nonsecure-entry/params-on-stack.stderr
new file mode 100644
index 00000000000..d9956acbe75
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/params-on-stack.stderr
@@ -0,0 +1,5 @@
+error: <unknown>:0:0: in function entry_function i32 (i32, i32, i32, i32, i32): secure entry function requires arguments on stack
+
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/cmse-nonsecure-entry/trustzone-only.rs b/src/test/ui/cmse-nonsecure-entry/trustzone-only.rs
new file mode 100644
index 00000000000..3783e279402
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/trustzone-only.rs
@@ -0,0 +1,10 @@
+// ignore-thumbv8m.main-none-eabi
+#![feature(cmse_nonsecure_entry)]
+
+#[no_mangle]
+#[cmse_nonsecure_entry] //~ ERROR [E0775]
+pub extern "C" fn entry_function(input: u32) -> u32 {
+    input + 6
+}
+
+fn main() {}
diff --git a/src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr b/src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr
new file mode 100644
index 00000000000..7e8862f9ab7
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr
@@ -0,0 +1,9 @@
+error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
+  --> $DIR/trustzone-only.rs:5:1
+   |
+LL | #[cmse_nonsecure_entry]
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0775`.
diff --git a/src/test/ui/cmse-nonsecure-entry/wrong-abi.rs b/src/test/ui/cmse-nonsecure-entry/wrong-abi.rs
new file mode 100644
index 00000000000..611c8643dcb
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/wrong-abi.rs
@@ -0,0 +1,10 @@
+// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
+// only-thumbv8m.main-none-eabi
+#![feature(cmse_nonsecure_entry)]
+#![no_std]
+
+#[no_mangle]
+#[cmse_nonsecure_entry]
+pub fn entry_function(a: u32, b: u32, c: u32, d: u32) -> u32 { //~ ERROR [E0776]
+    a + b + c + d
+}
diff --git a/src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr b/src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr
new file mode 100644
index 00000000000..d6967a11e6b
--- /dev/null
+++ b/src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr
@@ -0,0 +1,9 @@
+error[E0776]: `#[cmse_nonsecure_entry]` functions require C ABI
+  --> $DIR/wrong-abi.rs:7:1
+   |
+LL | #[cmse_nonsecure_entry]
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0776`.