-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
#[naked]
: report incompatible attributes
#127853
#[naked]
: report incompatible attributes
#127853
Conversation
rustbot has assigned @compiler-errors. Use |
// | ||
// * `#[inline]` | ||
// * `#[track_caller]` | ||
// * `#[target_feature]` |
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 an extern 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.
r? bjorn3 |
@bors r+ |
…ssages, r=bjorn3 `#[naked]`: report incompatible attributes tracking issue: rust-lang#90957 this is a re-implementation of rust-lang#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 discussion below) * `#[test]`, `#[ignore]`, `#[should_panic]` There may be valid use cases for `#[target_feature]` but for now it is disallowed. The others 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.
Rollup of 9 pull requests Successful merges: - rust-lang#124941 (Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str`) - rust-lang#127853 (`#[naked]`: report incompatible attributes) - rust-lang#128210 (rustdoc: change title of search results) - rust-lang#128223 (Refactor complex conditions in `collect_tokens_trailing_token`) - rust-lang#128224 (Remove unnecessary range replacements) - rust-lang#128226 (Remove redundant option that was just encoding that a slice was empty) - rust-lang#128227 (CI: do not respect custom try jobs for unrolled perf builds) - rust-lang#128229 (Improve `extern "<abi>" unsafe fn()` error message) - rust-lang#128235 (Fix `Iterator::filter` docs) r? `@ghost` `@rustbot` modify labels: rollup
@bors r- It looks like the changes here are breaking the compiler_builtins build #128248 (comment). It seems like link-related attributes ( |
right, that's a (perma-unstable, apparently) unstable attribute and only |
@rustbot ready though are there other unstable attributes that may be missing from that list? is there a comprehensive list of such attributes? |
I don't know of any list specific for attributes unfortunately, just the huge list in Does this correctly flag on |
I'm pretty sure bors will fail when running aarch64 tests. The last commit fixes those issues. Not sure what should happen but because the bors thing is tied to a commit I think some action is needed |
Bors bumps you out of the queue when you push, just doesn't update the labels for some reason. Your last change switched from |
well, "the |
Ah weird, yeah seems reasonable. @bors r=bjorn3 |
…ssages, r=bjorn3 `#[naked]`: report incompatible attributes tracking issue: rust-lang#90957 this is a re-implementation of rust-lang#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.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#127853 (`#[naked]`: report incompatible attributes) - rust-lang#128228 (Stabilize `const_waker`) - rust-lang#128276 (Add a README to rustbook to explain its purpose) - rust-lang#128279 (Stabilize `is_sorted`) - rust-lang#128282 (bitwise and bytewise methods on `NonZero`) - rust-lang#128285 (rustc book: document how the RUST_TARGET_PATH variable is used) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#127853 (`#[naked]`: report incompatible attributes) - rust-lang#128276 (Add a README to rustbook to explain its purpose) - rust-lang#128279 (Stabilize `is_sorted`) - rust-lang#128282 (bitwise and bytewise methods on `NonZero`) - rust-lang#128285 (rustc book: document how the RUST_TARGET_PATH variable is used) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127853 - folkertdev:naked-function-error-messages, r=bjorn3 `#[naked]`: report incompatible attributes tracking issue: rust-lang#90957 this is a re-implementation of rust-lang#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.
I'm currently running into "error[E0736]: attribute incompatible with |
…mment, r=bjorn3 make `///` doc comments compatible with naked functions tracking issue: rust-lang#90957 reported in rust-lang#127853 (comment) it turns out `/// doc comment` and `#[doc = "doc comment"]` are represented differently, at least at the point where we perform the check for what should be allowed. The `///` style doc comment is now also allowed. r? `@bjorn3` cc `@hsanzg`
Having the same issue over here. |
The fix is in #128380, unless your case is different @portasynthinca3. It will probably make it into either today or tomorrow's nightly. |
…mment, r=bjorn3 make `///` doc comments compatible with naked functions tracking issue: rust-lang#90957 reported in rust-lang#127853 (comment) it turns out `/// doc comment` and `#[doc = "doc comment"]` are represented differently, at least at the point where we perform the check for what should be allowed. The `///` style doc comment is now also allowed. r? ``@bjorn3`` cc ``@hsanzg``
Rollup merge of rust-lang#128380 - folkertdev:naked-compatible-doc-comment, r=bjorn3 make `///` doc comments compatible with naked functions tracking issue: rust-lang#90957 reported in rust-lang#127853 (comment) it turns out `/// doc comment` and `#[doc = "doc comment"]` are represented differently, at least at the point where we perform the check for what should be allowed. The `///` style doc comment is now also allowed. r? ``@bjorn3`` cc ``@hsanzg``
rust-lang/rust#127853 (comment) ``` error[E0736]: attribute incompatible with `#[naked]` --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gba-0.11.6/src/asm_runtime.rs:164:1 | 164 | /// Returns 0 in `r0`, while placing the `numerator` into `r1`. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `` attribute is incompatible with `#[naked]` ... 172 | #[naked] | -------- function marked with `#[naked]` here ```
…bjorn3 make `///` doc comments compatible with naked functions tracking issue: rust-lang/rust#90957 reported in rust-lang/rust#127853 (comment) it turns out `/// doc comment` and `#[doc = "doc comment"]` are represented differently, at least at the point where we perform the check for what should be allowed. The `///` style doc comment is now also allowed. r? ``@bjorn3`` cc ``@hsanzg``
Before this PR was merged, I was able to use |
The idea of the linked PR is to implement naked functions like this core::arch::global_asm!(".globl page_fault_handler","page_fault_handler:", "ud2");
extern "x86-interrupt" {
fn page_fault_handler(_: u64, _: u64);
} but with support for (const) generics and with being able to export the symbol (which is tricky with extern function declarations in user space). I think in that world, the However, in the meantime, we probably should not break anyone? @bjorn3 do you have thoughts on what to do? |
@Freax13 could you open a new bug for this crash? It seems like that very specific combination of |
tracking issue: #90957
this is a re-implementation of #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]
(this is now allowed, see PR discussion)#[target_feature]
#[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.