Skip to content

cmd/internal/obj: rewriting MOVQ to XOR causes bugs and confusion #20986

@hdevalence

Description

@hdevalence

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.3 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/hdevalence/go"
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-build126311645=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I put MOVQ $0, AX in a Go assembly file.

What did you expect to see?

A move instruction, such as

48 b8 00 00 00 00 00 	movabs rax,0x0
00 00 00

or any other equivalent instruction.

What did you see instead?

An XOR, which clobbers the carry flags, breaking the program.

31 c0                	xor    eax,eax

This is essentially a duplicate of #12405, which is now locked. That issue notes that MOV is now "marked as clobbering flags" (presumably in the compiler internals?) but this fact seems not to be documented in either the Go assembly documentation or in the Plan 9 assembler documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions