asm icon indicating copy to clipboard operation
asm copied to clipboard

the repo will cause compile error when using go vendor mode

Open Boyce-Lee opened this issue 2 years ago • 14 comments

Boyce-Lee avatar Mar 18 '22 03:03 Boyce-Lee

err msg: undefined reference to `github.com/segmentio/asm/cpu.X86'; I guess that go vendor mode changes the file path of the repo, which make the asm code "BTL $0x08, github·com∕segmentio∕asm∕cpu·X86+0(SB)" error

Boyce-Lee avatar Mar 18 '22 03:03 Boyce-Lee

Hey @Boyce-Lee, thanks for reporting.

We've seen this error as well when using older versions of Go; do you mind sharing details about your go version and environment? (maybe the output of go version and go env).

achille-roussel avatar Mar 18 '22 03:03 achille-roussel

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/tmp/.config-c8q0snp3nk6uslgt0ku0/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOOS="linux"
GOPATH="/compile_path"
GOPROXY="https://goproxy.byted.org"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build569257926=/tmp/go-build -gno-record-gcc-switches"

Boyce-Lee avatar Mar 18 '22 04:03 Boyce-Lee

go 1.3/1.4/1.5 do not work

my test version: go version go1.15.13 linux/amd64

Boyce-Lee avatar Mar 18 '22 04:03 Boyce-Lee

@Boyce-Lee Go 1.15.13 is an old release, are there any limitation to use newer Go 1.17 or even 1.18 release?

cristaloleg avatar Mar 18 '22 08:03 cristaloleg

FWIW, I see the same with Go 1.18.1

tuftedocelot avatar Apr 30 '22 12:04 tuftedocelot

I just tried this and did not observe any issues:

package main

import "github.com/segmentio/asm/mem"

func main() {
	src := [1]byte{42}
	dst := [1]byte{}
	mem.Copy(dst[:], src[:])
}
$ go mod init test-asm
go: creating new go.mod: module test-asm
go: to add module requirements and sums:
	go mod tidy
$ go mod tidy
go: finding module for package github.com/segmentio/asm/mem
go: found github.com/segmentio/asm/mem in github.com/segmentio/asm v1.2.0
$ go mod vendor
$ cat vendor/modules.txt
# github.com/segmentio/asm v1.2.0
## explicit; go 1.18
github.com/segmentio/asm/cpu
github.com/segmentio/asm/cpu/arm
github.com/segmentio/asm/cpu/arm64
github.com/segmentio/asm/cpu/cpuid
github.com/segmentio/asm/cpu/x86
github.com/segmentio/asm/mem
# golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
## explicit; go 1.17
golang.org/x/sys/cpu

Do you happen to have a reproducible test case that demonstrates the problem on Go 1.18?

achille-roussel avatar May 01 '22 17:05 achille-roussel

Regarding the original issue, the latest version of the project now requires Go 1.17+, there were changes to the build tool that add maintenance overhead to maintain backward compatibility with older Go versions. Version 1.1.5 is the last one supporting Go 1.16, older versions of Go were never supported.

achille-roussel avatar May 01 '22 17:05 achille-roussel

fwiw this causes a build failure on OpenBSD/amd64 using go 1.18.1 when building grafana 8.5 and a vendored source tree (which includes segmentio/asm 1.1.0 & 1.1.1 afaict).

/usr/local/go/pkg/tool/openbsd_amd64/link: running cc failed: exit status 1
ld: error: undefined symbol: github.com/segmentio/asm/cpu.X86
>>> referenced by valid_amd64.s:16 (/usr/obj/ports/grafana-8.5.2/go/src/github.com/grafana/grafana/vendor/github.com/segmentio/asm/ascii/valid_amd64.s:16)
>>>               /usr/obj/ports/grafana-8.5.2/build-amd64/go-link-2094309761/go.o:(github.com/grafana/grafana/vendor/github.com/segmentio/asm/ascii.ValidString.abi0)
>>> referenced by valid_print_amd64.s:15 (/usr/obj/ports/grafana-8.5.2/go/src/github.com/grafana/grafana/vendor/github.com/segmentio/asm/ascii/valid_print_amd64.s:15)
>>>               /usr/obj/ports/grafana-8.5.2/build-amd64/go-link-2094309761/go.o:(github.com/grafana/grafana/vendor/github.com/segmentio/asm/ascii.ValidPrintString.abi0)

landryb avatar May 05 '22 10:05 landryb

This looks like a linker issue, likely the build pipeline behaves slightly differently on OpenBSD and it looks like the symbols from the asm/cpu package are stripped out (maybe they don't have any references in the Go code), which breaks when they are linked from the assembly files.

I tried on a linux/amd64 and did not observe this behavior:

$ go version
go version go1.18.1 linux/amd64
$ cat go.mod
module test-asm

go 1.18

require github.com/segmentio/asm v1.1.1

require golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect

The test program I shared above vendors and builds fine.

I also tried building Grafana on the same platform and it succeeded (running make from the repo, go vendor worked as well).

achille-roussel avatar May 05 '22 16:05 achille-roussel

i got same error github.com/segmentio/asm/ascii.ValidString: relocation target github.com/segmentio/asm/cpu.X86 not defined github.com/segmentio/asm/ascii.ValidPrintString: relocation target github.com/segmentio/asm/cpu.X86 not defined

how to fix ?

hhyvs111 avatar Jul 22 '22 13:07 hhyvs111

i got same error too

github.com/segmentio/asm/bswap.swap64: relocation target github.com/segmentio/asm/cpu.X86 not defined

go version

go version go1.19.2 linux/amd64

go env

GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/builds/aquarius/assetsmgr/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/builds/aquarius/assetsmgr/.go"
GOPRIVATE=""
GOPROXY="[https://proxy.golang.org,direct](https://proxy.golang.org%2Cdirect/)"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2728460220=/tmp/go-build -gno-record-gcc-switches"

hjweddie avatar Nov 02 '22 06:11 hjweddie

i got same error too

github.com/segmentio/asm/bswap.swap64: relocation target github.com/segmentio/asm/cpu.X86 not defined

go version

go version go1.19.2 linux/amd64

go env

GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/builds/aquarius/assetsmgr/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/builds/aquarius/assetsmgr/.go"
GOPRIVATE=""
GOPROXY="[https://proxy.golang.org,direct](https://proxy.golang.org%2Cdirect/)"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2728460220=/tmp/go-build -gno-record-gcc-switches"

if I enable go mod, problem fixed.

hjweddie avatar Nov 02 '22 07:11 hjweddie

https://github.com/segmentio/asm

go build -tags purego ...

This is mainly useful to compare the impact of using the assembly optimized versions instead of the simpler Go-only implementations.

582033 avatar Nov 02 '22 13:11 582033