Skip to content

Commit bb145c2

Browse files
Rollup merge of rust-lang#142146 - workingjubilee:doubt-that-cmse-nonsecure-abis-always-match-c, r=compiler-errors
Withdraw the claim `extern "C-cmse-nonsecure-*"` always matches `extern "C"` We currently claim that `extern "C-cmse-nonsecure-*"` ABIs will always match `extern "C"`, but that seems... **optimistic** when one considers that `extern "C"` is ambiguous enough to be redefined in ways we may not want the Cortex M Security Extensions ABIs to mirror. If some configuration, feature, or other platform quirk that applied to Arm CPUs with CMSE would modify the `extern "C"` ABI, it does not seem like we should guarantee that also applies to the `extern "cmse-nonsecure-*"` ABIs. Anything involving target modifiers that might affect register availability or usage could make us liars if, for instance, clang decides those apply to normal C functions but not ones with the CMSE attributes, but we still want to have interop with the C compiler. We simply do not control enough of the factors involved to both force these ABIs to match and still provide useful interop, so we shouldn't implicitly promise they do. We should leave this judgement call to the decisions of platform experts who can afford to keep up with the latest news from Cambridge, instead of enshrining today's hopeful guess forever in Rust's permitted ABIs. It's a bit weird anyways. - The attributes are `__attribute__((cmse_nonsecure_call))` and `__attribute__((cmse_nonsecure_entry))`, so the obvious choice is `extern "cmse-nonsecure-call"` and `extern "cmse-nonsecure-entry"`. - We do not prefix any other ABI that reflects (or even *is*) a C ABI with "C-", with the exception of the Rust-defined `extern "C-unwind`", e.g. we do not have `extern "C-aapcs"` or `extern "C-sysv64"`. Tracking issues: - rust-lang#75835 - rust-lang#81391
2 parents 7854342 + b769c62 commit bb145c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+482
-489
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ impl fmt::Display for CanonAbi {
6363
CanonAbi::Custom => ExternAbi::Custom,
6464
CanonAbi::Arm(arm_call) => match arm_call {
6565
ArmCall::Aapcs => ExternAbi::Aapcs { unwind: false },
66-
ArmCall::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
67-
ArmCall::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
66+
ArmCall::CCmseNonSecureCall => ExternAbi::CmseNonSecureCall,
67+
ArmCall::CCmseNonSecureEntry => ExternAbi::CmseNonSecureEntry,
6868
},
6969
CanonAbi::GpuKernel => ExternAbi::GpuKernel,
7070
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ pub enum ExternAbi {
5555
unwind: bool,
5656
},
5757
/// extremely constrained barely-C ABI for TrustZone
58-
CCmseNonSecureCall,
58+
CmseNonSecureCall,
5959
/// extremely constrained barely-C ABI for TrustZone
60-
CCmseNonSecureEntry,
60+
CmseNonSecureEntry,
6161

6262
/* gpu */
6363
/// An entry-point function called by the GPU's host
@@ -136,8 +136,6 @@ macro_rules! abi_impls {
136136
abi_impls! {
137137
ExternAbi = {
138138
C { unwind: false } =><= "C",
139-
CCmseNonSecureCall =><= "C-cmse-nonsecure-call",
140-
CCmseNonSecureEntry =><= "C-cmse-nonsecure-entry",
141139
C { unwind: true } =><= "C-unwind",
142140
Rust =><= "Rust",
143141
Aapcs { unwind: false } =><= "aapcs",
@@ -146,6 +144,8 @@ abi_impls! {
146144
AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
147145
Cdecl { unwind: false } =><= "cdecl",
148146
Cdecl { unwind: true } =><= "cdecl-unwind",
147+
CmseNonSecureCall =><= "cmse-nonsecure-call",
148+
CmseNonSecureEntry =><= "cmse-nonsecure-entry",
149149
Custom =><= "custom",
150150
EfiApi =><= "efiapi",
151151
Fastcall { unwind: false } =><= "fastcall",

compiler/rustc_ast_lowering/src/stability.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
124124
feature: sym::abi_riscv_interrupt,
125125
explain: GateReason::Experimental,
126126
}),
127-
ExternAbi::CCmseNonSecureCall => Err(UnstableAbi {
127+
ExternAbi::CmseNonSecureCall => Err(UnstableAbi {
128128
abi,
129-
feature: sym::abi_c_cmse_nonsecure_call,
129+
feature: sym::abi_cmse_nonsecure_call,
130130
explain: GateReason::Experimental,
131131
}),
132-
ExternAbi::CCmseNonSecureEntry => Err(UnstableAbi {
132+
ExternAbi::CmseNonSecureEntry => Err(UnstableAbi {
133133
abi,
134134
feature: sym::cmse_nonsecure_entry,
135135
explain: GateReason::Experimental,

compiler/rustc_error_codes/src/error_codes/E0775.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Erroneous code example:
88
```ignore (no longer emitted)
99
#![feature(cmse_nonsecure_entry)]
1010
11-
pub extern "C-cmse-nonsecure-entry" fn entry_function() {}
11+
pub extern "cmse-nonsecure-entry" fn entry_function() {}
1212
```
1313

1414
To fix this error, compile your code for a Rust target that supports the
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
The `C-cmse-nonsecure-call` ABI can only be used with function pointers.
1+
The `cmse-nonsecure-call` ABI can only be used with function pointers.
22

33
Erroneous code example:
44

55
```compile_fail,E0781
6-
#![feature(abi_c_cmse_nonsecure_call)]
6+
#![feature(abi_cmse_nonsecure_call)]
77
8-
pub extern "C-cmse-nonsecure-call" fn test() {}
8+
pub extern "cmse-nonsecure-call" fn test() {}
99
```
1010

11-
The `C-cmse-nonsecure-call` ABI should be used by casting function pointers to
11+
The `cmse-nonsecure-call` ABI should be used by casting function pointers to
1212
specific addresses.

compiler/rustc_error_codes/src/error_codes/E0798.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Functions marked as `C-cmse-nonsecure-call` place restrictions on their
1+
Functions marked as `cmse-nonsecure-call` place restrictions on their
22
inputs and outputs.
33

44
- inputs must fit in the 4 available 32-bit argument registers. Alignment
@@ -12,12 +12,12 @@ see [arm's aapcs32](https://github.com/ARM-software/abi-aa/releases).
1212

1313
Erroneous code example:
1414

15-
```ignore (only fails on supported targets)
16-
#![feature(abi_c_cmse_nonsecure_call)]
15+
```ignore (host errors will not match for target)
16+
#![feature(abi_cmse_nonsecure_call)]
1717
1818
#[no_mangle]
1919
pub fn test(
20-
f: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
20+
f: extern "cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
2121
) -> u32 {
2222
f(1, 2, 3, 4, 5)
2323
}
@@ -27,12 +27,12 @@ Arguments' alignment is respected. In the example below, padding is inserted
2727
so that the `u64` argument is passed in registers r2 and r3. There is then no
2828
room left for the final `f32` argument
2929

30-
```ignore (only fails on supported targets)
31-
#![feature(abi_c_cmse_nonsecure_call)]
30+
```ignore (host errors will not match for target)
31+
#![feature(abi_cmse_nonsecure_call)]
3232
3333
#[no_mangle]
3434
pub fn test(
35-
f: extern "C-cmse-nonsecure-call" fn(u32, u64, f32) -> u32,
35+
f: extern "cmse-nonsecure-call" fn(u32, u64, f32) -> u32,
3636
) -> u32 {
3737
f(1, 2, 3.0)
3838
}

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,5 +690,5 @@ E0805: 0805,
690690
// E0723, // unstable feature in `const` context
691691
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
692692
// E0744, // merged into E0728
693-
// E0776, // Removed; cmse_nonsecure_entry is now `C-cmse-nonsecure-entry`
693+
// E0776, // Removed; `#[cmse_nonsecure_entry]` is now `extern "cmse-nonsecure-entry"`
694694
// E0796, // unused error code. We use `static_mut_refs` lint instead.

compiler/rustc_feature/src/removed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ declare_features! (
5454

5555
/// Allows using the `amdgpu-kernel` ABI.
5656
(removed, abi_amdgpu_kernel, "1.77.0", Some(51575), None, 120495),
57+
(removed, abi_c_cmse_nonsecure_call, "CURRENT_RUSTC_VERSION", Some(81391), Some("renamed to abi_cmse_nonsecure_call"), 142146),
5758
(removed, advanced_slice_patterns, "1.42.0", Some(62254),
5859
Some("merged into `#![feature(slice_patterns)]`"), 67712),
5960
(removed, allocator, "1.0.0", None, None),

compiler/rustc_feature/src/unstable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ declare_features! (
353353

354354
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
355355
(unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
356-
/// Allows `extern "C-cmse-nonsecure-call" fn()`.
357-
(unstable, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391)),
356+
/// Allows `extern "cmse-nonsecure-call" fn()`.
357+
(unstable, abi_cmse_nonsecure_call, "CURRENT_RUSTC_VERSION", Some(81391)),
358358
/// Allows `extern "custom" fn()`.
359359
(unstable, abi_custom, "CURRENT_RUSTC_VERSION", Some(140829)),
360360
/// Allows `extern "gpu-kernel" fn()`.
@@ -431,7 +431,7 @@ declare_features! (
431431
(unstable, closure_lifetime_binder, "1.64.0", Some(97362)),
432432
/// Allows `#[track_caller]` on closures and coroutines.
433433
(unstable, closure_track_caller, "1.57.0", Some(87417)),
434-
/// Allows `extern "C-cmse-nonsecure-entry" fn()`.
434+
/// Allows `extern "cmse-nonsecure-entry" fn()`.
435435
(unstable, cmse_nonsecure_entry, "1.48.0", Some(75835)),
436436
/// Allows `async {}` expressions in const contexts.
437437
(unstable, const_async_blocks, "1.53.0", Some(85368)),

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are fo
7373
.label = `for<...>` is here
7474
7575
hir_analysis_cmse_call_generic =
76-
function pointers with the `"C-cmse-nonsecure-call"` ABI cannot contain generics in their type
76+
function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
7777
7878
hir_analysis_cmse_entry_generic =
79-
functions with the `"C-cmse-nonsecure-entry"` ABI cannot contain generics in their type
79+
functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
8080
8181
hir_analysis_cmse_inputs_stack_spill =
8282
arguments for `{$abi}` function too large to pass via registers

0 commit comments

Comments
 (0)