Skip to content

Withdraw the claim extern "C-cmse-nonsecure-*" always matches extern "C" #142146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/canon_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl fmt::Display for CanonAbi {
CanonAbi::RustCold => ExternAbi::RustCold,
CanonAbi::Arm(arm_call) => match arm_call {
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
ArmCall::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
ArmCall::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
ArmCall::CCmseNonSecureCall => ExternAbi::CmseNonSecureCall,
ArmCall::CCmseNonSecureEntry => ExternAbi::CmseNonSecureEntry,
},
CanonAbi::GpuKernel => ExternAbi::GpuKernel,
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub enum ExternAbi {
unwind: bool,
},
/// extremely constrained barely-C ABI for TrustZone
CCmseNonSecureCall,
CmseNonSecureCall,
/// extremely constrained barely-C ABI for TrustZone
CCmseNonSecureEntry,
CmseNonSecureEntry,

/* gpu */
/// An entry-point function called by the GPU's host
Expand Down Expand Up @@ -131,8 +131,6 @@ macro_rules! abi_impls {
abi_impls! {
ExternAbi = {
C { unwind: false } =><= "C",
CCmseNonSecureCall =><= "C-cmse-nonsecure-call",
CCmseNonSecureEntry =><= "C-cmse-nonsecure-entry",
C { unwind: true } =><= "C-unwind",
Rust =><= "Rust",
Aapcs { unwind: false } =><= "aapcs",
Expand All @@ -141,6 +139,8 @@ abi_impls! {
AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
Cdecl { unwind: false } =><= "cdecl",
Cdecl { unwind: true } =><= "cdecl-unwind",
CmseNonSecureCall =><= "cmse-nonsecure-call",
CmseNonSecureEntry =><= "cmse-nonsecure-entry",
EfiApi =><= "efiapi",
Fastcall { unwind: false } =><= "fastcall",
Fastcall { unwind: true } =><= "fastcall-unwind",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
feature: sym::abi_riscv_interrupt,
explain: GateReason::Experimental,
}),
ExternAbi::CCmseNonSecureCall => Err(UnstableAbi {
ExternAbi::CmseNonSecureCall => Err(UnstableAbi {
abi,
feature: sym::abi_c_cmse_nonsecure_call,
explain: GateReason::Experimental,
}),
ExternAbi::CCmseNonSecureEntry => Err(UnstableAbi {
ExternAbi::CmseNonSecureEntry => Err(UnstableAbi {
abi,
feature: sym::cmse_nonsecure_entry,
explain: GateReason::Experimental,
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 @@ -8,7 +8,7 @@ Erroneous code example:
```ignore (no longer emitted)
#![feature(cmse_nonsecure_entry)]

pub extern "C-cmse-nonsecure-entry" fn entry_function() {}
pub extern "cmse-nonsecure-entry" fn entry_function() {}
```

To fix this error, compile your code for a Rust target that supports the
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0781.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
The `C-cmse-nonsecure-call` ABI can only be used with function pointers.
The `cmse-nonsecure-call` ABI can only be used with function pointers.

Erroneous code example:

```compile_fail,E0781
#![feature(abi_c_cmse_nonsecure_call)]

pub extern "C-cmse-nonsecure-call" fn test() {}
pub extern "cmse-nonsecure-call" fn test() {}
```

The `C-cmse-nonsecure-call` ABI should be used by casting function pointers to
The `cmse-nonsecure-call` ABI should be used by casting function pointers to
specific addresses.
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0798.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Functions marked as `C-cmse-nonsecure-call` place restrictions on their
Functions marked as `cmse-nonsecure-call` place restrictions on their
inputs and outputs.

- inputs must fit in the 4 available 32-bit argument registers. Alignment
Expand All @@ -17,7 +17,7 @@ Erroneous code example:

#[no_mangle]
pub fn test(
f: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
f: extern "cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
) -> u32 {
f(1, 2, 3, 4, 5)
}
Expand All @@ -32,7 +32,7 @@ room left for the final `f32` argument

#[no_mangle]
pub fn test(
f: extern "C-cmse-nonsecure-call" fn(u32, u64, f32) -> u32,
f: extern "cmse-nonsecure-call" fn(u32, u64, f32) -> u32,
) -> u32 {
f(1, 2, 3.0)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,5 +688,5 @@ E0804: 0804,
// E0723, // unstable feature in `const` context
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
// E0744, // merged into E0728
// E0776, // Removed; cmse_nonsecure_entry is now `C-cmse-nonsecure-entry`
// E0776, // Removed; `#[cmse_nonsecure_entry]` is now `extern "cmse-nonsecure-entry"`
// E0796, // unused error code. We use `static_mut_refs` lint instead.
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ declare_features! (

/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
(unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
/// Allows `extern "C-cmse-nonsecure-call" fn()`.
/// Allows `extern "cmse-nonsecure-call" fn()`.
(unstable, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391)),
/// Allows `extern "gpu-kernel" fn()`.
(unstable, abi_gpu_kernel, "1.86.0", Some(135467)),
Expand Down Expand Up @@ -427,7 +427,7 @@ declare_features! (
(unstable, closure_lifetime_binder, "1.64.0", Some(97362)),
/// Allows `#[track_caller]` on closures and coroutines.
(unstable, closure_track_caller, "1.57.0", Some(87417)),
/// Allows `extern "C-cmse-nonsecure-entry" fn()`.
/// Allows `extern "cmse-nonsecure-entry" fn()`.
(unstable, cmse_nonsecure_entry, "1.48.0", Some(75835)),
/// Allows `async {}` expressions in const contexts.
(unstable, const_async_blocks, "1.53.0", Some(85368)),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are fo
.label = `for<...>` is here

hir_analysis_cmse_call_generic =
function pointers with the `"C-cmse-nonsecure-call"` ABI cannot contain generics in their type
function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type

hir_analysis_cmse_entry_generic =
functions with the `"C-cmse-nonsecure-entry"` ABI cannot contain generics in their type
functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type

hir_analysis_cmse_inputs_stack_spill =
arguments for `{$abi}` function too large to pass via registers
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
fn_sig: ty::PolyFnSig<'tcx>,
) {
match abi {
ExternAbi::CCmseNonSecureCall => {
ExternAbi::CmseNonSecureCall => {
let hir_node = tcx.hir_node(hir_id);
let hir::Node::Ty(hir::Ty {
span: bare_fn_span,
Expand All @@ -38,7 +38,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
dcx,
span,
E0781,
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
"the `\"cmse-nonsecure-call\"` ABI is only allowed on function pointers"
)
.emit();
return;
Expand Down Expand Up @@ -78,7 +78,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
}
};
}
ExternAbi::CCmseNonSecureEntry => {
ExternAbi::CmseNonSecureEntry => {
let hir_node = tcx.hir_node(hir_id);
let Some(hir::FnSig { decl, span: fn_sig_span, .. }) = hir_node.fn_sig() else {
// might happen when this ABI is used incorrectly. That will be handled elsewhere
Expand Down Expand Up @@ -203,11 +203,11 @@ fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError
match layout_err {
TooGeneric(ty) => {
match abi {
ExternAbi::CCmseNonSecureCall => {
ExternAbi::CmseNonSecureCall => {
// prevent double reporting of this error
!ty.is_impl_trait()
}
ExternAbi::CCmseNonSecureEntry => true,
ExternAbi::CmseNonSecureEntry => true,
_ => bug!("invalid ABI: {abi}"),
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,10 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
| EfiApi
| AvrInterrupt
| AvrNonBlockingInterrupt
| CmseNonSecureCall
| CmseNonSecureEntry
| RiscvInterruptM
| RiscvInterruptS
| CCmseNonSecureCall
| CCmseNonSecureEntry
| Unadjusted => false,
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ impl RustcInternal for Abi {
Abi::Vectorcall { unwind } => rustc_abi::ExternAbi::Vectorcall { unwind },
Abi::Thiscall { unwind } => rustc_abi::ExternAbi::Thiscall { unwind },
Abi::Aapcs { unwind } => rustc_abi::ExternAbi::Aapcs { unwind },
Abi::CCmseNonSecureCall => rustc_abi::ExternAbi::CmseNonSecureCall,
Abi::CCmseNonSecureEntry => rustc_abi::ExternAbi::CmseNonSecureEntry,
Abi::Win64 { unwind } => rustc_abi::ExternAbi::Win64 { unwind },
Abi::SysV64 { unwind } => rustc_abi::ExternAbi::SysV64 { unwind },
Abi::PtxKernel => rustc_abi::ExternAbi::PtxKernel,
Expand All @@ -488,8 +490,6 @@ impl RustcInternal for Abi {
Abi::EfiApi => rustc_abi::ExternAbi::EfiApi,
Abi::AvrInterrupt => rustc_abi::ExternAbi::AvrInterrupt,
Abi::AvrNonBlockingInterrupt => rustc_abi::ExternAbi::AvrNonBlockingInterrupt,
Abi::CCmseNonSecureCall => rustc_abi::ExternAbi::CCmseNonSecureCall,
Abi::CCmseNonSecureEntry => rustc_abi::ExternAbi::CCmseNonSecureEntry,
Abi::System { unwind } => rustc_abi::ExternAbi::System { unwind },
Abi::RustCall => rustc_abi::ExternAbi::RustCall,
Abi::Unadjusted => rustc_abi::ExternAbi::Unadjusted,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
ExternAbi::EfiApi => Abi::EfiApi,
ExternAbi::AvrInterrupt => Abi::AvrInterrupt,
ExternAbi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
ExternAbi::CCmseNonSecureCall => Abi::CCmseNonSecureCall,
ExternAbi::CCmseNonSecureEntry => Abi::CCmseNonSecureEntry,
ExternAbi::CmseNonSecureCall => Abi::CCmseNonSecureCall,
ExternAbi::CmseNonSecureEntry => Abi::CCmseNonSecureEntry,
ExternAbi::System { unwind } => Abi::System { unwind },
ExternAbi::RustCall => Abi::RustCall,
ExternAbi::Unadjusted => Abi::Unadjusted,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/spec/abi_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ impl AbiMap {
(ExternAbi::Aapcs { .. }, Arch::Arm(..)) => CanonAbi::Arm(ArmCall::Aapcs),
(ExternAbi::Aapcs { .. }, _) => return AbiMapping::Invalid,

(ExternAbi::CCmseNonSecureCall, Arch::Arm(ArmVer::ThumbV8M)) => {
(ExternAbi::CmseNonSecureCall, Arch::Arm(ArmVer::ThumbV8M)) => {
CanonAbi::Arm(ArmCall::CCmseNonSecureCall)
}
(ExternAbi::CCmseNonSecureEntry, Arch::Arm(ArmVer::ThumbV8M)) => {
(ExternAbi::CmseNonSecureEntry, Arch::Arm(ArmVer::ThumbV8M)) => {
CanonAbi::Arm(ArmCall::CCmseNonSecureEntry)
}
(ExternAbi::CCmseNonSecureCall | ExternAbi::CCmseNonSecureEntry, ..) => {
(ExternAbi::CmseNonSecureCall | ExternAbi::CmseNonSecureEntry, ..) => {
return AbiMapping::Invalid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LLVM, the Rust compiler and the linker are providing
[support](https://developer.arm.com/documentation/ecm0359818/latest/) for the
TrustZone-M feature.

One of the things provided, with this unstable feature, is the
`C-cmse-nonsecure-call` function ABI. This ABI is used on function pointers to
One of the things provided with this unstable feature is the
"cmse-nonsecure-call" function ABI. This ABI is used on function pointers to
non-secure code to mark a non-secure function call (see [section
5.5](https://developer.arm.com/documentation/ecm0359818/latest/) for details).

Expand All @@ -28,9 +28,6 @@ With this ABI, the compiler will do the following to perform the call:
To avoid using the non-secure stack, the compiler will constrain the number and
type of parameters/return value.

The `extern "C-cmse-nonsecure-call"` ABI is otherwise equivalent to the
`extern "C"` ABI.

<!-- NOTE(ignore) this example is specific to thumbv8m targets -->

``` rust,ignore
Expand All @@ -40,7 +37,7 @@ The `extern "C-cmse-nonsecure-call"` ABI is otherwise equivalent to the
#[no_mangle]
pub fn call_nonsecure_function(addr: usize) -> u32 {
let non_secure_function =
unsafe { core::mem::transmute::<usize, extern "C-cmse-nonsecure-call" fn() -> u32>(addr) };
unsafe { core::mem::transmute::<usize, extern "cmse-nonsecure-call" fn() -> u32>(addr) };
non_secure_function()
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ LLVM, the Rust compiler and the linker are providing
[support](https://developer.arm.com/documentation/ecm0359818/latest/) for the
TrustZone-M feature.

One of the things provided, with this unstable feature, is the
`C-cmse-nonsecure-entry` ABI. This ABI marks a Secure function as an
One of the things provided with this unstable feature is the
"cmse-nonsecure-entry" ABI. This ABI marks a Secure function as an
entry function (see [section
5.4](https://developer.arm.com/documentation/ecm0359818/latest/) for details).
With this ABI, the compiler will do the following:
Expand All @@ -30,7 +30,6 @@ 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 All @@ -42,7 +41,7 @@ gateway veneer.
#![feature(cmse_nonsecure_entry)]

#[no_mangle]
pub extern "C-cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
pub extern "cmse-nonsecure-entry" fn entry_function(input: u32) -> u32 {
input + 6
}
```
Expand Down
6 changes: 2 additions & 4 deletions tests/assembly/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use minicore::*;
// Branch back to non-secure side
// CHECK: bxns lr
#[no_mangle]
pub extern "C-cmse-nonsecure-entry" fn entry_point() -> i64 {
pub extern "cmse-nonsecure-entry" fn entry_point() -> i64 {
0
}

Expand Down Expand Up @@ -95,8 +95,6 @@ pub extern "C-cmse-nonsecure-entry" fn entry_point() -> i64 {
// Call to non-secure
// CHECK: blxns r12
#[no_mangle]
pub fn call_nonsecure(
f: unsafe extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32) -> u64,
) -> u64 {
pub fn call_nonsecure(f: unsafe extern "cmse-nonsecure-call" fn(u32, u32, u32, u32) -> u64) -> u64 {
unsafe { f(0, 1, 2, 3) }
}
2 changes: 1 addition & 1 deletion tests/crashes/130104.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

fn main() {
let non_secure_function =
core::mem::transmute::<fn() -> _, extern "C-cmse-nonsecure-call" fn() -> _>;
core::mem::transmute::<fn() -> _, extern "cmse-nonsecure-call" fn() -> _>;
}
2 changes: 1 addition & 1 deletion tests/crashes/132142.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//@ known-bug: #132142

async extern "C-cmse-nonsecure-entry" fn fun(...) {}
async extern "cmse-nonsecure-entry" fn fun(...) {}
2 changes: 1 addition & 1 deletion tests/crashes/132430.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
struct Test;

impl Test {
pub async unsafe extern "C-cmse-nonsecure-entry" fn test(val: &str) {}
pub async unsafe extern "cmse-nonsecure-entry" fn test(val: &str) {}
}
Loading
Loading