Skip to content

Commit aaef383

Browse files
bstriefolkertdev
authored andcommitted
Add naked to the attribute index
1 parent 1375337 commit aaef383

File tree

2 files changed

+46
-71
lines changed

2 files changed

+46
-71
lines changed

src/attributes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ The following is an index of all built-in attributes.
287287
- Code generation
288288
- [`inline`] --- Hint to inline code.
289289
- [`cold`] --- Hint that a function is unlikely to be called.
290+
- [`naked`] - Prevent the compiler from emitting a function prologue.
290291
- [`no_builtins`] --- Disables use of certain built-in functions.
291292
- [`target_feature`] --- Configure platform-specific code generation.
292293
- [`track_caller`] --- Pass the parent call location to `std::panic::Location::caller()`.
@@ -363,6 +364,7 @@ The following is an index of all built-in attributes.
363364
[`macro_export`]: macros-by-example.md#path-based-scope
364365
[`macro_use`]: macros-by-example.md#the-macro_use-attribute
365366
[`must_use`]: attributes/diagnostics.md#the-must_use-attribute
367+
[`naked`]: attributes/codegen.md#the-naked-attribute
366368
[`no_builtins`]: attributes/codegen.md#the-no_builtins-attribute
367369
[`no_implicit_prelude`]: names/preludes.md#the-no_implicit_prelude-attribute
368370
[`no_link`]: items/extern-crates.md#the-no_link-attribute

src/attributes/codegen.md

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,77 +52,49 @@ be called.
5252
r[attributes.codegen.naked]
5353
## The `naked` attribute
5454

55-
The *`naked` [attribute]* may be applied to a function in order to prevent the compiler
56-
from emitting a function prologue.
57-
58-
### Requirements
59-
60-
Any function marked with the `naked` attribute must meet the following requirements;
61-
failure to do so will result in a compiler error.
62-
63-
* The [function body] must consist of exactly one [`asm!`] macro invocation,
64-
which may be enclosed within an [unsafe block].
65-
* This `asm!` invocation must not contain any [operands]
66-
except for `const` and `sym` operands.
67-
* This `asm!` invocation must specify the `noreturn` [option],
68-
and must not specify any other options except for `att_syntax`.
69-
* The function must not be marked with the [`inline`] attribute.
70-
71-
### Recommendations
72-
73-
Any function marked with the `naked` attribute should adhere to the following recommendations;
74-
failure to do so will result in a compiler warning.
75-
76-
* The function should feature an [extern function qualifier] that is not `extern "Rust"`.
77-
* All arguments and return types of the function should be [FFI-safe].
78-
79-
### Effects
80-
81-
Marking a function with the `naked` attribute has the following effects:
82-
83-
* The compiler will not generate a prologue for this function.
84-
Within the function, all registers will remain precisely as they were set up
85-
by its caller.
86-
* The compiler will suppress the [`unused_variables`] lint for this function.
87-
88-
### Notes
89-
90-
* The [rules for inline assembly] ordinarily consider it undefined behavior to
91-
refer to registers not specified as input operands, or to modify
92-
registers not specified as output operands.
93-
The reason for this is because ordinarily an `asm!` invocation cannot guarantee
94-
the state of the registers surrounding the assembly block.
95-
However, in naked functions the state of the registers is guaranteed
96-
by adherence to the specified calling convention.
97-
Therefore, it is not undefined behavior for the `asm!` invocation in a naked function
98-
to refer to registers without specifying them as operands.
99-
* A naked function that makes use of registers in a way that does not conform
100-
to the specified calling convention imposes additional safety invariants on its caller,
101-
and therefore must be marked as an [unsafe function].
102-
* Implementations may assume that naked functions never unwind.
103-
Unwinding through a naked function is undefined behavior.
104-
* The semantics of naked functions require implementations to set up the call stack
105-
according to the specified calling convention before executing a naked function,
106-
even in contexts where setting up the call stack would ordinarily be unnecessary,
107-
such as when the function is inlined.
108-
An implementation can fulfill this requirement by guaranteeing that naked functions
109-
are never inlined.
110-
However, implementations are not currently required to guarantee that naked functions
111-
are never inlined.
112-
In the future it may become a requirement for implementations to guarantee that
113-
naked functions are never inlined;
114-
users must not rely on any observable behavior that may result from inlining.
115-
* Although implementations are prohibited from generating code for a naked function that
116-
contains any instructions that precede the naked function's `asm!` block,
117-
under some circumstances, implementations may generate code that contains instructions
118-
*after* a naked function's `asm!` block.
119-
In the future it may become a requirement for implementations to guarantee
120-
the absence of any instructions following a naked function's `asm!` block;
121-
users must not rely on the presence of any trailing instructions.
122-
If a user of the `naked` attribute relies on the absence of trailing instructions
123-
for correctness, for the time being it is the user's responsibility to ensure that
124-
the instructions truly are absent,
125-
for example by passing any necessary code generation flags to the compiler.
55+
r[attributes.codegen.naked]
56+
57+
r[attributes.codegen.naked.intro]
58+
The *`naked` [attribute]* prevents the compiler from emitting a function prologue and
59+
epilogue for the attributed function.
60+
61+
r[attributes.codegen.naked.body]
62+
The [function body] must consist of exactly one [`naked_asm!`] macro invocation, which
63+
may be enclosed within an [unsafe block].
64+
65+
r[attributes.codegen.naked.prologue-epilogue]
66+
No function prologue or epilogue are generated for the attributed function: the contents
67+
of the `naked_asm!` invocation make up the full body of a naked function.
68+
69+
r[attributes.codegen.naked.call-stack]
70+
The caller must set up the call stack acording to the specified calling convention before
71+
executing a naked function, even in contexts where setting up the call stack would ordinarily
72+
be unnecessary, such as when the function is inlined.
73+
74+
An implementation can fulfill this requirement by guaranteeing that naked functions
75+
are never inlined. However, implementations are not currently required to guarantee that
76+
naked functions are never inlined.
77+
78+
In the future it may become a requirement for implementations to guarantee that
79+
naked functions are never inlined; users must not rely on any observable behavior
80+
that may result from inlining. according to the specified calling convention before
81+
executing a naked function,
82+
83+
r[attributes.codegen.naked.unsafe-function]
84+
A naked function that makes use of registers in a way that does not conform
85+
to the specified calling convention imposes additional safety invariants on its caller,
86+
and therefore must be marked as an [unsafe function].
87+
88+
> ***Note***: a `naked_asm!` invocation may refer to registers that were not specified as operands.
89+
> for standard `asm!` this is undefined behavior, but `inline_asm!` may rely on the state of registers
90+
> as specified by the calling convention.
91+
92+
r[attributes.codegen.naked.unused-variables]
93+
The [`unused_variables`] lint is suppressed within naked functions.
94+
95+
r[attributes.codegen.naked.no-unwind]
96+
Implementations may assume that naked functions never unwind.
97+
Unwinding through a naked function is undefined behavior.
12698

12799
r[attributes.codegen.no_builtins]
128100
## The `no_builtins` attribute
@@ -539,6 +511,7 @@ trait object whose methods are attributed.
539511
[`is_aarch64_feature_detected`]: ../../std/arch/macro.is_aarch64_feature_detected.html
540512
[`naked_asm!`]: ../inline-assembly.md
541513
[`inline`]: #the-inline-attribute
514+
[`track_caller`]: #the-track-caller-attribute
542515
[`target_feature` conditional compilation option]: ../conditional-compilation.md#target_feature
543516
[`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables
544517
[attribute]: ../attributes.md

0 commit comments

Comments
 (0)