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: misassembles MOVD #65193

Closed
clausecker opened this issue Jan 21, 2024 · 3 comments
Closed

cmd/asm: misassembles MOVD #65193

clausecker opened this issue Jan 21, 2024 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@clausecker
Copy link

Go version

go version go1.20.12 freebsd/amd64

Output of go env in your module/workspace:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/home/fuz/.cache/go-build"
GOENV="/usr/home/fuz/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOINSECURE=""
GOMODCACHE="/usr/home/fuz/src/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="freebsd"
GOPATH="/usr/home/fuz/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go120"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go120/pkg/tool/freebsd_amd64"
GOVCS=""
GOVERSION="go1.20.12"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="cc"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-I$HOME/include -I/usr/local/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-L$HOME/lib -L/usr/local/lib"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3711417635=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have tried to assemble an amd64 assembly file that contains an instruction like

MOVD (AX), X0

This instruction is found in clausecker/pospop. As specified by Intel, it is supposed to perform a 32 bit load from (SI) into X0.

What did you see happen?

I observe that the instruction was assembled to the instruction

a.s:10		0x331			f30f7e00		MOVQ 0(AX), X0                       // movq (%rax),%xmm0	

which performs a 64 bit load from memory. When (AX) is right before an unmapped page, this causes a crash.

What did you expect to see?

I expect the MOVD mnemonic to assembly into a 32 bit move instruction, not a 64 bit one.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 21, 2024
@randall77
Copy link
Contributor

MOVD is a 64-bit float load. MOVL is the 32-bit int load.
(The Go assembler syntax is different in this respect than one you might be used to, like at&t.)

@clausecker
Copy link
Author

That sounds reasonable. Still, one heck of a confusion. Perhaps this could be documented better. A lot of the SIMD stuff has Intel-like mnemonics as opposed to the Plan 9-like mnemonics one would expect, so it's kind of a tossup which one you need to use and what behaviour you get.

@randall77
Copy link
Contributor

Yeah I agree it is kind of a mishmash. I think at some point we decided there were too many intel instructions to make a new plan9 syntax version of each one.

We could add more documentation to https://go.dev/doc/asm if that would help. CLs appreciated.

I'm going to close this issue, as it isn't a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants