Add more tests and check for ABI

Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
This commit is contained in:
Hugues de Valon 2020-09-30 18:10:17 +01:00
parent 1aaafac6ff
commit 2588287def
13 changed files with 92 additions and 5 deletions

View File

@ -459,6 +459,7 @@ E0771: include_str!("./error_codes/E0771.md"),
E0773: include_str!("./error_codes/E0773.md"),
E0774: include_str!("./error_codes/E0774.md"),
E0775: include_str!("./error_codes/E0775.md"),
E0776: include_str!("./error_codes/E0776.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard

View File

@ -7,7 +7,7 @@ Erroneous code example:
#![feature(cmse_nonsecure_entry)]
#[cmse_nonsecure_entry]
fn toto() {}
pub extern "C" fn entry_function() {}
```
To fix this error, compile your code for a Rust target that supports the

View File

@ -0,0 +1,13 @@
`#[cmse_nonsecure_entry]` functions require a C ABI
Erroneous code example:
```compile_fail,E0776
#![feature(cmse_nonsecure_entry)]
#[no_mangle]
#[cmse_nonsecure_entry]
pub fn entry_function(input: Vec<u32>) {}
```
To fix this error, declare your entry function with a C ABI, using `extern "C"`.

View File

@ -2544,6 +2544,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
} else if tcx.sess.check_name(attr, sym::used) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
} else if tcx.sess.check_name(attr, sym::cmse_nonsecure_entry) {
if tcx.fn_sig(id).abi() != abi::Abi::C {
struct_span_err!(
tcx.sess,
attr.span,
E0776,
"`#[cmse_nonsecure_entry]` requires C ABI"
)
.emit();
}
if !tcx.sess.target.target.llvm_target.contains("thumbv8m") {
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
.emit();

View File

@ -26,6 +26,12 @@ With this attribute, the compiler will do the following:
information
* use the `BXNS` instruction to return
Because the stack can not be used to pass parameters, there will be compilation
errors if:
* the total size of all parameters is too big (for example more than four 32
bits integers)
* the entry function is not using a C ABI
The special symbol `__acle_se_` will be used by the linker to generate a secure
gateway veneer.

View File

@ -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() {}

View File

@ -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`.

View File

@ -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
}

View File

@ -1,4 +1,3 @@
// gate-test-cmse_nonsecure_entry
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
// only-thumbv8m.main-none-eabi
#![feature(cmse_nonsecure_entry)]
@ -6,6 +5,6 @@
#[no_mangle]
#[cmse_nonsecure_entry]
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 {
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 { //~ ERROR
a + b + c + d + e
}

View File

@ -1,4 +1,3 @@
// gate-test-cmse_nonsecure_entry
// ignore-thumbv8m.main-none-eabi
#![feature(cmse_nonsecure_entry)]

View File

@ -1,5 +1,5 @@
error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
--> $DIR/trustzone-only.rs:6:1
--> $DIR/trustzone-only.rs:5:1
|
LL | #[cmse_nonsecure_entry]
| ^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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
}

View File

@ -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`.