go application build with bazel can't link when running inside container

219 views Asked by At

I am trying to containerize my application build, though, when running the build that uses bazel with bazel-gazelle inside a container I will get this error:

$ bazel run --spawn_strategy=local //:gazelle --verbose_failures 
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/workstation/.cache/bazel/_bazel_workstation/fb227af4c7b6aa39cc5b15d7fd9b737a/external/go_sdk/BUILD.bazel:43:15: GoToolchainBinary external/go_sdk/builder [for host] failed: (Exit 1): go failed: error executing command 
  (cd /home/workstation/.cache/bazel/_bazel_workstation/fb227af4c7b6aa39cc5b15d7fd9b737a/execroot/__main__ && \
  exec env - \
    GOROOT_FINAL=GOROOT \
  external/go_sdk/bin/go tool link -o bazel-out/host/bin/external/go_sdk/builder bazel-out/host/bin/external/go_sdk/builder.a)
# Configuration: e0f1106e28100863b4221c55fca6feb935acec078da5376e291cf644e275dae5
# Execution platform: @local_config_platform//:host
/opt/go/pkg/tool/linux_amd64/link: mapping output file failed: invalid argument
Target //:gazelle failed to build
INFO: Elapsed time: 2.302s, Critical Path: 0.35s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

I tried to run it standalone:

$ /home/workstation/.cache/bazel/_bazel_workstation/fb227af4c7b6aa39cc5b15d7fd9b737a/external/go_sdk/bin/go tool link -o bazel-out/host/bin/external/go_sdk/builder bazel-out/host/bin/external/go_sdk/builder.a
/opt/go/pkg/tool/linux_amd64/link: mapping output file failed: invalid argument

and still got no success.

Never had this kind of link problem and the linker don't provide much more information. Tried to install all packages I could think of and still no luck.

For context:

Running Ubuntu 20.04 LTS
Docker         20.10.9
Bazel          4.2.2
Rules GO       v0.31.0
Bazel Gazelle  v0.25.0

Also tried to run it with the strace, though I don't think I am skilled enough to find meaningful information from the tool output.

@edit

For more context:

e$ /home/workstation/.cache/bazel/_bazel_workstation/fb227af4c7b6aa39cc5b15d7fd9b737a/external/go_sdk/bin/go tool link -v -o bazel-out/host/bin/external/go_sdk/builder bazel-out/host/bin/external/go_sdk/builder.a
HEADER = -H5 -T0x401000 -R0x1000
searching for runtime.a in /opt/go/pkg/linux_amd64/runtime.a
/opt/go/pkg/tool/linux_amd64/link: mapping output file failed: invalid argument
0

There are 0 answers