go: cmd/link: compilation failure on armv6/armv7 due to truncated relocations
What version of Go are you using (go version)?
$ docker run grafana/agent-build-image:0.21.0 bash -c "go version" go version go1.20 linux/arm64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
The following is for the build container that cross-compiles to armv6/armv7 and encounters the failure
go env Output
$ docker run grafana/agent-build-image:0.21.0 bash -c "go env" GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/root/.cache/go-build" GOENV="/root/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.20" GCCGO="gccgo" AR="ar" CC="viceroycc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1972461801=/tmp/go-build -gno-record-gcc-switches"
What did you do?
- Cloned the grafana/agent repo, and checked out the
reproduce-relocation-truncatedbranch or https://github.com/grafana/agent/commit/7e4cae232290d4ab13e5e892dfb61e668d97f6b1 - Run
USE_CONTAINER=1 GOOS=linux GOARCH=arm GOARM=6 make agentctlto cross-compile theagentctlbinary for ARMv6 - Wait around
What did you expect to see?
A successful compilation
What did you see instead?
# github.com/grafana/agent/cmd/grafana-agentctl
/usr/local/go/pkg/tool/linux_amd64/link: running viceroycc failed: exit status 1
/tmp/go-link-3047421554/go.o: in function `github.com/google/gnostic/openapiv3.NewResponse':
/go/pkg/mod/github.com/google/gnostic@v0.6.9/openapiv3/OpenAPIv3.go:3631:(.text+0x207d790): relocation truncated to fit: R_ARM_CALL against `runtime.duffzero'
/go/pkg/mod/github.com/google/gnostic@v0.6.9/openapiv3/OpenAPIv3.go:3635:(.text+0x207d894): relocation truncated to fit: R_ARM_CALL against `runtime.duffzero'
collect2: error: ld returned 1 exit status
make: *** [Makefile:195: agentctl] Error 1
Background
Hello team! I’m opening this issue on behalf of the Grafana Agent squad.
Recently, we saw our ARMv6 and ARMv6 builds start to fail with relocation truncated to fit: errors.
We think it has to do with the growing binary size and the number of dependencies that the Agent brings in. Looking at the GCC arm-specific options, we used the -mlong-calls flag for our ARM builds which hid the issue for a few more commits, until it resurfaced.
We also discovered #15823 for a similar issue around builds, but for a different architecture ppc64le which was fixed at the language level in CL27790. Do you think this is similar enough?
Some other information that might be useful:
- Our process uses a Docker container to perform the build and copies the resulting build back to the host
- It looks like that having CGO enabled/disabled has an effect on builds; we need CGO_ENABLED=1 for our dependencies
- Within the build container, CC is set to a shell script which looks for an appropriate
gccfor the GOOS/GOARCH/GOARM tuple and calls out to it; in this casearm-linux-gnueabi-gccinstalled from Debian bullseye is used
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (7 by maintainers)
Commits related to this issue
- cmd/link: add ARM to the architectures to split text sections for Fixes #58428 Change-Id: I2e5c277cf609b98081f38da8de4716fd0cd8efdd — committed to tpaschalis/go by tpaschalis a year ago
- cmd/link/internal/ld: fix text section splitting for ARM Fix a problem with trampoline generation for ARM that was causing link failures when building selected k8s targets. Representative error (this... — committed to golang/go by thanm a year ago
- cmd/link/internal/ld: fix text section splitting for ARM Fix a problem with trampoline generation for ARM that was causing link failures when building selected k8s targets. Representative error (this... — committed to Pryz/go by thanm a year ago
- cmd/link: better fix for arm32 trampgen problem with duff routines This patch provides a fix for a problem linking large arm32 binaries with external linking, specifically R_CALLARM relocations again... — committed to golang/go by thanm a year ago
- cmd/link: revert CL 467715 in favor of better fix This patch backs out CL 467715 (written to fix 58425), now that we have a better fix for the "relocation doesn't fit" problem in the trampoline gener... — committed to golang/go by thanm a year ago
- [release-branch.go1.19] cmd/link: better fix for arm32 trampgen problem with duff routines This patch provides a fix for a problem linking large arm32 binaries with external linking, specifically R_C... — committed to golang/go by thanm a year ago
- [release-branch.go1.20] cmd/link: better fix for arm32 trampgen problem with duff routines This patch provides a fix for a problem linking large arm32 binaries with external linking, specifically R_C... — committed to golang/go by thanm a year ago
- [release-branch.go1.20] cmd/link: better fix for arm32 trampgen problem with duff routines This patch provides a fix for a problem linking large arm32 binaries with external linking, specifically R_C... — committed to TroutSoftware/go by thanm a year ago
Yes, we first started to observe this with go1.19.4, and I’m able to locally reproduce the same issue using go1.19.5 as well.