Skip to content

Fix bad conversion from llvm_asm! to asm!#218

Merged
phil-opp merged 1 commit intorust-osdev:masterfrom
tomaka:fix-bochs-breakpoint
Dec 28, 2020
Merged

Fix bad conversion from llvm_asm! to asm!#218
phil-opp merged 1 commit intorust-osdev:masterfrom
tomaka:fix-bochs-breakpoint

Conversation

@tomaka
Copy link
Copy Markdown
Contributor

@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/github.com-1ecc6299db9ec823/x86_64-0.12.3/src/instructions/mod.rs:51:15
   |
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.

@tomaka
Copy link
Copy Markdown
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.

@phil-opp
Copy link
Copy Markdown
Member

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: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=74fb87fe9c686b6e4beffb1b1e1fd564

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants