Skip to content

Commit

Permalink
Add more tests and check for ABI
Browse files Browse the repository at this point in the history
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
  • Loading branch information
hug-dev committed Sep 30, 2020
1 parent 1aaafac commit 2588287
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0775.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0776.md
Original file line number Diff line number Diff line change
@@ -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"`.
9 changes: 9 additions & 0 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/cmse-nonsecure-entry/gate_test.rs
Original file line number Diff line number Diff line change
@@ -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() {}
19 changes: 19 additions & 0 deletions src/test/ui/cmse-nonsecure-entry/gate_test.stderr
Original file line number Diff line number Diff line change
@@ -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`.
11 changes: 11 additions & 0 deletions src/test/ui/cmse-nonsecure-entry/params-on-registers.rs
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions src/test/ui/cmse-nonsecure-entry/params-on-stack.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// gate-test-cmse_nonsecure_entry
// 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 {
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 { //~ ERROR
a + b + c + d + e
}
1 change: 0 additions & 1 deletion src/test/ui/cmse-nonsecure-entry/trustzone-only.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// gate-test-cmse_nonsecure_entry
// ignore-thumbv8m.main-none-eabi
#![feature(cmse_nonsecure_entry)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr
Original file line number Diff line number Diff line change
@@ -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]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/cmse-nonsecure-entry/wrong-abi.rs
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 2588287

Please sign in to comment.