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

the repo will cause compile error when using go vendor mode #73

Open
Boyce-Lee opened this issue Mar 18, 2022 · 14 comments
Open

the repo will cause compile error when using go vendor mode #73

Boyce-Lee opened this issue Mar 18, 2022 · 14 comments

Comments

@Boyce-Lee
Copy link

No description provided.

@Boyce-Lee
Copy link
Author

Boyce-Lee commented Mar 18, 2022

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

@achille-roussel
Copy link
Contributor

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).

@Boyce-Lee
Copy link
Author

Boyce-Lee commented Mar 18, 2022

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
Copy link
Author

go 1.3/1.4/1.5 do not work

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

@cristaloleg
Copy link

@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?

@tuftedocelot
Copy link

FWIW, I see the same with Go 1.18.1

@achille-roussel
Copy link
Contributor

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
Copy link
Contributor

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.

@landryb
Copy link

landryb commented May 5, 2022

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)

@achille-roussel
Copy link
Contributor

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).

@hhyvs111
Copy link

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 ?

@hjweddie
Copy link

hjweddie commented Nov 2, 2022

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
Copy link

hjweddie commented Nov 2, 2022

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.

@582033
Copy link

582033 commented Nov 2, 2022

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.

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

8 participants