golang/go

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

オープン

#66,189 opened on 2024/03/08

 (3 件のコメント) (0 件のリアクション) (0 人の担当者)Go (19,008 件のフォーク)batch import
NeedsInvestigationarch-arm64help wanted

Repository metrics

Stars
 (133,883 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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.

コントリビューターガイド