-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
add extern "C-cmse-nonsecure-entry" fn
#127766
Changes from all commits
1ddd67a
5722a80
a33dcb3
a41c209
4d75a4f
ac9a49f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,6 +422,9 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { | |
if let Conv::RiscvInterrupt { kind } = self.conv { | ||
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", kind.as_str())); | ||
} | ||
if let Conv::CCmseNonSecureEntry = self.conv { | ||
func_attrs.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry")) | ||
} | ||
Comment on lines
+425
to
+427
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This got moved here from compiler/rustc_codegen_llvm/src/attributes.rs |
||
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs }); | ||
|
||
let mut i = 0; | ||
|
@@ -659,9 +662,11 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { | |
impl From<Conv> for llvm::CallConv { | ||
fn from(conv: Conv) -> Self { | ||
match conv { | ||
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall | Conv::RiscvInterrupt { .. } => { | ||
llvm::CCallConv | ||
} | ||
Conv::C | ||
| Conv::Rust | ||
| Conv::CCmseNonSecureCall | ||
| Conv::CCmseNonSecureEntry | ||
| Conv::RiscvInterrupt { .. } => llvm::CCallConv, | ||
Conv::Cold => llvm::ColdCallConv, | ||
Conv::PreserveMost => llvm::PreserveMost, | ||
Conv::PreserveAll => llvm::PreserveAll, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,24 +195,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { | |
} | ||
} | ||
} | ||
sym::cmse_nonsecure_entry => { | ||
if let Some(fn_sig) = fn_sig() | ||
&& !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. }) | ||
{ | ||
struct_span_code_err!( | ||
tcx.dcx(), | ||
attr.span, | ||
E0776, | ||
"`#[cmse_nonsecure_entry]` requires C ABI" | ||
) | ||
.emit(); | ||
} | ||
if !tcx.sess.target.llvm_target.contains("thumbv8m") { | ||
struct_span_code_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension") | ||
.emit(); | ||
} | ||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY | ||
} | ||
Comment on lines
-198
to
-215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these checks are no longer needed, as the ABI now is specified explicitly, and checks for if an ABI is supported on a target are already in place here: compiler/rustc_target/src/spec/mod.rs |
||
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL, | ||
sym::track_caller => { | ||
let is_closure = tcx.is_closure_like(did.to_def_id()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
#### Note: this error code is no longer emitted by the compiler. | ||
|
||
`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M | ||
extension. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0775 | ||
```ignore (no longer emitted) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this test also get the "Note: this error code is no longer emitted by the compiler." at the top? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I added that now. We had some thoughts about re-using this error code, but if we end up doing that we can just remove that note. |
||
#![feature(cmse_nonsecure_entry)] | ||
|
||
#[cmse_nonsecure_entry] | ||
pub extern "C" fn entry_function() {} | ||
pub extern "C-cmse-nonsecure-entry" fn entry_function() {} | ||
``` | ||
|
||
To fix this error, compile your code for a Rust target that supports the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,9 +120,7 @@ bitflags::bitflags! { | |
/// #[ffi_const]: applies clang's `const` attribute to a foreign function | ||
/// declaration. | ||
const FFI_CONST = 1 << 12; | ||
/// #[cmse_nonsecure_entry]: with a TrustZone-M extension, declare a | ||
/// function as an entry function from Non-Secure code. | ||
const CMSE_NONSECURE_ENTRY = 1 << 13; | ||
// (Bit 13 was used for `#[cmse_nonsecure_entry]`, but is now unused.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this comment is needed. I guess bit 7 maybe also was used previously but no more? There's no comment there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are just following bit 14 here
I'm not sure what happened to bit 7, but it seems useful to document what bits were used for (e.g. if we ever run out of bits in this 32-bit integer, and might want to re-use one of the unused ones). |
||
// (Bit 14 was used for `#[coverage(off)]`, but is now unused.) | ||
/// `#[used(linker)]`: | ||
/// indicates that neither LLVM nor the linker will eliminate this function. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cranelift does not support any ARM cortex-m targets anyway. So this does not change anything.