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

cmd/asm: accepts MOVB (BX)(R8*4), AH incorrectly #14288

Open
randall77 opened this issue Feb 10, 2016 · 4 comments
Open

cmd/asm: accepts MOVB (BX)(R8*4), AH incorrectly #14288

randall77 opened this issue Feb 10, 2016 · 4 comments
Labels
NeedsFix
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Feb 10, 2016

MOVB (BX)(R8*4), AH
The assembler accepts this instruction but silently misassembles it to:
MOVB (BX)(R8*4), SP
This is because we need the RAX prefix for the indexed address, but then the RAX prefix also forces the use of standard register naming instead of the weird *H register naming.

gas rejects this instruction movb (%rbx,%r8,4),%ah with can't encode register '%ah' in an instruction requiring REX prefix.

@rsc

@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Feb 10, 2016
@bradfitz bradfitz changed the title bad assembly accepted, misassembled cmd/asm: bad assembly accepted, misassembled Feb 10, 2016
@rsc
Copy link
Contributor

@rsc rsc commented Feb 10, 2016

We'll catch this as part of the big asm fixup.

@rsc
Copy link
Contributor

@rsc rsc commented Feb 10, 2016

But expanding what I said yesterday just a bit: never use MOVB or MOVW with a register destination, since it's inefficient (it's a read-modify-write on the target register). Instead use MOVL for reg->reg and use MOVBLZX or MOVWLZX for mem->reg; those are pure writes on the target register.

@rsc
Copy link
Contributor

@rsc rsc commented Feb 10, 2016

Actually, on third glance I'm even more surprised you are trying to address AH (not AL). Why?

@randall77
Copy link
Contributor Author

@randall77 randall77 commented Feb 11, 2016

SSA never uses AH. I just ran into this while writing a test case.

@mdempsky mdempsky added this to the Go1.8 milestone May 19, 2016
@mdempsky mdempsky removed this from the Go1.7 milestone May 19, 2016
@quentinmit quentinmit added the NeedsFix label Oct 5, 2016
@rsc rsc added this to the Go1.9 milestone Oct 21, 2016
@rsc rsc removed this from the Go1.8 milestone Oct 21, 2016
@rsc rsc changed the title cmd/asm: bad assembly accepted, misassembled cmd/asm: accepts MOVB (BX)(R8*4), AH incorrectly Oct 21, 2016
@randall77 randall77 added this to the Go1.10 milestone Jun 26, 2017
@randall77 randall77 removed this from the Go1.9 milestone Jun 26, 2017
@rsc rsc removed this from the Go1.10 milestone Nov 22, 2017
@rsc rsc added this to the Go1.11 milestone Nov 22, 2017
@gopherbot gopherbot removed this from the Go1.11 milestone May 23, 2018
@gopherbot gopherbot added this to the Unplanned milestone May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

6 participants