-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
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 grafana/agent@7e4cae2 - 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