Skip to content

cmd/asm: panic assembling VGATHERDPD instruction #43421

Open

Description

@mmcloughlin

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

$ go version
go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes, it's present in go1.16beta1 too.

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mbm/Library/Caches/go-build"
GOENV="/Users/mbm/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mbm/Development/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mbm/Development/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mbm/Development/avo/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cj/jl6w0c1j4sz5vs05h5l1cby40000gn/T/go-build260372576=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Assembling the following code:

TEXT ·test(SB), 0, $0
	VGATHERDPD	32(Y13*8), Z17
	RET

What did you expect to see?

Assembler should produce an error.

What did you see instead?

$ go tool asm panic.s
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1189ec2]

goroutine 1 [running]:
cmd/internal/obj/x86.(*AsmBuf).doasm(0xc0000bfb90, 0xc00009c820, 0xc0000ce100, 0xc0000935f0)
	/usr/local/Cellar/go/1.15.6/libexec/src/cmd/internal/obj/x86/asm6.go:4235 +0x74e2
cmd/internal/obj/x86.(*AsmBuf).asmins(0xc0000bfb90, 0xc00009c820, 0xc0000ce100, 0xc0000935f0)
	/usr/local/Cellar/go/1.15.6/libexec/src/cmd/internal/obj/x86/asm6.go:5382 +0x65
cmd/internal/obj/x86.span6(0xc00009c820, 0xc0000ce100, 0xc00008e540)
	/usr/local/Cellar/go/1.15.6/libexec/src/cmd/internal/obj/x86/asm6.go:2154 +0x545
cmd/internal/obj.Flushplist(0xc00009c820, 0xc0000bfe30, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.15.6/libexec/src/cmd/internal/obj/plist.go:107 +0x762
main.main()
	/usr/local/Cellar/go/1.15.6/libexec/src/cmd/asm/main.go:91 +0x74b

I'm guessing this is an unsafe use of p.GetFrom3():

if p.GetFrom3().Reg >= REG_K0 && p.GetFrom3().Reg <= REG_K7 {

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Dec 30, 2020
  2. added this to the Backlog milestone on Dec 30, 2020
  3. IBlackVoid commented on Nov 5, 2026

    @IBlackVoid
    Contributor

    This looks already fixed. On tip the instruction from the report produces a diagnostic instead of a crash:

    $ cat case.s
    TEXT ·test(SB), 0, $0
    	VGATHERDPD	32(Y13*8), Z17
    	RET
    
    $ go tool asm -o /dev/null case.s
    asm: need a third arg for gather instruction: 00000 (case.s:2)	VGATHERDPD	32(Y13*8), Z17
    asm: assembly failed
    

    The guard is the p.GetFrom3() == nil check the report guessed at. It went in with b958d4a ("cmd/asm: don't panic on bad GATHER x86 instructions") in March 2023, filed against #58822, which is probably why this issue never got closed.

    I also tried two operand forms of VPGATHERQQ, VGATHERQPD, VPGATHERDD, VGATHERDPS and VPGATHERQD, all of them clean, and the correct three operand form still assembles.

    Looks safe to close.

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

    NeedsFixThe path to resolution is known, but the work has not been done.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