bazel-contrib / bazel-contrib/rules_go

Compiling as static pie doesn't work via bazel, but works with the go command

Open
#3,772 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

`0.43.0`

### What version of gazelle are you using?

none

### What version of Bazel are you using?

From `gcr.io/bazel-public/bazel:latest`:

```
Build label: 6.4.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Oct 19 17:07:43 2023 (1697735263)
Build timestamp: 1697735263
Build timestamp as int: 1697735263
```

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

Yes

### What operating system and processor architecture are you using?

Linux amd64

### Any other potentially useful information about your toolchain?

The toolchains installed in gcr.io/bazel-public/bazel:latest

### What did you do?

Tried to migrate a static pie go binary from the native toolchain to bazel.

Minimal sample project: https://github.com/bluec0re/rules_go_linker_error

### What did you expect to see?

It compiles into a static pie binary.

### What did you see instead?

```
[...]
external/go_sdk/pkg/tool/linux_amd64/link: running /usr/bin/gcc failed: exit status 1
/usr/bin/ld.gold: --no-dynamic-linker: unknown option
/usr/bin/ld.gold: use the --help option for usage information
collect2: error: ld returned 1 exit status

link: error running subcommand external/go_sdk/pkg/tool/linux_amd64/link: exit status 2
Target //:hello failed to build
[...]
```

Contributor guide

Open the contributing guide

Research direction

Start with the minimal sample project linked in the issue and reproduce the Bazel build on Linux amd64 using rules_go 0.43.0 and Bazel 6.4.0. Compare the Bazel linker invocation with the working go-command build, focusing on the ld.gold error for --no-dynamic-linker. Done means the sample builds successfully as a static PIE through Bazel.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.