From fdb6bdacfab4d6f52124fa0e81ac3c7db84d35f7 Mon Sep 17 00:00:00 2001 From: Smittyvb Date: Wed, 3 Nov 2021 09:24:50 -0400 Subject: [PATCH 1/2] Add note about x86 instruction prefixes in asm! Since rustc doesn't do the assembly parsing itself, it is unable to detect when inline assembly ends with an instruction prefix, which doesn't make sense since it would apply to instructions from the compiler. This fixes #82314 by mentioning that x86 instruction prefixes must not be used in inline assembly. --- src/doc/unstable-book/src/library-features/asm.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index 6bf21e8f58b..6e416462610 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -885,5 +885,7 @@ The compiler performs some additional checks on options: - You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds). - The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited. - 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. +- On x86, inline assembly must not end with an instruction prefix (such as `LOCK`) that would apply to instructions generated by the compiler. + - The compiler is currently unable to detect this due to the way inline assembly is compiled. > **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call. From 773cc4f52b7f6bfa5b9ad0878583fb0ac9e9f2ea Mon Sep 17 00:00:00 2001 From: Smittyvb Date: Thu, 4 Nov 2021 11:31:03 -0400 Subject: [PATCH 2/2] Mention possible future rejections Co-authored-by: Josh Triplett --- src/doc/unstable-book/src/library-features/asm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index 6e416462610..84fc6dcc339 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -886,6 +886,6 @@ The compiler performs some additional checks on options: - The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited. - 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. - On x86, inline assembly must not end with an instruction prefix (such as `LOCK`) that would apply to instructions generated by the compiler. - - The compiler is currently unable to detect this due to the way inline assembly is compiled. + - The compiler is currently unable to detect this due to the way inline assembly is compiled, but may catch and reject this in the future. > **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call.