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
NeedsInvestigation
Milestone

Comments

@WojciechMula
Copy link

@WojciechMula WojciechMula commented Jan 28, 2022

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

@randall77 randall77 commented Jan 28, 2022

Related, but probably not identical: #14288

@mknyszek mknyszek added the NeedsInvestigation label Jan 28, 2022
@mknyszek mknyszek added this to the Backlog milestone Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants