Importing golang.org/x/arch/arm64/arm64asm in cmd/internal/obj/arm64 doesn't work

181 views
Skip to first unread message

Eric Fang

unread,
Oct 23, 2023, 4:13:23 AM10/23/23
to golang-dev
I try to import golang.org/x/arch/arm64/arm64asm in cmd/internal/obj/arm64 because I want to share some information in assembler and disassembler. But I found this doesn't work. It's weird that golang.org/x/arch/arm64/arm64asm is used in cmd/internal/objfile/disasm.go, and it works fine. I tried to see if there was any special handling for this, but I didn't find it. Can anyone point me to how I should do this? Or is this a bug?

$ go version
go version devel go1.22-3839447ac3 Sat Oct 21 03:03:54 2023 +0000 linux/arm64

$ git diff
diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go
index 0991ec9201..20fce4b844 100644
--- a/src/cmd/internal/obj/arm64/asm7.go
+++ b/src/cmd/internal/obj/arm64/asm7.go
@@ -38,8 +38,14 @@ import (
        "math"
        "sort"
        "strings"
+
+       "golang.org/x/arch/arm64/arm64asm"

 )

+func aConstant() int {
+       return int(arm64asm.ABS)
+}
+

 // ctxt7 holds state while assembling a single function.
 // Each function gets a fresh ctxt7.
 // This allows for multiple functions to be safely concurrently assembled.

$ ./make.bash
Building Go cmd/dist using /home/erifan01/go-in-use. (go1.20.6 linux/arm64)
Building Go toolchain1 using /home/erifan01/go-in-use.
../../../../src/cmd/internal/obj/arm64/asm7.go:42: no required module provides package golang.org/x/arch/arm64/arm64asm; to add it:
        go get golang.org/x/arch/arm64/arm64asm
go tool dist: FAILED: /home/erifan01/go-in-use/bin/go install -tags=math_big_pure_go compiler_bootstrap purego bootstrap/cmd/...: exit status 1

$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/erifan01/.cache/go-build'
GOENV='/home/erifan01/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/erifan01/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/erifan01/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/erifan01/go-master'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/erifan01/go-master/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='devel go1.22-3839447ac3 Sat Oct 21 03:03:54 2023 +0000'
GCCGO='/usr/bin/gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/erifan01/go-master/src/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3732264150=/tmp/go-build -gno-record-gcc-switches'

Benny Siegert

unread,
Oct 23, 2023, 7:45:19 AM10/23/23
to Eric Fang, golang-dev


> Am 23.10.2023 um 10:13 schrieb Eric Fang <eric...@arm.com>:
>
> I try to import golang.org/x/arch/arm64/arm64asm in cmd/internal/obj/arm64 because I want to share some information in assembler and disassembler. But I found this doesn't work. It's weird that golang.org/x/arch/arm64/arm64asm is used in cmd/internal/objfile/disasm.go, and it works fine. I tried to see if there was any special handling for this, but I didn't find it. Can anyone point me to how I should do this? Or is this a bug?


It’s not a bug but the context in which the code is built. You notice that your code is built as part of toolchain1, using go_bootstrap. ISTR that there is a table somewhere about which code depends on which module, but I couldn’t find it.

Try starting from the cmd/dist sources to trace what it’s doing.


Benny

cherry

unread,
Oct 23, 2023, 12:12:31 PM10/23/23
to Benny Siegert, Eric Fang, golang-dev
Here is the table https://cs.opensource.google/go/go/+/master:src/cmd/dist/buildtool.go;l=22-91 . Packages needed for building the bootstrap toolchain ("toolchain1", which includes the compiler, linker, assembler, and the cgo command) need to be explicitly listed in cmd/dist.

That said, I think we probably don't want to directly import golang.org/x/arch/arm64/arm64asm in the assembler. It is probably better to do some code generation, instead of direct import. Thanks.

Cherry 


Try starting from the cmd/dist sources to trace what it’s doing.


Benny

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/20104CE7-C581-40AD-81FF-69DF708C3F43%40gmail.com.

Eric Fang

unread,
Oct 23, 2023, 9:21:42 PM10/23/23
to golang-dev
This will lead to duplication of code. The code generated by the xml parser has a copy in x/arch, and this copy will be imported into the Go repo through cmd/vendor. If we also put a copy in cmd/internal/obj/arm64, isn't this a duplication?

Eric Fang

unread,
Oct 23, 2023, 9:59:36 PM10/23/23
to golang-dev
Thanks @Benny @Cherry

cherry

unread,
Oct 24, 2023, 12:11:46 PM10/24/23
to Eric Fang, golang-dev
On Mon, Oct 23, 2023 at 9:21 PM Eric Fang <eric...@arm.com> wrote:
This will lead to duplication of code. The code generated by the xml parser has a copy in x/arch, and this copy will be imported into the Go repo through cmd/vendor. If we also put a copy in cmd/internal/obj/arm64, isn't this a duplication?

The XML parser will be in the x/arch repo, but the code generated by it doesn't need to be in the x/arch repo. It can live in the main repo directly.

Let's focus on the assembler first, not worrying about the disassembler for now. If later it turns out that generated code is also suitable for the disassembler, we can arrange tools like cmd/objdump import cmd/internal/obj/arm64 instead of x/arch. The current x/arch/arm64/arm64asm package contains things that the assembler and compiler don't need. Also, "A little copying is better than a little dependency."

Let's continue the discussion on the CL stack. Thanks.
 

在2023年10月24日星期二 UTC+8 00:12:31<cherry> 写道:
On Mon, Oct 23, 2023 at 7:45 AM Benny Siegert <bsie...@gmail.com> wrote:


> Am 23.10.2023 um 10:13 schrieb Eric Fang <eric...@arm.com>:
>
> I try to import golang.org/x/arch/arm64/arm64asm in cmd/internal/obj/arm64 because I want to share some information in assembler and disassembler. But I found this doesn't work. It's weird that golang.org/x/arch/arm64/arm64asm is used in cmd/internal/objfile/disasm.go, and it works fine. I tried to see if there was any special handling for this, but I didn't find it. Can anyone point me to how I should do this? Or is this a bug?


It’s not a bug but the context in which the code is built. You notice that your code is built as part of toolchain1, using go_bootstrap. ISTR that there is a table somewhere about which code depends on which module, but I couldn’t find it.

Here is the table https://cs.opensource.google/go/go/+/master:src/cmd/dist/buildtool.go;l=22-91 . Packages needed for building the bootstrap toolchain ("toolchain1", which includes the compiler, linker, assembler, and the cgo command) need to be explicitly listed in cmd/dist.

That said, I think we probably don't want to directly import golang.org/x/arch/arm64/arm64asm in the assembler. It is probably better to do some code generation, instead of direct import. Thanks.

Cherry 


Try starting from the cmd/dist sources to trace what it’s doing.


Benny

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/20104CE7-C581-40AD-81FF-69DF708C3F43%40gmail.com.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages