Skip to content

Commit 2588287

Browse files
committed
Add more tests and check for ABI
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
1 parent 1aaafac commit 2588287

File tree

13 files changed

+92
-5
lines changed

13 files changed

+92
-5
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ E0771: include_str!("./error_codes/E0771.md"),
459459
E0773: include_str!("./error_codes/E0773.md"),
460460
E0774: include_str!("./error_codes/E0774.md"),
461461
E0775: include_str!("./error_codes/E0775.md"),
462+
E0776: include_str!("./error_codes/E0776.md"),
462463
;
463464
// E0006, // merged with E0005
464465
// E0008, // cannot bind by-move into a pattern guard

compiler/rustc_error_codes/src/error_codes/E0775.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Erroneous code example:
77
#![feature(cmse_nonsecure_entry)]
88
99
#[cmse_nonsecure_entry]
10-
fn toto() {}
10+
pub extern "C" fn entry_function() {}
1111
```
1212

1313
To fix this error, compile your code for a Rust target that supports the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
`#[cmse_nonsecure_entry]` functions require a C ABI
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0776
6+
#![feature(cmse_nonsecure_entry)]
7+
8+
#[no_mangle]
9+
#[cmse_nonsecure_entry]
10+
pub fn entry_function(input: Vec<u32>) {}
11+
```
12+
13+
To fix this error, declare your entry function with a C ABI, using `extern "C"`.

compiler/rustc_typeck/src/collect.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
25442544
} else if tcx.sess.check_name(attr, sym::used) {
25452545
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
25462546
} else if tcx.sess.check_name(attr, sym::cmse_nonsecure_entry) {
2547+
if tcx.fn_sig(id).abi() != abi::Abi::C {
2548+
struct_span_err!(
2549+
tcx.sess,
2550+
attr.span,
2551+
E0776,
2552+
"`#[cmse_nonsecure_entry]` requires C ABI"
2553+
)
2554+
.emit();
2555+
}
25472556
if !tcx.sess.target.target.llvm_target.contains("thumbv8m") {
25482557
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
25492558
.emit();

src/doc/unstable-book/src/language-features/cmse-nonsecure-entry.md

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ With this attribute, the compiler will do the following:
2626
information
2727
* use the `BXNS` instruction to return
2828

29+
Because the stack can not be used to pass parameters, there will be compilation
30+
errors if:
31+
* the total size of all parameters is too big (for example more than four 32
32+
bits integers)
33+
* the entry function is not using a C ABI
34+
2935
The special symbol `__acle_se_` will be used by the linker to generate a secure
3036
gateway veneer.
3137

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// gate-test-cmse_nonsecure_entry
2+
3+
#[no_mangle]
4+
#[cmse_nonsecure_entry]
5+
//~^ ERROR [E0775]
6+
//~| ERROR [E0658]
7+
pub extern "C" fn entry_function(input: u32) -> u32 {
8+
input + 6
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0658]: the `#[cmse_nonsecure_entry]` attribute is an experimental feature
2+
--> $DIR/gate_test.rs:4:1
3+
|
4+
LL | #[cmse_nonsecure_entry]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #75835 <https://github.com/rust-lang/rust/issues/75835> for more information
8+
= help: add `#![feature(cmse_nonsecure_entry)]` to the crate attributes to enable
9+
10+
error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
11+
--> $DIR/gate_test.rs:4:1
12+
|
13+
LL | #[cmse_nonsecure_entry]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0658, E0775.
19+
For more information about an error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// build-pass
2+
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
3+
// only-thumbv8m.main-none-eabi
4+
#![feature(cmse_nonsecure_entry)]
5+
#![no_std]
6+
7+
#[no_mangle]
8+
#[cmse_nonsecure_entry]
9+
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32) -> u32 {
10+
a + b + c + d
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// gate-test-cmse_nonsecure_entry
21
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
32
// only-thumbv8m.main-none-eabi
43
#![feature(cmse_nonsecure_entry)]
54
#![no_std]
65

76
#[no_mangle]
87
#[cmse_nonsecure_entry]
9-
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 {
8+
pub extern "C" fn entry_function(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 { //~ ERROR
109
a + b + c + d + e
1110
}

src/test/ui/cmse-nonsecure-entry/trustzone-only.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// gate-test-cmse_nonsecure_entry
21
// ignore-thumbv8m.main-none-eabi
32
#![feature(cmse_nonsecure_entry)]
43

src/test/ui/cmse-nonsecure-entry/trustzone-only.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0775]: `#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension
2-
--> $DIR/trustzone-only.rs:6:1
2+
--> $DIR/trustzone-only.rs:5:1
33
|
44
LL | #[cmse_nonsecure_entry]
55
| ^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
2+
// only-thumbv8m.main-none-eabi
3+
#![feature(cmse_nonsecure_entry)]
4+
#![no_std]
5+
6+
#[no_mangle]
7+
#[cmse_nonsecure_entry]
8+
pub fn entry_function(a: u32, b: u32, c: u32, d: u32) -> u32 { //~ ERROR [E0776]
9+
a + b + c + d
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0776]: `#[cmse_nonsecure_entry]` functions require C ABI
2+
--> $DIR/wrong-abi.rs:7:1
3+
|
4+
LL | #[cmse_nonsecure_entry]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0776`.

0 commit comments

Comments
 (0)