Context
PR #6248 added binutils-gold to 6 development Dockerfiles to fix
ARM64 (Apple Silicon) builds failing with cannot find 'ld' during
go install of dev tools (air, golangci-lint, mockery).
The fix works but has issues:
-
Wrong root cause: the PR attributed -fuse-ld=gold to
golangci-lint, but it actually comes from Go's own toolchain
(/usr/local/go/pkg/tool/linux_arm64/link) when CGO is enabled
on linux/arm64. Verified by reproducing in
golang:1.25.8-alpine3.22 ARM64 container.
-
gold is deprecated: removed/marked deprecated in binutils 2.44
(Jan 2025). Alpine will drop the package eventually.
-
Bloat for x86_64 users: the package is only needed on ARM64,
but was added unconditionally to all dev images.
-
CGO not actually needed: the tools installed (air, golangci-lint,
mockery) are pure Go and don't require cgo.
Reproduction
# Fails on ARM64 without binutils-gold
docker run --rm --platform linux/arm64 golang:1.25.8-alpine3.22 sh -c '
apk add --no-cache git build-base
CGO_ENABLED=1 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.3
'
# → /usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exit status 1
# → collect2: fatal error: cannot find 'ld'
# Works on ARM64 without binutils-gold
docker run --rm --platform linux/arm64 golang:1.25.8-alpine3.22 sh -c '
apk add --no-cache git
CGO_ENABLED=0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.3
'
# → success, binary works
Proposed fix
Replace binutils-gold install + default cgo with CGO_ENABLED=0
on all go install of dev tools, in 6 Dockerfiles:
# Remove binutils-gold (and build-base where it was added only for this) from apk add
RUN apk add --update openssl ...
# Add CGO_ENABLED=0 to each go install
RUN CGO_ENABLED=0 go install github.com/air-verse/air@v1.62 && \
CGO_ENABLED=0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.3 && \
CGO_ENABLED=0 go install github.com/vektra/mockery/v2/...@v2.53.2
Files affected:
agent/Dockerfile
api/Dockerfile
cli/Dockerfile
gateway/Dockerfile
openapi/Dockerfile
ssh/Dockerfile
Future-proofing note
If we ever need cgo in dev tools or in the actual app build, the
modern replacement for gold is ld.lld (LLVM linker), available
via apk add lld. To force Go to use it on ARM64 alpine:
ENV CGO_LDFLAGS="-fuse-ld=lld".
Context
PR #6248 added
binutils-goldto 6 development Dockerfiles to fixARM64 (Apple Silicon) builds failing with
cannot find 'ld'duringgo installof dev tools (air, golangci-lint, mockery).The fix works but has issues:
Wrong root cause: the PR attributed
-fuse-ld=goldtogolangci-lint, but it actually comes from Go's own toolchain
(
/usr/local/go/pkg/tool/linux_arm64/link) when CGO is enabledon linux/arm64. Verified by reproducing in
golang:1.25.8-alpine3.22ARM64 container.gold is deprecated: removed/marked deprecated in binutils 2.44
(Jan 2025). Alpine will drop the package eventually.
Bloat for x86_64 users: the package is only needed on ARM64,
but was added unconditionally to all dev images.
CGO not actually needed: the tools installed (air, golangci-lint,
mockery) are pure Go and don't require cgo.
Reproduction
Proposed fix
Replace
binutils-goldinstall + default cgo withCGO_ENABLED=0on all
go installof dev tools, in 6 Dockerfiles:Files affected:
agent/Dockerfileapi/Dockerfilecli/Dockerfilegateway/Dockerfileopenapi/Dockerfilessh/DockerfileFuture-proofing note
If we ever need cgo in dev tools or in the actual app build, the
modern replacement for gold is
ld.lld(LLVM linker), availablevia
apk add lld. To force Go to use it on ARM64 alpine:ENV CGO_LDFLAGS="-fuse-ld=lld".