Skip to content

cmd/asm: amd64 MOVBQZX instructions referring to upper-byte registers are not rejected #50882

Closed

Description

@WojciechMula

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         

Activity

  1. changed the title [-]Go assembler accepts wrong amd64 code and emits[/-] [+]cmd/asm: amd64 MOVBQZX instructions referring to upper-byte registers are not rejected[/+] on Jan 28, 2022
  2. randall77 commented on Jan 28, 2022

    @randall77
    Contributor

    Related, but probably not identical: #14288

  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Jan 28, 2022
  4. added this to the Backlog milestone on Jan 28, 2022
  5. gopherbot commented on Oct 19, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/849950 mentions this issue: cmd/internal/obj/x86: reject high byte registers with REX prefix

  6. added a commit that references this issue on Oct 30, 2026
    b0d3d28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone 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.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions