Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bc8631e

Browse files
authored
Rollup merge of rust-lang#127766 - folkertdev:c-cmse-nonsecure-entry, r=jackh726
add `extern "C-cmse-nonsecure-entry" fn` tracking issue rust-lang#75835 in rust-lang#75835 (comment) it was decided that using an abi, rather than an attribute, was the right way to go for this feature. This PR adds that ABI and removes the `#[cmse_nonsecure_entry]` attribute. All relevant tests have been updated, some are now obsolete and have been removed. Error 0775 is no longer generated. It contains the list of targets that support the CMSE feature, and maybe we want to still use this? right now a generic "this abi is not supported on this platform" error is returned when this abi is used on an unsupported platform. On the other hand, users of this abi are likely to be experienced rust users, so maybe the generic error is good enough.
2 parents 2836482 + ac9a49f commit bc8631e

File tree

45 files changed

+185
-182
lines changed

Some content is hidden

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

45 files changed

+185
-182
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
6161
Conv::CCmseNonSecureCall => {
6262
sess.dcx().fatal("C-cmse-nonsecure-call call conv is not yet implemented");
6363
}
64+
Conv::CCmseNonSecureEntry => {
65+
sess.dcx().fatal("C-cmse-nonsecure-entry call conv is not yet implemented");
66+
}
6467

6568
Conv::Msp430Intr | Conv::PtxKernel | Conv::AvrInterrupt | Conv::AvrNonBlockingInterrupt => {
6669
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
422422
if let Conv::RiscvInterrupt { kind } = self.conv {
423423
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", kind.as_str()));
424424
}
425+
if let Conv::CCmseNonSecureEntry = self.conv {
426+
func_attrs.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry"))
427+
}
425428
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs });
426429

427430
let mut i = 0;
@@ -659,9 +662,11 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
659662
impl From<Conv> for llvm::CallConv {
660663
fn from(conv: Conv) -> Self {
661664
match conv {
662-
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall | Conv::RiscvInterrupt { .. } => {
663-
llvm::CCallConv
664-
}
665+
Conv::C
666+
| Conv::Rust
667+
| Conv::CCmseNonSecureCall
668+
| Conv::CCmseNonSecureEntry
669+
| Conv::RiscvInterrupt { .. } => llvm::CCallConv,
665670
Conv::Cold => llvm::ColdCallConv,
666671
Conv::PreserveMost => llvm::PreserveMost,
667672
Conv::PreserveAll => llvm::PreserveAll,

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
483483
let allocated_pointer = AttributeKind::AllocatedPointer.create_attr(cx.llcx);
484484
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), &[allocated_pointer]);
485485
}
486-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY) {
487-
to_add.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry"));
488-
}
489486
if let Some(align) = codegen_fn_attrs.alignment {
490487
llvm::set_alignment(llfn, align);
491488
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
195195
}
196196
}
197197
}
198-
sym::cmse_nonsecure_entry => {
199-
if let Some(fn_sig) = fn_sig()
200-
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. })
201-
{
202-
struct_span_code_err!(
203-
tcx.dcx(),
204-
attr.span,
205-
E0776,
206-
"`#[cmse_nonsecure_entry]` requires C ABI"
207-
)
208-
.emit();
209-
}
210-
if !tcx.sess.target.llvm_target.contains("thumbv8m") {
211-
struct_span_code_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
212-
.emit();
213-
}
214-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY
215-
}
216198
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
217199
sym::track_caller => {
218200
let is_closure = tcx.is_closure_like(did.to_def_id());

compiler/rustc_error_codes/src/error_codes/E0775.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M
24
extension.
35

46
Erroneous code example:
57

6-
```compile_fail,E0775
8+
```ignore (no longer emitted)
79
#![feature(cmse_nonsecure_entry)]
810
9-
#[cmse_nonsecure_entry]
10-
pub extern "C" fn entry_function() {}
11+
pub extern "C-cmse-nonsecure-entry" fn entry_function() {}
1112
```
1213

1314
To fix this error, compile your code for a Rust target that supports the

compiler/rustc_error_codes/src/error_codes/E0776.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
`#[cmse_nonsecure_entry]` functions require a C ABI
24

35
Erroneous code example:
46

5-
```compile_fail,E0776
7+
```ignore (no longer emitted)
68
#![feature(cmse_nonsecure_entry)]
79
810
#[no_mangle]

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,5 @@ E0800: 0800,
681681
// E0723, // unstable feature in `const` context
682682
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
683683
// E0744, // merged into E0728
684+
// E0776, // Removed; cmse_nonsecure_entry is now `C-cmse-nonsecure-entry`
684685
// E0796, // unused error code. We use `static_mut_refs` lint instead.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
551551
EncodeCrossCrate::No, experimental!(register_tool),
552552
),
553553

554-
gated!(
555-
cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
556-
EncodeCrossCrate::No, experimental!(cmse_nonsecure_entry)
557-
),
558554
// RFC 2632
559555
gated!(
560556
const_trait, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, const_trait_impl,

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ declare_features! (
395395
(unstable, closure_lifetime_binder, "1.64.0", Some(97362)),
396396
/// Allows `#[track_caller]` on closures and coroutines.
397397
(unstable, closure_track_caller, "1.57.0", Some(87417)),
398-
/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
398+
/// Allows `extern "C-cmse-nonsecure-entry" fn()`.
399399
(unstable, cmse_nonsecure_entry, "1.48.0", Some(75835)),
400400
/// Allows `async {}` expressions in const contexts.
401401
(unstable, const_async_blocks, "1.53.0", Some(85368)),

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ bitflags::bitflags! {
120120
/// #[ffi_const]: applies clang's `const` attribute to a foreign function
121121
/// declaration.
122122
const FFI_CONST = 1 << 12;
123-
/// #[cmse_nonsecure_entry]: with a TrustZone-M extension, declare a
124-
/// function as an entry function from Non-Secure code.
125-
const CMSE_NONSECURE_ENTRY = 1 << 13;
123+
// (Bit 13 was used for `#[cmse_nonsecure_entry]`, but is now unused.)
126124
// (Bit 14 was used for `#[coverage(off)]`, but is now unused.)
127125
/// `#[used(linker)]`:
128126
/// indicates that neither LLVM nor the linker will eliminate this function.

0 commit comments

Comments
 (0)