Add more tests and check for ABI
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
This commit is contained in:
parent
1aaafac6ff
commit
2588287def
13 changed files with 92 additions and 5 deletions
|
@ -459,6 +459,7 @@ E0771: include_str!("./error_codes/E0771.md"),
|
||||||
E0773: include_str!("./error_codes/E0773.md"),
|
E0773: include_str!("./error_codes/E0773.md"),
|
||||||
E0774: include_str!("./error_codes/E0774.md"),
|
E0774: include_str!("./error_codes/E0774.md"),
|
||||||
E0775: include_str!("./error_codes/E0775.md"),
|
E0775: include_str!("./error_codes/E0775.md"),
|
||||||
|
E0776: include_str!("./error_codes/E0776.md"),
|
||||||
;
|
;
|
||||||
// E0006, // merged with E0005
|
// E0006, // merged with E0005
|
||||||
// E0008, // cannot bind by-move into a pattern guard
|
// E0008, // cannot bind by-move into a pattern guard
|
||||||
|
|
|
@ -7,7 +7,7 @@ Erroneous code example:
|
||||||
#![feature(cmse_nonsecure_entry)]
|
#![feature(cmse_nonsecure_entry)]
|
||||||
|
|
||||||
#[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
|
To fix this error, compile your code for a Rust target that supports the
|
||||||
|
|
13
compiler/rustc_error_codes/src/error_codes/E0776.md
Normal file
13
compiler/rustc_error_codes/src/error_codes/E0776.md
Normal 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"`.
|
|
@ -2544,6 +2544,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
||||||
} else if tcx.sess.check_name(attr, sym::used) {
|
} else if tcx.sess.check_name(attr, sym::used) {
|
||||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
|
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
|
||||||
} else if tcx.sess.check_name(attr, sym::cmse_nonsecure_entry) {
|
} 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") {
|
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")
|
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
|
||||||
.emit();
|
.emit();
|
||||||
|
|
|
@ -26,6 +26,12 @@ With this attribute, the compiler will do the following:
|
||||||
information
|
information
|
||||||
* use the `BXNS` instruction to return
|
* 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
|
The special symbol `__acle_se_` will be used by the linker to generate a secure
|
||||||
gateway veneer.
|
gateway veneer.
|
||||||
|
|
||||||
|
|
11
src/test/ui/cmse-nonsecure-entry/gate_test.rs
Normal file
11
src/test/ui/cmse-nonsecure-entry/gate_test.rs
Normal 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() {}
|
19
src/test/ui/cmse-nonsecure-entry/gate_test.stderr
Normal file
19
src/test/ui/cmse-nonsecure-entry/gate_test.stderr
Normal 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`.
|
11
src/test/ui/cmse-nonsecure-entry/params-on-registers.rs
Normal file
11
src/test/ui/cmse-nonsecure-entry/params-on-registers.rs
Normal 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
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
// gate-test-cmse_nonsecure_entry
|
|
||||||
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
|
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
|
||||||
// only-thumbv8m.main-none-eabi
|
// only-thumbv8m.main-none-eabi
|
||||||
#![feature(cmse_nonsecure_entry)]
|
#![feature(cmse_nonsecure_entry)]
|
||||||
|
@ -6,6 +5,6 @@
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cmse_nonsecure_entry]
|
#[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
|
a + b + c + d + e
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// gate-test-cmse_nonsecure_entry
|
|
||||||
// ignore-thumbv8m.main-none-eabi
|
// ignore-thumbv8m.main-none-eabi
|
||||||
#![feature(cmse_nonsecure_entry)]
|
#![feature(cmse_nonsecure_entry)]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
|
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]
|
LL | #[cmse_nonsecure_entry]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
10
src/test/ui/cmse-nonsecure-entry/wrong-abi.rs
Normal file
10
src/test/ui/cmse-nonsecure-entry/wrong-abi.rs
Normal 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
|
||||||
|
}
|
9
src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr
Normal file
9
src/test/ui/cmse-nonsecure-entry/wrong-abi.stderr
Normal 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`.
|
Loading…
Add table
Add a link
Reference in a new issue