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

x/arch: asm64.Decode() can not decode CASAL instruction #66189

Open
sancppp opened this issue Mar 8, 2024 · 2 comments
Open

x/arch: asm64.Decode() can not decode CASAL instruction #66189

sancppp opened this issue Mar 8, 2024 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@sancppp
Copy link

sancppp commented Mar 8, 2024

Go version

go version go1.21.3 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/tzx/.cache/go-build'
GOENV='/home/tzx/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/tzx/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/tzx/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3822673542=/tmp/go-build -gno-record-gcc-switches'

What did you do?

a demo:

package main

import (
	"sync/atomic"
)

func main() {
	a := atomic.Int32{}
	a.Store(1)
	a.CompareAndSwap(1, 4)
}

Try to use the arm64asm.Decode method to parse the elf file, the code is as follows:

package main

import (
	"debug/elf"
	"fmt"
	"log"

	"golang.org/x/arch/arm64/arm64asm"
)

func main() {
	file, err := elf.Open("/home/tzx/test/casal/main")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	for _, section := range file.Sections {
		if section.Flags&elf.SHF_EXECINSTR != 0 {
			data, err := section.Data()
			if err != nil {
				log.Fatal(err)
			}
			for pc := section.Addr; pc < section.Addr+section.Size; {
				instr, err := arm64asm.Decode(data[pc-section.Addr:])
				if err != nil {
					fmt.Printf("%#x: error data: ", pc)
					for i := len(data[pc-section.Addr:pc-section.Addr+4]) - 1; i >= 0; i-- {
						fmt.Printf("%02x", data[pc-section.Addr+uint64(i)])
					}
					fmt.Printf("\n")
				} else {
					fmt.Printf("%#x: %s\n", pc, instr)
				}
				pc += 4
			}
		}
	}
}

Use the objdump tool to output its assembly instructions, and the results are output to objdump.txt (left side of the picture)
Use arm64asm.Decode() to parse the elf compiled by the above demo, and the results are output to decode.txt (right side of the picture)

bn3h75

What did you see happen?

asm64.Decode() can not decode CASAL instruction.

The possible reason is that there is no description of the CASAL instruction in table.go

What did you expect to see?

In this demo, the output of objdump and arm64asm.Decode should be the same.

@mknyszek mknyszek added this to the Backlog milestone Mar 8, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Mar 8, 2024

CC @golang/compiler

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 8, 2024
@sancppp
Copy link
Author

sancppp commented Mar 24, 2024

@mknyszek Hello, Is this issue still being processed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants