-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Go link tool needs to find gcc on Arm platform #1574
Conversation
Hi all,
|
go/private/actions/compile.bzl
Outdated
@@ -103,5 +103,7 @@ def _bootstrap_compile(go, sources, out_lib, gc_goopts): | |||
inputs = sources + go.sdk_files + go.sdk_tools, | |||
outputs = [out_lib], | |||
mnemonic = "GoCompile", | |||
command = "export GOROOT=$(pwd)/{} && export GOROOT_FINAL=GOROOT && {} {}".format(go.root, go.go.path, " ".join(args)), | |||
# workaround: go link tool needs some features of gcc to complete the job on Arm platform. | |||
# So, PATH for 'gcc' is required here on Arm platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is gcc needed for compiling Go code? My expectation is that it should only be required for linking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it form compile.bzl
Thanks.
go/private/actions/link.bzl
Outdated
@@ -159,6 +159,8 @@ def _bootstrap_link(go, archive, executable, gc_linkopts): | |||
inputs = inputs, | |||
outputs = [executable], | |||
mnemonic = "GoLink", | |||
# workaround: go link tool needs some features of gcc to complete the job on Arm platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATH
isn't actually set here.
Instead of setting PATH
though, I think it would be better to set CC
to go.cgo_tools.ld_executable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jayconrod
'CC=go.cgo_tools.ld_executable' is useless here.
I modified the code like this:
command = "export GOROOT=$(pwd)/{} && export GOROOT_FINAL=GOROOT && export CC={} && {} {}".format(go.root, go.cgo_tools.ld_executable, go.go.path, " ".join(args)),
And google/gvisor still reported that 'gcc' was not found in $PATH.
Please see full logs as reference:
root@bin:/go/src/github.com/google/gvisor# bazel build runsc --verbose_failures
INFO: SHA256 (https://github.com/lubinsz/rules_go/archive/801a52883ef36ae078f069bc250a325ca7121acd.tar.gz) = 5ba38ec2b0bee96a77793f7f95669fa4ea101599aa39eb8dce1b9daf149431fd
INFO: Build options have changed, discarding analysis cache.
INFO: Analysed target //runsc:runsc (183 packages loaded).
INFO: Found 1 target...
ERROR: /root/.cache/bazel/_bazel_root/954c2359eaedb37da1533cf5fa671511/external/io_bazel_rules_go/go/tools/builders/BUILD.bazel:54:1: error executing shell command: 'export GOROOT=$(pwd)/external/go_sdk && export GOROOT_FINAL=GOROOT && export CC=/usr/bin/ld && external/go_sdk/bin/go tool link -s -o bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders...' failed (Exit 1): bash failed: error executing command
(cd /root/.cache/bazel/_bazel_root/954c2359eaedb37da1533cf5fa671511/execroot/main &&
exec env -
/bin/bash -c 'export GOROOT=$(pwd)/external/go_sdk && export GOROOT_FINAL=GOROOT && export CC=/usr/bin/ld && external/go_sdk/bin/go tool link -s -o bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_arm64_stripped/embed bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_arm64_stripped/embed~/go/tools/builders/embed.a')
Use --sandbox_debug to see verbose messages from the sandbox
/root/.cache/bazel/_bazel_root/954c2359eaedb37da1533cf5fa671511/sandbox/linux-sandbox/4/execroot/main/external/go_sdk/pkg/tool/linux_arm64/link: running gcc failed: exec: "gcc": executable file not found in $PATH
Target //runsc:runsc failed to build
ERROR: /go/src/github.com/google/gvisor/runsc/BUILD:5:1 error executing shell command: 'export GOROOT=$(pwd)/external/go_sdk && export GOROOT_FINAL=GOROOT && export CC=/usr/bin/ld && external/go_sdk/bin/go tool link -s -o bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders...' failed (Exit 1): bash failed: error executing command
(cd /root/.cache/bazel/_bazel_root/954c2359eaedb37da1533cf5fa671511/execroot/main &&
exec env -
/bin/bash -c 'export GOROOT=$(pwd)/external/go_sdk && export GOROOT_FINAL=GOROOT && export CC=/usr/bin/ld && external/go_sdk/bin/go tool link -s -o bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_arm64_stripped/embed bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/linux_arm64_stripped/embed~/go/tools/builders/embed.a')
Use --sandbox_debug to see verbose messages from the sandbox
INFO: Elapsed time: 20.737s, Critical Path: 8.50s
INFO: 7 processes, linux-sandbox.
FAILED: Build did NOT complete successfully
root@bin:/go/src/github.com/google/gvisor# uname -p
aarch64
Hi @jayconrod
|
Reference #1506 "arm64 support" |
@jayconrod |
@lubinszARM The So as I understand this, external linking (i.e., linking the final compiled Go code with a C linker like gcc or clang) is required on arm64 because of limitations in the Go toolchain. golang/go#10373 is an open feature request for this. There is also some discussion. I don't know the details of this; if you know, it would be helpful to add a comment explaining it. Otherwise, just add a comment pointing to golang/go#10373. The right way to provide an external linker is to pass the Hard coding Note that this PR currently only affects linking of host mode tools (i.e., our wrappers for the compiler, linker, and other tools). It won't affect linking of |
Signed-off-by: Bin Lu <[email protected]>
Hi @jayconrod For issue #10373 in golang, my colleague has finished a prototype for it. But as he said, there are still a lot of work to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Signed-off-by: Bin Lu [email protected]