golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.81k stars 17.64k forks source link

cmd/internal/obj/arm64: when the immediate is MOVCON/BITCON type, assembler handles "cmp/cmn $immediate, RSP" instruction incorrectly. #25557

Closed zhangfannie closed 6 years ago

zhangfannie commented 6 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +87a18c6 Tue May 22 02:58:04 2018 +0000 linux/arm64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="arm64" GOBIN="" GOCACHE="/home/fanzha02/.cache/go-build" GOEXE="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/fanzha02/go" GORACE="" GOROOT="/mnt/share/homes/fanzha02/RefineAsm/golang" GOTMPDIR="" GOTOOLDIR="/mnt/share/homes/fanzha02/RefineAsm/golang/pkg/tool/linux_arm64" GCCGO="gccgo" CC="gcc" 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" GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build672309942=/tmp/go-build -gno-record-gcc-switches"

What did you do?

check assembler assembly instruction "CMPW $0x22220000, RSP", the instruction is encoded as two binary 5b44a4d2 ff031b6b. binary 5b44a4d2 is decoded as MOVD $0x2222000, R27, binary ff031b6b is decoded as CMPW R27, ZR.

If possible, provide a recipe for reproducing the error. A complete runnable program is good. A link on play.golang.org is best.

What did you expect to see?

CMPW $0x2222000, RSP is assembled as MOVD $0x22220000, R27, CMPW R27, RSP(CMP (extended register))

What did you see instead?

CMPW $0x2222000, RSP is assembled as MOVD $0x22220000, R27, CMPW R27, ZR(CMP (shifted register))

andybons commented 6 years ago

@randall77

benshi001 commented 6 years ago

There is one more error with optab 62,

  1. "AND $0x22220000, R2, RSP" is encoded to 5b44a4d25f601b00, which should be a report of "illegal combination".

first, 5f601b00 is not a legal aarch64 instruction

second, "AND Reg, Reg, Reg" does not accept RSP as source or destination.

According to arm64's architecture reference manual, using RSP as destination in AND is only legal in "AND C_BITCON, Reg, RSP".

The attempt to emulate "AND C_MOVCON, Reg, RSP" by combination of "MOV C_MOVCON, Rtmp" "AND Rtmp, RSP, RSP" is illegal

gopherbot commented 6 years ago

Change https://golang.org/cl/114796 mentions this issue: cmd/internal/arm64: fix two issues in the assembler