-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/internal/obj/x86: FSAVE assembled as FNSAVE #23386
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
If this issue is never fixed, here is advice for programmers from the future: And if FWAIT is not implemented at the moment you read this, try:
|
I wonder if it would be worth fuzzing the assembler with valid but odd instructions to find any other mismatches. |
I may be wrong (not fuzzing expert), but maybe validation against external assemblers/disassemblers is more appropriate? I did some of it using XED for AVX2 and above (including AVX512 with most of it's extensions), so only legacy instructions need heavy testing. Updated x86.csv can be useful as a foundation for tests code generation (it was used for existing amd64enc.s suite and disassembler "map"). In theory, when x86.csv is updated, we need to re-generate disassembler from it and check the assembler by tests based on it (this part is mostly done, but there is a room for improvements). But anyway, I think fuzzing can still find places where x86 asm crashes.. (By the way, there are still open issues from previous fuzz attack.) |
More complete list of instructions that assembled in incorrect way:
Since current uses of all instructions from the left imply FWAIT (WAIT), but in reality they assembled into forms without WAIT, it could be acceptable to forbid "pseudo" WAIT+op forms and add instructions without WAIT, so programmer can use both forms. This way, invalid code will not be assembled anymore. Probably can be fixed automatically with go fix. The other way is to change FSAVE to proper encoding, but that will change code behavior silently. We're also missing operand size override for FSTENVS (%rax)
FSTENV (%rax)
FSTENVL (%rax)
=>
0: 66 d9 30 fnstenvs (%rax)
3: d9 30 fnstenv (%rax)
5: d9 30 fnstenv (%rax) My proposed solution is described above, but I can't make the final decision here. |
CC @TocarIP (not urgent, adding to copy just in case) |
CC @cherrymui |
@TocarIP What do you think of the suggestion above? (Personally I'm not worried about backward compatibility for these instructions, and I think it would be OK to just fix them. But I also don't know much about this.) |
I'm Ok with fixing FSAVE. Quick search shows that it isn't encountered at all in github data-set (https://cloud.google.com/bigquery/public-data/), so breakage would be minimal. |
Change https://golang.org/cl/153217 mentions this issue: |
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/quasilyte/CODE/intel/avxgen"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build350631872=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
go tool asm fsave.s
:go tool objdump fsave.o
What did you expect to see?
FSAVE instruction is assembled into FSAVE.
Result encoding is "9bdd30".
What did you see instead?
FSAVE instruction is assembled into FNSAVE.
Result encoding is "dd30".
Additional notes
I can send a CL that fixes this.
The only trouble is backwards-compatibility: if FSAVE becomes FNSAVE, what to do with existing code?
Note that FSAVE is really a combination of FWAIT and FNSAVE.
The text was updated successfully, but these errors were encountered: