-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/internal/obj/x86: assembler accepts memory operands for DR/CR MOVs #24981
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
Comments
CC @cherrymui This also affects CR moves (at least I believe so). |
CC @TocarIP, in case you're interested in this. |
Current state is erroneous with almost 100% confidence. |
I think we should fix it, rejecting the invalid cases. MOVL DR0, (AX) looks like a store, but the machine instruction it generates is not. MOVL DR0, 777(AX) is even worse. |
Change https://golang.org/cl/107075 mentions this issue: |
Uh oh!
There was an error while loading. Please reload this page.
Originated from CL107075.
Problem: MOV instructions for CR/DR registers accept memory operands in addition to registers.
Both AMD and Intel manuals don't specify memory args as valid.
This can lead to unexpected results for the programmer.
Solution: fix
Yml
operand class toYrl
. Not totally backwards-compatible.Details below.
MOV DebugReg
instructions describe non-DR argument as reg/mem (Yml) instead of just reg (Yrl):go/src/cmd/internal/obj/x86/asm6.go
Lines 3545 to 3560 in dd71e3f
Note that two entries have expected
Yrl
, they were added later:So, all lines below are assembled:
MOV_DR
is special because it'sModR/M.MOD
bits are all aliased to0b11
(reg).In theory, they should execute identically (source, see "COMMENT").
Also, quote from AMD manual for
MOV DR
:This makes it debatable whether we should forbid memory arguments or not, but it's almost certainly an error to use memory operand with displacement (SIB byte is error, too).
Here are external disassemblers output for code above:
XED accepts all MOD bits combinations, but not displacement immediate itself.
If we change
Yml
toYrl
, weird behavior can be mitigated, but this is not backwards-compatible.Not sure if anyone depends on this.
Maybe such code can be considered as broken anyway.
Everything above also applies to
CR
moves.The text was updated successfully, but these errors were encountered: