Skip to content

cmd/link: slow link times with large amounts of DWARF data #75508

@orf

Description

@orf

Go version

go version go1.26-devel_bffe7ad9f1 Wed Sep 17 06:43:57 2025 -0700 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/tom/.local/share/mise/installs/go/1.25.0/bin'
GOCACHE='/Users/tom/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/tom/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/r1/myg4s_g127d6pjrb1rbry1_80000gn/T/go-build559902963=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/tom/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tom/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/tom/.local/share/mise/installs/go/1.25.0'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/tom/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tom/.local/share/mise/installs/go/1.25.0/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26-devel_bffe7ad9f1 Wed Sep 17 06:43:57 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

We have a binary that has around ~1GB of DWARF data when built. This takes ~4 minutes, 3 of which is spent inside the linker.

What did you see happen?

When passing the -w argument to the linker to skip including DWARF data the linker runtime is reduced to ~30 seconds.

After some profiling (see attached linker-cpu.prof.gz), ~25% of linker runtime is spent inside runtime/memmove.

One of the biggest culprits seems to be WriteSym here:

func (out *OutBuf) WriteSym(ldr *loader.Loader, s loader.Sym) []byte {
if !ldr.IsGeneratedSym(s) {
P := ldr.Data(s)
n := int64(len(P))
pos, buf := out.writeLoc(n)
copy(buf[pos:], P)
out.off += n
ldr.FreeData(s)
return buf[pos : pos+n]

Specifically, with this binary copy() is called 5,402,448 times and moves a total of 832 MB.

What did you expect to see?

Building binaries that bring in large volumes of DWARF data should not take ~3 minutes to build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions