-
Notifications
You must be signed in to change notification settings - Fork 13.8k
#[naked]
: report incompatible attributes
#127853
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
Merged
bors
merged 7 commits into
rust-lang:master
from
folkertdev:naked-function-error-messages
Jul 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ceec6dd
update text for E0736 and E0739
folkertdev 4bd3632
improve error message when `#[naked]` is used with `#[inline]`
folkertdev 7e6c083
improve error message when `#[naked]` is used with `#[track-caller] a…
folkertdev 4d082b7
add error message when `#[naked]` is used with `#[test]`
folkertdev c6a166b
switch to an allowlist approach
folkertdev a3bb010
allow `#[target_feature]` on `#[naked]` functions
folkertdev c7e688e
fix `tests/ui/asm/naked-functions.rs` for aarch64
folkertdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
switch to an allowlist approach
- merge error codes - use attribute name that is incompatible in error message - add test for conditional incompatible attribute - add `linkage` to the allowlist
- Loading branch information
commit c6a166bac269eda77b595fdc8ff7290e1372c147
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,7 +536,6 @@ E0794: 0794, | |
E0795: 0795, | ||
E0796: 0796, | ||
E0797: 0797, | ||
E0798: 0798, | ||
); | ||
) | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
error[E0736]: cannot use additional code generation attributes with `#[naked]` | ||
error[E0736]: attribute incompatible with `#[naked]` | ||
--> $DIR/naked-functions-inline.rs:13:1 | ||
| | ||
LL | #[naked] | ||
| -------- function marked with `#[naked]` here | ||
LL | #[inline] | ||
| ^^^^^^^^^ this attribute is incompatible with `#[naked]` | ||
| ^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]` | ||
|
||
error[E0736]: cannot use additional code generation attributes with `#[naked]` | ||
error[E0736]: attribute incompatible with `#[naked]` | ||
--> $DIR/naked-functions-inline.rs:20:1 | ||
| | ||
LL | #[naked] | ||
| -------- function marked with `#[naked]` here | ||
LL | #[inline(always)] | ||
| ^^^^^^^^^^^^^^^^^ this attribute is incompatible with `#[naked]` | ||
| ^^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]` | ||
|
||
error[E0736]: cannot use additional code generation attributes with `#[naked]` | ||
error[E0736]: attribute incompatible with `#[naked]` | ||
--> $DIR/naked-functions-inline.rs:27:1 | ||
| | ||
LL | #[naked] | ||
| -------- function marked with `#[naked]` here | ||
LL | #[inline(never)] | ||
| ^^^^^^^^^^^^^^^^ this attribute is incompatible with `#[naked]` | ||
| ^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]` | ||
|
||
error: aborting due to 3 previous errors | ||
error[E0736]: attribute incompatible with `#[naked]` | ||
--> $DIR/naked-functions-inline.rs:34:19 | ||
| | ||
LL | #[naked] | ||
| -------- function marked with `#[naked]` here | ||
LL | #[cfg_attr(all(), inline(never))] | ||
| ^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0736`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ compile-flags: --target armv5te-unknown-linux-gnueabi | ||
//@ needs-llvm-components: arm | ||
//@ needs-asm-support | ||
//@ build-pass | ||
|
||
#![crate_type = "lib"] | ||
#![feature(no_core, lang_items, rustc_attrs, naked_functions)] | ||
#![no_core] | ||
|
||
#[rustc_builtin_macro] | ||
macro_rules! asm { | ||
() => {}; | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[no_mangle] | ||
#[naked] | ||
#[instruction_set(arm::t32)] | ||
unsafe extern "C" fn test_thumb() { | ||
asm!("bx lr", options(noreturn)); | ||
} | ||
|
||
#[no_mangle] | ||
#[naked] | ||
#[instruction_set(arm::t32)] | ||
unsafe extern "C" fn test_arm() { | ||
asm!("bx lr", options(noreturn)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
#[target_feature]
affects the set of instructions allowed inside inline assembly as well as the exact encoding of certain instructions.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.
yes, I'm going off of #90957 (comment) where @joshtriplett suggests to exclude
#[target_feature]
initially.that was 2 years ago though so maybe that should be re-evaluated. Do you have concerns with allowing
#[target_feature]
now?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.
I don't know what a reason for forbidding it would be, and why @joshtriplett thought it would be hard to get right
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.
well a reason to be cautious is that I think to most (me included) it's not 100% clear what
#[target_feature]
could do. Are we absolutely sure that on no platform, present or future, a target feature would insert additional instructions that violate the assumptions of#[naked]
?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.
What I said at the time was that it might take some care to get right. If we take that care, and commit to avoiding any potential issues that might arise (e.g. locking down what a given
target_feature
means for a naked function and never inserting any instructions for it), then supporting the combination seems fine.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.
With the implementation strategy in #128004 I don't think there is any risk of
#[target_feature]
inserting instructions. The user's inline assembly block is hoisted to a top-level global asm block, and the function itself becomes effectively anextern fn
.So I've now added
target_feature
to the allow list in a separate commit that can be reverted if there are any concerns.