Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chorman0773
Copy link
Contributor

@chorman0773 chorman0773 commented Aug 26, 2024

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

…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.
Copy link
Member

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).

@traviscross traviscross added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants