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

Broken change of golang.org/x/sys causes build failed in go1.16 #163

Open
zhongxinghong opened this issue Dec 23, 2022 · 2 comments
Open
Labels
question Further information is requested

Comments

@zhongxinghong
Copy link

Question

Current go.mod use go1.16 with golang.org/x/sys v0.0.0-20221010170243-090e33056c14 package which introduced go1.17's unsafe.Slice in 20220910 (see history https://cs.opensource.google/go/x/sys/+/master:unix/syscall.go;bpv=1). This will cause build failed in go1.16 with following error messges.

# golang.org/x/sys/unix
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../compile_path/pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17
@zhongxinghong zhongxinghong added the question Further information is requested label Dec 23, 2022
@zhangyunhao116
Copy link
Member

I can't reproduce this error, could you list a more detailed reproduction process? thanks!

My steps:

> go version
go version go1.16.15 linux/amd64
> git clone https://github.com/bytedance/gopkg.git && cd gopkg && go test ./...
go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
go: downloading github.com/stretchr/testify v1.7.0
go: downloading golang.org/x/sys v0.0.0-20221010170243-090e33056c14
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: downloading github.com/davecgh/go-spew v1.1.0
ok      github.com/bytedance/gopkg/cache/asynccache     6.819s
ok      github.com/bytedance/gopkg/cloud/circuitbreaker 18.233s
ok      github.com/bytedance/gopkg/cloud/metainfo       0.002s
ok      github.com/bytedance/gopkg/collection/hashset   0.121s
ok      github.com/bytedance/gopkg/collection/lscq      0.361s
ok      github.com/bytedance/gopkg/collection/skipmap   0.348s
ok      github.com/bytedance/gopkg/collection/skipset   0.132s
ok      github.com/bytedance/gopkg/collection/zset      0.029s
?       github.com/bytedance/gopkg/internal/benchmark/linkedq   [no test files]
?       github.com/bytedance/gopkg/internal/benchmark/msq       [no test files]
?       github.com/bytedance/gopkg/internal/hack        [no test files]
ok      github.com/bytedance/gopkg/internal/runtimex    0.002s
ok      github.com/bytedance/gopkg/internal/wyhash      0.205s
ok      github.com/bytedance/gopkg/lang/fastrand        0.028s
ok      github.com/bytedance/gopkg/lang/mcache  0.002s
ok      github.com/bytedance/gopkg/lang/stringx 0.002s
ok      github.com/bytedance/gopkg/lang/syncx   0.116s
ok      github.com/bytedance/gopkg/util/gctuner 0.025s
ok      github.com/bytedance/gopkg/util/gopool  0.015s
?       github.com/bytedance/gopkg/util/logger  [no test files]
ok      github.com/bytedance/gopkg/util/xxhash3 0.369s
?       github.com/bytedance/gopkg/util/xxhash3/internal/xxh3_raw       [no test files]

@zhongxinghong
Copy link
Author

zhongxinghong commented Dec 30, 2022

This is because bytedance/gopkg doesn't depend on golang.org/x/sys/unix. Let's create a package that depends on it then you will see the problem:

  1. setup
$ /usr/local/go1.16.15/bin/go version
go version go1.16.15 linux/amd64
$ mkdir -p ~/go/src/test/issue163 && cd ~/go/src/test/issue163
$ touch go.mod
$ touch main.go
  1. create main.go
//go:build linux
// +build linux

package main

import (
    "github.com/bytedance/gopkg/util/gopool"
    "golang.org/x/sys/unix"
)

func main() {
    _ = gopool.NewPool
    _ = unix.Fadvise
}
  1. create go.mod
module test/issue163

go 1.16
  1. go mod tidy
$ /usr/local/go1.16.15/bin/go mod tidy
go: finding module for package golang.org/x/sys/unix
go: finding module for package github.com/bytedance/gopkg/util/gopool
go: found github.com/bytedance/gopkg/util/gopool in github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
go: found golang.org/x/sys/unix in golang.org/x/sys v0.3.0

after current step our go.mod will look like this:

module test/issue163

go 1.16

require (
    github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
    golang.org/x/sys v0.3.0
)
  1. go build
$ /usr/local/go1.16.15/bin/go build
# golang.org/x/sys/unix
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2256:9: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17
  1. downgrade golang.org/x/sys and test it again
  • modify our go.mod
module test/issue163

go 1.16

require (
    github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
    golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe
)

NOTE: a commonly used library in ByteDance use golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe

  • go mod tidy
$ /usr/local/go1.16.15/bin/go mod tidy

then our go.mod will look like this:

module test/issue163

go 1.16

require (
    github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6
    golang.org/x/sys v0.0.0-20221010170243-090e33056c14
)

the version of golang.org/x/sys will be changed to v0.0.0-20221010170243-090e33056c14 since bytedance/gopkg choose it.

  • go build
$ /usr/local/go1.16.15/bin/go build
# golang.org/x/sys/unix
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall.go:83:16: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
../../../pkg/mod/golang.org/x/[email protected]/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
note: module requires Go 1.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants