a13f40dae6
`#[naked]`: report incompatible attributes tracking issue: https://github.com/rust-lang/rust/issues/90957 this is a re-implementation of https://github.com/rust-lang/rust/pull/93809 by ``@bstrie`` which was closed 2 years ago due to inactivity. This PR takes some of the final comments into account, specifically providing a little more context in error messages, and using an allow list to determine which attributes are compatible with `#[naked]`. Notable attributes that are incompatible with `#[naked]` are: * `#[inline]` * `#[track_caller]` * ~~`#[target_feature]`~~ (this is now allowed, see PR discussion) * `#[test]`, `#[ignore]`, `#[should_panic]` These attributes just directly conflict with what `#[naked]` should do. Naked functions are still important for systems programming, embedded, and operating systems, so I'd like to move them forward.
255 lines
8.0 KiB
Plaintext
255 lines
8.0 KiB
Plaintext
error: asm with the `pure` option must have at least one output
|
|
--> $DIR/naked-functions.rs:112:14
|
|
|
|
|
LL | asm!("", options(readonly, nostack), options(pure));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^
|
|
|
|
error: this is a user specified error
|
|
--> $DIR/naked-functions.rs:168:5
|
|
|
|
|
LL | compile_error!("this is a user specified error")
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: this is a user specified error
|
|
--> $DIR/naked-functions.rs:174:5
|
|
|
|
|
LL | compile_error!("this is a user specified error");
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: asm template must be a string literal
|
|
--> $DIR/naked-functions.rs:181:10
|
|
|
|
|
LL | asm!(invalid_syntax)
|
|
| ^^^^^^^^^^^^^^
|
|
|
|
error: patterns not allowed in naked function parameters
|
|
--> $DIR/naked-functions.rs:19:5
|
|
|
|
|
LL | mut a: u32,
|
|
| ^^^^^
|
|
|
|
error: patterns not allowed in naked function parameters
|
|
--> $DIR/naked-functions.rs:21:5
|
|
|
|
|
LL | &b: &i32,
|
|
| ^^
|
|
|
|
error: patterns not allowed in naked function parameters
|
|
--> $DIR/naked-functions.rs:23:6
|
|
|
|
|
LL | (None | Some(_)): Option<std::ptr::NonNull<u8>>,
|
|
| ^^^^^^^^^^^^^^
|
|
|
|
error: patterns not allowed in naked function parameters
|
|
--> $DIR/naked-functions.rs:25:5
|
|
|
|
|
LL | P { x, y }: P,
|
|
| ^^^^^^^^^^
|
|
|
|
error: referencing function parameters is not allowed in naked functions
|
|
--> $DIR/naked-functions.rs:34:5
|
|
|
|
|
LL | a + 1
|
|
| ^
|
|
|
|
|
= help: follow the calling convention in asm block to use parameters
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:32:1
|
|
|
|
|
LL | pub unsafe extern "C" fn inc(a: u32) -> u32 {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL |
|
|
LL | a + 1
|
|
| ----- non-asm is unsupported in naked functions
|
|
|
|
error: referencing function parameters is not allowed in naked functions
|
|
--> $DIR/naked-functions.rs:41:31
|
|
|
|
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
|
|
| ^
|
|
|
|
|
= help: follow the calling convention in asm block to use parameters
|
|
|
|
error[E0787]: only `const` and `sym` operands are supported in naked functions
|
|
--> $DIR/naked-functions.rs:41:23
|
|
|
|
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
|
|
| ^^^^^^^^^
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:47:1
|
|
|
|
|
LL | pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL |
|
|
LL | (|| a + 1)()
|
|
| ------------ non-asm is unsupported in naked functions
|
|
|
|
error[E0787]: only `const` and `sym` operands are supported in naked functions
|
|
--> $DIR/naked-functions.rs:64:10
|
|
|
|
|
LL | in(reg) a,
|
|
| ^^^^^^^^^
|
|
LL |
|
|
LL | inlateout(reg) b,
|
|
| ^^^^^^^^^^^^^^^^
|
|
LL | inout(reg) c,
|
|
| ^^^^^^^^^^^^
|
|
LL | lateout(reg) d,
|
|
| ^^^^^^^^^^^^^^
|
|
LL | out(reg) e,
|
|
| ^^^^^^^^^^
|
|
|
|
error[E0787]: asm in naked functions must use `noreturn` option
|
|
--> $DIR/naked-functions.rs:62:5
|
|
|
|
|
LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
|
|
LL | |
|
|
LL | | in(reg) a,
|
|
LL | |
|
|
... |
|
|
LL | | sym G,
|
|
LL | | );
|
|
| |_____^
|
|
|
|
|
help: consider specifying that the asm block is responsible for returning from the function
|
|
|
|
|
LL | sym G, options(noreturn),
|
|
| +++++++++++++++++++
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:53:1
|
|
|
|
|
LL | pub unsafe extern "C" fn unsupported_operands() {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL |
|
|
LL | let mut a = 0usize;
|
|
| ------------------- non-asm is unsupported in naked functions
|
|
LL | let mut b = 0usize;
|
|
| ------------------- non-asm is unsupported in naked functions
|
|
LL | let mut c = 0usize;
|
|
| ------------------- non-asm is unsupported in naked functions
|
|
LL | let mut d = 0usize;
|
|
| ------------------- non-asm is unsupported in naked functions
|
|
LL | let mut e = 0usize;
|
|
| ------------------- non-asm is unsupported in naked functions
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:76:1
|
|
|
|
|
LL | pub extern "C" fn missing_assembly() {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error[E0787]: asm in naked functions must use `noreturn` option
|
|
--> $DIR/naked-functions.rs:84:9
|
|
|
|
|
LL | asm!("");
|
|
| ^^^^^^^^
|
|
|
|
|
help: consider specifying that the asm block is responsible for returning from the function
|
|
|
|
|
LL | asm!("", options(noreturn));
|
|
| +++++++++++++++++++
|
|
|
|
error[E0787]: asm in naked functions must use `noreturn` option
|
|
--> $DIR/naked-functions.rs:86:9
|
|
|
|
|
LL | asm!("");
|
|
| ^^^^^^^^
|
|
|
|
|
help: consider specifying that the asm block is responsible for returning from the function
|
|
|
|
|
LL | asm!("", options(noreturn));
|
|
| +++++++++++++++++++
|
|
|
|
error[E0787]: asm in naked functions must use `noreturn` option
|
|
--> $DIR/naked-functions.rs:88:9
|
|
|
|
|
LL | asm!("");
|
|
| ^^^^^^^^
|
|
|
|
|
help: consider specifying that the asm block is responsible for returning from the function
|
|
|
|
|
LL | asm!("", options(noreturn));
|
|
| +++++++++++++++++++
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:81:1
|
|
|
|
|
LL | pub extern "C" fn too_many_asm_blocks() {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
...
|
|
LL | asm!("");
|
|
| -------- multiple asm blocks are unsupported in naked functions
|
|
LL |
|
|
LL | asm!("");
|
|
| -------- multiple asm blocks are unsupported in naked functions
|
|
LL |
|
|
LL | asm!("", options(noreturn));
|
|
| --------------------------- multiple asm blocks are unsupported in naked functions
|
|
|
|
error: referencing function parameters is not allowed in naked functions
|
|
--> $DIR/naked-functions.rs:98:11
|
|
|
|
|
LL | *&y
|
|
| ^
|
|
|
|
|
= help: follow the calling convention in asm block to use parameters
|
|
|
|
error[E0787]: naked functions must contain a single asm block
|
|
--> $DIR/naked-functions.rs:96:5
|
|
|
|
|
LL | pub extern "C" fn inner(y: usize) -> usize {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
LL |
|
|
LL | *&y
|
|
| --- non-asm is unsupported in naked functions
|
|
|
|
error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_flags`
|
|
--> $DIR/naked-functions.rs:106:5
|
|
|
|
|
LL | asm!("", options(nomem, preserves_flags, noreturn));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error[E0787]: asm options unsupported in naked functions: `pure`, `readonly`, `nostack`
|
|
--> $DIR/naked-functions.rs:112:5
|
|
|
|
|
LL | asm!("", options(readonly, nostack), options(pure));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error[E0787]: asm in naked functions must use `noreturn` option
|
|
--> $DIR/naked-functions.rs:112:5
|
|
|
|
|
LL | asm!("", options(readonly, nostack), options(pure));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: consider specifying that the asm block is responsible for returning from the function
|
|
|
|
|
LL | asm!("", options(noreturn), options(readonly, nostack), options(pure));
|
|
| +++++++++++++++++++
|
|
|
|
error[E0787]: asm options unsupported in naked functions: `may_unwind`
|
|
--> $DIR/naked-functions.rs:120:5
|
|
|
|
|
LL | asm!("", options(noreturn, may_unwind));
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
warning: Rust ABI is unsupported in naked functions
|
|
--> $DIR/naked-functions.rs:125:1
|
|
|
|
|
LL | pub unsafe fn default_abi() {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: `#[warn(undefined_naked_function_abi)]` on by default
|
|
|
|
warning: Rust ABI is unsupported in naked functions
|
|
--> $DIR/naked-functions.rs:131:1
|
|
|
|
|
LL | pub unsafe fn rust_abi() {
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: aborting due to 27 previous errors; 2 warnings emitted
|
|
|
|
For more information about this error, try `rustc --explain E0787`.
|