Skip to content

Commit ae298d8

Browse files
committed
Clarify rules around the use of symbols in asm code
1 parent 3633849 commit ae298d8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

text/0000-inline-asm.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,12 @@ unsafe fn foo(mut a: i32, b: i32) -> (i32, i32)
823823
- You cannot exit an `asm!` block that has not been entered. Neither can you exit an `asm!` block that has already been exited.
824824
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
825825
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
826+
- You cannot assume that an `asm!` block will appear exactly once in the output binary. The compiler is allowed to instantiate multiple copies of the `asm!` block, for example when the function containing it is inlined in multiple places.
827+
- As a consequence, you should only use [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions.
826828

827-
> **Note**: As a general rule, these are the flags which are *not* preserved when performing a function call.
829+
> **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call.
830+
831+
[local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
828832

829833
# Drawbacks
830834
[drawbacks]: #drawbacks

0 commit comments

Comments
 (0)