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

Unable to build golang.org/x/sys with Go 1.19 beta1 #3199

Closed
abhinav opened this issue Jun 14, 2022 · 3 comments · Fixed by #3231
Closed

Unable to build golang.org/x/sys with Go 1.19 beta1 #3199

abhinav opened this issue Jun 14, 2022 · 3 comments · Fixed by #3231

Comments

@abhinav
Copy link
Contributor

abhinav commented Jun 14, 2022

What version of rules_go are you using?

v0.33.0

What version of gazelle are you using?

v0.25.0

What version of Bazel are you using?

% bazel version
Build label: 5.1.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Apr 8 15:49:48 2022 (1649432988)
Build timestamp: 1649432988
Build timestamp as int: 1649432988

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

% uname -sm
Linux x86_64

What did you do?

Attempt to build a binary that imports golang.org/x/sys with Go 1.19 beta1.

What did you expect to see?

A successful build.

What did you see instead?

ERROR: /home/user/src/tmp/hello/BUILD.bazel:11:10: GoLink hello/hello_/hello failed: (Exit 1): builder failed: error executing command bazel-out/k8-opt-exec-2B5CBBC6/bin/external/go_sdk/builder link -sdk external/go_sdk -installsuffix linux_amd64 -arc ... (remaining 17 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox
2022/06/14 16:03:32 link: unlinkable object (from package golang.org/x/sys/unix) - compiler requires -p flag
link: error running subcommand external/go_sdk/pkg/tool/linux_amd64/link: exit status 1
Target //hello:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.

To reproduce, here's a copy of all files and the directory layout:

-- BUILD.bazel --
load("@bazel_gazelle//:def.bzl", "gazelle")

# gazelle:prefix example.com/demo
gazelle(name = "gazelle")

-- WORKSPACE --
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
    ],
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "5982e5463f171da99e3bdaeff8c0f48283a7a5f396ec5282910b9e8a49c0dd7e",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz",
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.25.0/bazel-gazelle-v0.25.0.tar.gz",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

go_repository(
    name = "org_golang_x_sys",
    importpath = "golang.org/x/sys",
    sum = "h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=",
    version = "v0.0.0-20220610221304-9f5ed59c137d",
)

go_rules_dependencies()

go_register_toolchains(version = "1.19beta1")

gazelle_dependencies()

# Workaround for https://github.com/bazelbuild/bazel-gazelle/issues/1217
go_repository(
    name = "org_golang_x_xerrors",
    importpath = "golang.org/x/xerrors",
    sum = "h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=",
    version = "v0.0.0-20200804184101-5ec99f83aff1",
)

-- go.mod --
module example.com/demo

go 1.18

require golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d

-- go.sum --
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

-- hello/BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "hello_lib",
    srcs = ["hello.go"],
    importpath = "example.com/demo/hello",
    visibility = ["//visibility:private"],
    deps = ["@org_golang_x_sys//unix"],
)

go_binary(
    name = "hello",
    embed = [":hello_lib"],
    visibility = ["//visibility:public"],
)

-- hello/hello.go --
package main

import (
	"fmt"

	_ "golang.org/x/sys/unix"
)

func main() {
	fmt.Println("hello")
}

I got successful builds for the following cases:

  • :hello_lib
  • replace /x/sys/unix with a no-op local dependency //foo:foo_lib
  • replace /x/sys/unix with a simple external dependency (go.uber.org/atomic in this case)

So this is specifically an issue with how x/sys/unix is linked.

@sywhang thinks this is caused by golang/go@e853464.

@btwiuse
Copy link

btwiuse commented Jul 6, 2022

Yes, I'm having the same issue in btwiuse/k0s after upgraded to go1.19rc1 with rules_go

$ ./bazelw build //:k0s --verbose_failures
/home/aaron/k0s/./bazelw:176: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  LooseVersion(release["tag_name"])
DEBUG: /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/external/starlark/defs.bzl:18:6: str: starlark rocks
DEBUG: /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/external/starlark/defs.bzl:19:6: tuple: (1, 2, 3)
DEBUG: /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/external/starlark/defs.bzl:20:6: map: {"foo": 1, "bar": 2}
DEBUG: /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/external/starlark/defs.bzl:24:6: int: 1
DEBUG: /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/external/starlark/defs.bzl:15:10: list = [1, 4, 7]
WARNING: The major revision of the Android NDK referenced by android_ndk_repository rule 'androidndk' is 24. The major revisions supported by Bazel are [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]. Bazel will attempt to treat the NDK as if it was r21. This may cause compilation and linkage problems. Please download a supported NDK version.
INFO: Analyzed target //:k0s (0 packages loaded, 2105 targets configured).
INFO: Found 1 target...
ERROR: /home/aaron/k0s/BUILD.bazel:33:10: GoLink k0s_/k0s failed: (Exit 1): builder failed: error executing command
  (cd /home/aaron/.cache/bazel/_bazel_aaron/b4cd2202f34bfe1a3912cce4a4d4bd76/sandbox/linux-sandbox/4222/execroot/k0s && \
  exec env - \
    CGO_ENABLED=1 \
    GOARCH=amd64 \
    GOOS=linux \
    GOPATH='' \
    GOROOT=bazel-out/k8-fastbuild-ST-decdbd95dc97/bin/external/io_bazel_rules_go/stdlib_ \
    GOROOT_FINAL=GOROOT \
    PATH=/usr/sbin:/bin:/usr/bin \
  bazel-out/k8-opt-exec-2B5CBBC6-ST-0bf7e073e26f/bin/external/go_sdk/builder '-param=bazel-out/k8-fastbuild-ST-0bf7e073e26f/bin/k0s_/k0s-0.params' -- -extld /usr/sbin/gcc -linkmode external '-buildid=redacted' -extldflags '-fuse-ld=lld -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/sbin -pass-exit-codes -lm')
# Configuration: a852bd58a63370b51deff94b3d18c413bfbd1a6d9301f08d33ea6060140b363a
# Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
2022/07/07 07:47:24 link: unlinkable object (from package k0s.io/vendor/golang.org/x/sys/unix) - compiler requires -p flag
link: error running subcommand external/go_sdk/pkg/tool/linux_amd64/link: exit status 1
Target //:k0s failed to build
INFO: Elapsed time: 0.767s, Critical Path: 0.24s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

@fmeum
Copy link
Member

fmeum commented Jul 7, 2022

There has to be more to this story than is apparent from the Go changelog: We pass -p everywhere and thanks to https://go-review.googlesource.com/c/go/+/391014, compilation rather than linking should fail if we weren't. But somehow the compiler produces objects that the linker determines to be unlinkable. It probably has something to do with CGo, but I don't know nearly enough about how Go compilation to determine how.

@fmeum
Copy link
Member

fmeum commented Jul 7, 2022

go tool nm helped me diagnose this, we weren't passing -p to go tool asm. Submitted #3231.

anguslees added a commit to anguslees/go-jsonnet that referenced this issue Oct 26, 2022
Update `golang.org/x/sys` package to address golang/go#51706

Update bazel `rules_go` to address bazel-contrib/rules_go#3199
sparkprime pushed a commit to google/go-jsonnet that referenced this issue Oct 26, 2022
Update `golang.org/x/sys` package to address golang/go#51706

Update bazel `rules_go` to address bazel-contrib/rules_go#3199
copybara-service bot pushed a commit to tink-crypto/tink-go-hcvault that referenced this issue May 19, 2023
This required upgrading:
 * bazel-gazelle to v0.29.0 (see bazel-contrib/rules_go#3199)
 * io_bazel_rules_go to v0.37.0 (see compatibility table w/ bazel-gazelle here https://github.com/bazelbuild/bazel-gazelle/#compatibility-with-rules_go); this was preferred over more recent versions because since 0.38 this requires
org_golang_x_tools v0.5.0 [1], while Tink imports v0.1.12. io_bazel_rules_go
v0.37.0 is compatible with v0.1.12 [2].

[1] https://github.com/bazelbuild/rules_go/blob/cf78385a58e278b542511d246bb1cef287d528e9/go/private/repositories.bzl#L73
[2] https://github.com/bazelbuild/rules_go/blob/2a0f48241cf5a4838b9ccfde228863d75d6c646e/go/private/repositories.bzl#L73

PiperOrigin-RevId: 533540295
Change-Id: If55acb1d82e60d09cd0420b1575f94b0a802c7f2
copybara-service bot pushed a commit to tink-crypto/tink-go-awskms that referenced this issue May 19, 2023
This required upgrading:
 * bazel-gazelle to v0.29.0 (see bazel-contrib/rules_go#3199)
 * io_bazel_rules_go to v0.37.0 (see compatibility table w/ bazel-gazelle here https://github.com/bazelbuild/bazel-gazelle/#compatibility-with-rules_go); this was preferred over more recent versions because since 0.38 this requires
org_golang_x_tools v0.5.0 [1], while Tink imports v0.1.12. io_bazel_rules_go
v0.37.0 is compatible with v0.1.12 [2].

[1] https://github.com/bazelbuild/rules_go/blob/cf78385a58e278b542511d246bb1cef287d528e9/go/private/repositories.bzl#L73
[2] https://github.com/bazelbuild/rules_go/blob/2a0f48241cf5a4838b9ccfde228863d75d6c646e/go/private/repositories.bzl#L73

PiperOrigin-RevId: 533540295
Change-Id: I676a3416fd0b2b9fc342e0946c110b22fd89ca2f
copybara-service bot pushed a commit to tink-crypto/tink-go-gcpkms that referenced this issue May 19, 2023
This required upgrading:
 * bazel-gazelle to v0.29.0 (see bazel-contrib/rules_go#3199)
 * io_bazel_rules_go to v0.37.0 (see compatibility table w/ bazel-gazelle here https://github.com/bazelbuild/bazel-gazelle/#compatibility-with-rules_go); this was preferred over more recent versions because since 0.38 this requires
org_golang_x_tools v0.5.0 [1], while Tink imports v0.1.12. io_bazel_rules_go
v0.37.0 is compatible with v0.1.12 [2].

[1] https://github.com/bazelbuild/rules_go/blob/cf78385a58e278b542511d246bb1cef287d528e9/go/private/repositories.bzl#L73
[2] https://github.com/bazelbuild/rules_go/blob/2a0f48241cf5a4838b9ccfde228863d75d6c646e/go/private/repositories.bzl#L73

PiperOrigin-RevId: 533540295
Change-Id: I51b437418ac8cc63a18a26e4fdc7ee612c77f332
copybara-service bot pushed a commit to tink-crypto/tink-go that referenced this issue May 19, 2023
This required upgrading:
 * bazel-gazelle to v0.29.0 (see bazel-contrib/rules_go#3199)
 * io_bazel_rules_go to v0.37.0 (see compatibility table w/ bazel-gazelle here https://github.com/bazelbuild/bazel-gazelle/#compatibility-with-rules_go); this was preferred over more recent versions because since 0.38 this requires
org_golang_x_tools v0.5.0 [1], while Tink imports v0.1.12. io_bazel_rules_go
v0.37.0 is compatible with v0.1.12 [2].

[1] https://github.com/bazelbuild/rules_go/blob/cf78385a58e278b542511d246bb1cef287d528e9/go/private/repositories.bzl#L73
[2] https://github.com/bazelbuild/rules_go/blob/2a0f48241cf5a4838b9ccfde228863d75d6c646e/go/private/repositories.bzl#L73

PiperOrigin-RevId: 533540295
Change-Id: I818b20b5a00917c719d159b18166d293cc68e1ab
chuckx pushed a commit to tink-crypto/tink that referenced this issue Jun 5, 2023
This required upgrading:
 * bazel-gazelle to v0.29.0 (see bazel-contrib/rules_go#3199)
 * io_bazel_rules_go to v0.37.0 (see compatibility table w/ bazel-gazelle here https://github.com/bazelbuild/bazel-gazelle/#compatibility-with-rules_go); this was preferred over more recent versions because since 0.38 this requires
org_golang_x_tools v0.5.0 [1], while Tink imports v0.1.12. io_bazel_rules_go
v0.37.0 is compatible with v0.1.12 [2].

[1] https://github.com/bazelbuild/rules_go/blob/cf78385a58e278b542511d246bb1cef287d528e9/go/private/repositories.bzl#L73
[2] https://github.com/bazelbuild/rules_go/blob/2a0f48241cf5a4838b9ccfde228863d75d6c646e/go/private/repositories.bzl#L73

PiperOrigin-RevId: 533540295
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

Successfully merging a pull request may close this issue.

3 participants