-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify requires of Prefix/Directive validity requirements #1588
base: master
Are you sure you want to change the base?
Conversation
…ons are required to be obeyed even if the assembly block is never executed.
If inline assembly includes any "stateful" directive that modifies how subsequent assembly is processed, the block must undo the effects of any such directives before the inline assembly ends. If this constraint is violated, an error may be issued if it can be detected, but otherwise the result of executing the program that contains it is undefined - regardless of whether or not the inline assembly block that contains is eventually evaluated by that execution. | ||
|
||
r[asm.validity.prefix-restriction] | ||
Inline assembly must not end with an instruction prefix (such as `LOCK`) that would apply to instructions generated by the compiler. If this constraint is violated, an error may be issued if it can be detected, but otherwise the result of executing the program that contains it is undefined - regardless of whether or not the inline assembly block that contains is eventually evaluated by that execution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would generalize this even more: at the end of the asm block, the CPU must be in a state where it is ready to start a new instruction. Alternatively, the asm block must end at an instruction boundary. This covers cases where you use .byte
to only emit a part of an instruction, or leaving the assembler at an unaligned address for architectures that require aligned instructions (e.g. aarch64).
☔ The latest upstream changes (possibly f80986b) made this pull request unmergeable. Please resolve the merge conflicts. |
@chorman0773 Just checking in, is this something you want to continue working on? |
Yes, I just haven't had much time to work on it. |
This alters the text of the inline-assembly chapter to clarify that ending an inline-assembly block with a prefix or using a "stateful" assembly directive without reverting it results in undefined results whenever the program is executed at all - even if it doesn't eventually evaluate (let alone return from) the assembly block. It also notes that the compiler may (though does not currently) diagnose improper uses of stateful assembly directives that would violate that point.
This also removes the specific application of the prefix to x86 - I do not know whether this applies to any existing supported architectures, but it future proofs adding new such architectures.
Editorially, it also moves the aforementioned rules into the
[asm.validity]
section, and renames the identifiers accordingly.CC: @Amanieu