Skip to content

x/arch/x86: objdump cannot decode AVX instructions #69792

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

Closed
mhr3 opened this issue Oct 5, 2024 · 5 comments
Closed

x/arch/x86: objdump cannot decode AVX instructions #69792

mhr3 opened this issue Oct 5, 2024 · 5 comments
Milestone

Comments

@mhr3
Copy link

mhr3 commented Oct 5, 2024

Go version

go version go1.23.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/mhr3/Library/Caches/go-build'
GOENV='/Users/mhr3/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/mhr3/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/mhr3/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/mhr3/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/tmp/go-bin/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/k6/z2zpftk571d89c88yzh8b65c0000gn/T/go-build1267667530=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Running go tool objdump on a go binary cannot decode functions containing AVX instructions, for example when running objdump on a simple go binary built from this source code:

package main

import (
	"strings"
)

func main() {
	_ = strings.Contains("foo", "oo")
}

What did you see happen?

Building a amd64 binary using the above source code and running go tool objdump -s indexbytebody ./main outputs disassembled version of internal/bytealg/indexbyte_amd64.s, which contains (snip):

TEXT _indexbytebody(SB) /opt/homebrew/Cellar/go/1.23.1/libexec/src/internal/bytealg/indexbyte_amd64.s
  indexbyte_amd64.s:32	0x1003400		66480f6ec0		MOVQ AX, X0
  indexbyte_amd64.s:33	0x1003405		660f60c0		PUNPCKLBW X0, X0
  indexbyte_amd64.s:34	0x1003409		660f60c0		PUNPCKLBW X0, X0
...
  indexbyte_amd64.s:122	0x10034b6		803dc646180001		CMPB internal/cpu.X86+67(SB), $0x1
  indexbyte_amd64.s:123	0x10034bd		0f8562ffffff		JNE 0x1003425
  indexbyte_amd64.s:125	0x10034c3		66480f6ec0		MOVQ AX, X0
  indexbyte_amd64.s:126	0x10034c8		4c8d5c1ee0		LEAQ -0x20(SI)(BX*1), R11
  indexbyte_amd64.s:127	0x10034cd		c4e27d78c8		JS 0x100349a
  indexbyte_amd64.s:127	0x10034d2		660f1f840000000000	NOPW 0(AX)(AX*1)
  indexbyte_amd64.s:127	0x10034db		0f1f440000		NOPL 0(AX)(AX*1)
  indexbyte_amd64.s:131	0x10034e0		c5fe6f17		VMOVDQU 0(DI), X2
  indexbyte_amd64.s:132	0x10034e4		c5ed74d9		JE 0x10034c1
  indexbyte_amd64.s:133	0x10034e8		c4			?
  indexbyte_amd64.s:133	0x10034e9		e27d			LOOP 0x1003568
  indexbyte_amd64.s:133	0x10034eb		17			?
  indexbyte_amd64.s:133	0x10034ec		db			?

even though the source code contains:

#ifndef hasAVX2
CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1
JNE sse
#endif
MOVD AX, X0
LEAQ -32(SI)(BX*1), R11
VPBROADCASTB X0, Y1
PCALIGN $32
avx2_loop:
VMOVDQU (DI), Y2
VPCMPEQB Y1, Y2, Y3
VPTEST Y3, Y3

What did you expect to see?

The disassembled code should match the source code

@gopherbot gopherbot added this to the Unreleased milestone Oct 5, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/618036 mentions this issue: x86: allow decoding of AVX instructions

@mhr3
Copy link
Author

mhr3 commented Oct 5, 2024

Output with the linked PR:

  indexbyte_amd64.s:122	0x10034b6		803dc646180001		CMPB internal/cpu.X86+67(SB), $0x1
  indexbyte_amd64.s:123	0x10034bd		0f8562ffffff		JNE 0x1003425
  indexbyte_amd64.s:125	0x10034c3		66480f6ec0		MOVQ AX, X0
  indexbyte_amd64.s:126	0x10034c8		4c8d5c1ee0		LEAQ -0x20(SI)(BX*1), R11
  indexbyte_amd64.s:127	0x10034cd		c4e27d78c8		VPBROADCASTB X0, Y1
  indexbyte_amd64.s:127	0x10034d2		660f1f840000000000	NOPW 0(AX)(AX*1)
  indexbyte_amd64.s:127	0x10034db		0f1f440000		NOPL 0(AX)(AX*1)
  indexbyte_amd64.s:131	0x10034e0		c5fe6f17		VMOVDQU 0(DI), Y2
  indexbyte_amd64.s:132	0x10034e4		c5ed74d9		VPCMPEQB Y1, Y2, Y3
  indexbyte_amd64.s:133	0x10034e8		c4e27d17db		VPTEST Y3, Y3

@cherrymui
Copy link
Member

Perhaps this is a duplicate of #47307 ?

@cherrymui
Copy link
Member

This is similar to #47307. Closing as a dup. Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants