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