Repository navigation
Closed
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
What version of Go are you using (go version)?
$ go version go version go1.17.3 linux/amd64
Does this issue reproduce with the latest release?
Haven't checked
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/wojtek/.cache/go-build" GOENV="/home/wojtek/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/wojtek/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/wojtek/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go-1.17" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.17/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.3" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2132970980=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Consider this simple program
main.go
package main
// go:noescape
func asmfun()
func main() { asmfun() }
and the asm implementation --- asmfun_amd64.s
#include "textflag.h"
TEXT ·asmfun(SB), NOSPLIT, $0
// wrong code
MOVBQZX AH, AX
MOVBQZX BH, AX
MOVBQZX CH, AX
MOVBQZX DH, AX
RET
What did you expect to see?
I'd expect the assembler to reject invalid code, as referencing the upper-byte
registers is impossible.
What did you see instead?
$ go build
$ go tool objdump -s asmfun main
TEXT main.asmfun.abi0(SB) /home/wojtek/t/bug/asmfun_amd64.s
asmfun_amd64.s:5 0x455420 480fb6c4 MOVZX SP, AX
asmfun_amd64.s:6 0x455424 480fb6c7 MOVZX DI, AX
asmfun_amd64.s:7 0x455428 480fb6c5 MOVZX BP, AX
asmfun_amd64.s:8 0x45542c 480fb6c6 MOVZX SI, AX
asmfun_amd64.s:9 0x455430 c3 RET
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]Go assembler accepts wrong amd64 code and emits[/-][+]cmd/asm: amd64 MOVBQZX instructions referring to upper-byte registers are not rejected[/+]randall77 commentedon Jan 28, 2022
Related, but probably not identical: #14288
gopherbot commentedon Oct 19, 2026
Change https://go.dev/cl/849950 mentions this issue:
cmd/internal/obj/x86: reject high byte registers with REX prefixcmd/internal/obj/x86: reject high byte registers with REX prefix