Skip to content

Commit 8825997

Browse files
authored
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 8cf5fad + 3beed38 commit 8825997

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

+484
-491
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
@@ -59,9 +59,9 @@ pub enum ExternAbi {
5959
unwind: bool,
6060
},
6161
/// extremely constrained barely-C ABI for TrustZone
62-
CCmseNonSecureCall,
62+
CmseNonSecureCall,
6363
/// extremely constrained barely-C ABI for TrustZone
64-
CCmseNonSecureEntry,
64+
CmseNonSecureEntry,
6565

6666
/* gpu */
6767
/// An entry-point function called by the GPU's host
@@ -140,8 +140,6 @@ macro_rules! abi_impls {
140140
abi_impls! {
141141
ExternAbi = {
142142
C { unwind: false } =><= "C",
143-
CCmseNonSecureCall =><= "C-cmse-nonsecure-call",
144-
CCmseNonSecureEntry =><= "C-cmse-nonsecure-entry",
145143
C { unwind: true } =><= "C-unwind",
146144
Rust =><= "Rust",
147145
Aapcs { unwind: false } =><= "aapcs",
@@ -150,6 +148,8 @@ abi_impls! {
150148
AvrNonBlockingInterrupt =><= "avr-non-blocking-interrupt",
151149
Cdecl { unwind: false } =><= "cdecl",
152150
Cdecl { unwind: true } =><= "cdecl-unwind",
151+
CmseNonSecureCall =><= "cmse-nonsecure-call",
152+
CmseNonSecureEntry =><= "cmse-nonsecure-entry",
153153
Custom =><= "custom",
154154
EfiApi =><= "efiapi",
155155
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
@@ -127,12 +127,12 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
127127
feature: sym::abi_riscv_interrupt,
128128
explain: GateReason::Experimental,
129129
}),
130-
ExternAbi::CCmseNonSecureCall => Err(UnstableAbi {
130+
ExternAbi::CmseNonSecureCall => Err(UnstableAbi {
131131
abi,
132-
feature: sym::abi_c_cmse_nonsecure_call,
132+
feature: sym::abi_cmse_nonsecure_call,
133133
explain: GateReason::Experimental,
134134
}),
135-
ExternAbi::CCmseNonSecureEntry => Err(UnstableAbi {
135+
ExternAbi::CmseNonSecureEntry => Err(UnstableAbi {
136136
abi,
137137
feature: sym::cmse_nonsecure_entry,
138138
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)