Repository navigation
Closed
Labels
A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-naked_functions`#![feature(naked_functions)]``#![feature(naked_functions)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This is a tracking issue for the RFC "Constrained Naked Functions" (rust-lang/rfcs#2972).
The feature gate for the issue is #![feature(naked_functions)].
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implement the RFC
- Confirm that all errors and warnings are emitted properly
- Final review of attributes that are incompatible with
#[naked] - Determine precise inlining gurantees
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
None.
Implementation history
Metadata
Metadata
Assignees
Labels
A-nakedArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSArea: `#[naked]`, prologue and epilogue-free, functions, https://git.io/vAzzSB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-naked_functions`#![feature(naked_functions)]``#![feature(naked_functions)]`S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
safinaskar commentedon Jan 23, 2022
"produce a clear warning if any of the above suggestions are not heeded" in RFC seems to contain typo
bstrie commentedon Jan 25, 2022
This is implemented, checking the box.
Adding a new step: "Confirm that all errors and warnings are emitted properly".
bstrie commentedon Feb 2, 2022
Request for Stabilization
A proposal that the
naked_functionsfeature be stabilized for Rust 1.60, to be released 2022-04-07. A stabilization PR can be found at #93587.Summary
Adds a new attribute,
#[naked], which may be applied to functions. When applied to a function, the compiler will not emit a function prologue when generating code for this function. This attribute is analogous to__attribute__((naked))in C. The use of this feature allows the programmer to have precise control over the assembly that is generated for a given function.The body of a naked function must consist of a single
asm!invocation. Thisasm!invocation is heavily restricted: the only legal operands areconstandsym, and the only legal options arenoreturn(which is mandatory) andatt_syntax. In lieu of specifying operands, theasm!within a naked function relies on the specifiedexterncalling convention in order to determine the validity of registers.An example of a naked function:
Documentation
The Rust Reference: rust-lang/reference#1153
Tests
nakedandnoinlineLLVM attributes.asm!block, that they must specify thenoreturnoption, that they must not specify any other option exceptatt_syntax, that they only supportconstandsymoperands, that they warn when used withextern "Rust", and that they are incompatible with theinlineattribute.unused_variableslint is suppressed within naked functions.History
This feature was originally proposed in RFC 1201, filed on 2015-07-10 and accepted on 2016-03-21. Support for this feature was added in #32410, landing on 2016-03-23. Development languished for several years as it was realized that the semantics given in RFC 1201 were insufficiently specific. To address this, a minimal subset of naked functions was specified by RFC 2972, filed on 2020-08-07 and accepted on 2021-11-16. Prior to the acceptance of RFC 2972, all of the stricter behavior specified by RFC 2972 was implemented as a series of warn-by-default lints that would trigger on existing uses of the
nakedattribute; these lints became hard errors in #93153 on 2022-01-22. As a result, today RFC 2972 has completely superseded RFC 1201 in describing the semantics of thenakedattribute.Unresolved Questions
__attribute__((naked))prevents the compiler from generating both a function prologue and a function epilogue. However in Rust it was discovered that under some circumstances LLVM will choose to emit instructions following the body of a naked function, which is seemingly non-trivial to prevent. Since most of the utility of naked functions comes from preventing the prologue rather than the epilogue, for the time being this feature has restricted itself to only guaranteeing the absence of the prologue. Instead, the reference will specify that users must not rely on the presence of code following the body of a naked function, and that a future version of Rust reserves the right to guarantee the absence of such code.Stabilize naked_functions
bjorn3 commentedon Feb 2, 2022
There is no observable difference between LLVM adding an epilogue and a following unnamed function starting with instructions identical to a regular epilogue.
bstrie commentedon Feb 2, 2022
@bjorn3 I believe it can cause problems in circumstances such as #32408 (comment) . If someone were to work around that issue by assuming the existence of extra instructions and manually accounting for it, then their code would be broken if Rust ever stopped generating those instructions. It is this sort of edge case that this defensive wording is designed to address.
roblabla commentedon Feb 2, 2022
I believe it's possible to observe a difference when
nakedis coupled with#[link_section]. You could apply that attributed to a naked function to put it in a well-known section that you expect to only contain your function.joshtriplett commentedon Feb 2, 2022
👍 for stabilizing, though I'd like to make sure that there's consensus on #32408 (comment) .
169 remaining items
Rollup merge of rust-lang#138570 - folkertdev:naked-function-target-f…
Rollup merge of rust-lang#138570 - folkertdev:naked-function-target-f…
Unrolled build for rust-lang#138570
Rollup merge of rust-lang#134213 - folkertdev:stabilize-naked-functio…
Rollup merge of rust-lang#134213 - folkertdev:stabilize-naked-functio…
Unrolled build for rust-lang#134213
tgross35 commentedon Apr 22, 2025
With the stabilization at #134213, I believe this can be closed.
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…
Rollup merge of rust-lang#134213 - folkertdev:stabilize-naked-functio…
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…
Auto merge of #128651 - folkertdev:naked-asm-macro-v2, r=Amanieu
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…
Auto merge of #128651 - folkertdev:naked-asm-macro-v2, r=Amanieu
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgr…