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?

  1. Cloned the grafana/agent repo, and checked out the reproduce-relocation-truncated branch or https://github.com/grafana/agent/commit/7e4cae232290d4ab13e5e892dfb61e668d97f6b1
  2. Run USE_CONTAINER=1 GOOS=linux GOARCH=arm GOARM=6 make agentctl to cross-compile the agentctl binary for ARMv6
  3. 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 gcc for the GOOS/GOARCH/GOARM tuple and calls out to it; in this case arm-linux-gnueabi-gcc installed 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

Most upvoted comments

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.