You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/attributes/codegen.md
+9-16
Original file line number
Diff line number
Diff line change
@@ -50,28 +50,22 @@ r[attributes.codegen.naked]
50
50
## The `naked` attribute
51
51
52
52
r[attributes.codegen.naked.intro]
53
-
The *`naked`[attribute]* prevents the compiler from emitting a function prologue and
54
-
epilogue for the attributed function.
53
+
The *`naked`[attribute]* prevents the compiler from emitting a function prologue and epilogue for the attributed function.
55
54
56
55
r[attributes.codegen.naked.body]
57
-
The [function body] must consist of exactly one [`naked_asm!`] macro invocation, which
58
-
may be enclosed within an [unsafe block].
56
+
The [function body] must consist of exactly one [`naked_asm!`] macro invocation.
59
57
60
58
r[attributes.codegen.naked.prologue-epilogue]
61
-
No function prologue or epilogue are generated for the attributed function: the contents
62
-
of the `naked_asm!` invocation make up the full body of a naked function.
59
+
No function prologue or epilogue are generated for the attributed function: the contents of the `naked_asm!` invocation make up the full body of a naked function.
60
+
61
+
r[attributes.codegen.naked.unsafe-attribute]
62
+
The `naked` attribute is an [unsafe attribute]. Annotating a function with `#[unsafe(naked)]` comes with the safety obligation that the body respects the function's calling convention, and that the body either returns or diverges.
63
63
64
64
r[attributes.codegen.naked.call-stack]
65
-
The asm code will have a valid call stack and register state on entry as per the signature and calling convention of the function.
65
+
The assembly code will have a valid call stack and register state on entry as per the signature and calling convention of the function.
66
66
67
67
r[attributes.codegen.naked.no-duplication]
68
-
The asm code may not be duplicated by the compiler, except when monomorphizing polymorphic functions.
69
-
This property is important for naked functions that define symbols in the assembly code.
70
-
71
-
r[attributes.codegen.naked.unsafe-function]
72
-
A naked function that makes use of registers in a way that does not conform
73
-
to the specified calling convention imposes additional safety invariants on its caller,
74
-
and therefore must be marked as an [unsafe function].
68
+
The assembly code may not be duplicated by the compiler, except when monomorphizing polymorphic functions. This property is important for naked functions that define symbols in the assembly code.
75
69
76
70
r[attributes.codegen.naked.unused-variables]
77
71
The [`unused_variables`] lint is suppressed within naked functions.
@@ -552,8 +546,7 @@ trait object whose methods are attributed.
Copy file name to clipboardExpand all lines: src/inline-assembly.md
+31-25
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ r[asm]
2
2
# Inline assembly
3
3
4
4
r[asm.intro]
5
-
Support for inline assembly is provided via the [`asm!`], [`naked_asm!`] and [`global_asm!`] macros.
5
+
Support for inline assembly is provided via the [`asm!`], [`naked_asm!`], and [`global_asm!`] macros.
6
6
It can be used to embed handwritten assembly in the assembly output generated by the compiler.
7
7
8
8
[`asm!`]: core::arch::asm
@@ -84,6 +84,15 @@ r[asm.scope.naked_asm]
84
84
With the `naked_asm!` macro, the assembly code is emitted in a function scope and constitutes the full assembly code of a function.
85
85
The `naked_asm!` macro is only allowed in [naked functions](attributes/codegen.md#the-naked-attribute).
86
86
87
+
```rust
88
+
# #[cfg(target_arch ="x86_64")] {
89
+
# #[unsafe(naked)]
90
+
# extern"C"fnwrapper() {
91
+
core::arch::naked_asm!("/* {} */", const0);
92
+
# }
93
+
# }
94
+
```
95
+
87
96
r[asm.scope.global_asm]
88
97
With the `global_asm!` macro, the assembly code is emitted in a global scope, outside a function.
89
98
This can be used to hand-write entire functions using assembly code, and generally provides much more freedom to use arbitrary registers and assembler directives.
@@ -391,7 +400,7 @@ assert_eq!(y, 1);
391
400
```
392
401
393
402
r[asm.operand-type.naked_asm-restriction]
394
-
Because `naked_asm!` defines a whole function body, it can only use `sym` and `const` operands.
403
+
Because `naked_asm!` defines a whole function body and the compiler cannot emit any additional code to handle operands, it can only use `sym` and `const` operands.
395
404
396
405
r[asm.operand-type.global_asm-restriction]
397
406
Because `global_asm!` exists outside a function, it can only use `sym` and `const` operands.
0 commit comments