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: amd64 MOVBQZX instructions referring to upper-byte registers are not rejected #50882

Open
WojciechMula opened this issue Jan 28, 2022 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@WojciechMula
Copy link

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         
@bcmills bcmills changed the title Go assembler accepts wrong amd64 code and emits cmd/asm: amd64 MOVBQZX instructions referring to upper-byte registers are not rejected Jan 28, 2022
@randall77
Copy link
Contributor

Related, but probably not identical: #14288

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 28, 2022
@mknyszek mknyszek added this to the Backlog milestone Jan 28, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants