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

Fix bad conversion from llvm_asm! to asm! #218

merged 1 commit into from Dec 28, 2020


Copy link

@tomaka tomaka commented Dec 28, 2020

When updating x86_64 from 0.11.x to 0.12.x, I've gotten the following compilation error:

error: invalid instruction mnemonic 'xchgw'
  --> /home/pierre/.cargo/registry/src/
51 |         asm!("xchgw bx, bx", options(nomem, nostack));
   |               ^
note: instantiated into assembly here
  --> <inline asm>:2:2
2  |     xchgw bx, bx
   |     ^^^^^

According to this Bochs-related page, the instruction is indeed just xchg, while xchgw is the weird AT&T syntax equivalent.

My code compiles with this change, but I haven't tested if the Bochs breakpoint actually works.

Copy link
Contributor Author

tomaka commented Dec 28, 2020

Note that just running cargo build on the source code of x86_64 doesn't seem to actually verify the assembly. You can try this by writing asm!("xchgfoobarbaz bx, bx") and it will still compile.
I don't know exactly how it works, but it's likely that it's only the linker that checks the correctness of the assembly.

Copy link

Thanks a lot for reporting this! I wasn't aware that asm! is only checked when it's used, but it seems like you're right:

I opened a Rust issue about this at rust-lang/rust#80440 to see if this is a bug or the intended behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants