Skip to content

cmd/link: linker panic and relocation errors with complex generics inlining #75461

@denisvmedia

Description

@denisvmedia

Go version

go version go1.25.1 windows/amd64 (the same applies to running on linux/amd64)

Output of go env in your module/workspace:

set AR=ar set CC=gcc set CGO_CFLAGS=-O2 -g set CGO_CPPFLAGS= set CGO_CXXFLAGS=-O2 -g set CGO_ENABLED=0 set CGO_FFLAGS=-O2 -g set CGO_LDFLAGS=-O2 -g set CXX=g++ set GCCGO=gccgo set GO111MODULE= set GOAMD64=v1 set GOARCH=amd64 set GOAUTH=netrc set GOBIN= set GOCACHE=C:\Users\user\AppData\Local\go-build set GOCACHEPROG= set GODEBUG= set GOENV=C:\Users\user\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFIPS140=off set GOFLAGS= set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\user\AppData\Local\Temp\go-build1541654439=/tmp/go-build -gno-record-gcc-switches set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMOD=NUL set GOMODCACHE=C:\Users\user\go\pkg\mod set GONOPROXY=gitlab.galeracluster.com/lib/executor set GONOSUMDB=gitlab.galeracluster.com/lib/executor set GOOS=windows set GOPATH=C:\Users\user\go set GOPRIVATE=gitlab.galeracluster.com/lib/executor set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Users\user\scoop\apps\go\current set GOSUMDB=sum.golang.org set GOTELEMETRY=local set GOTELEMETRYDIR=C:\Users\user\AppData\Roaming\go\telemetry set GOTMPDIR= set GOTOOLCHAIN=auto set GOTOOLDIR=C:\Users\user\scoop\apps\go\current\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.25.1 set GOWORK= set PKG_CONFIG=pkg-config

What did you do?

Tested a project using complex generic constraints with different third-party generic ordered map libraries. The project uses a generic registry pattern with constrained type parameters.

This PR contains the issue demo: denisvmedia/inventario#579

Issue is observed with go 1.25.1 (also with 1.25.0), but is NOT observed with go 1.24.7.

What did you see happen?

Error 1: Relocation Target Not Defined with github.com/wk8/go-ordered-map/v2:

# github.com/denisvmedia/inventario/backup/restore.test github.com/denisvmedia/inventario/backup/restore_test.TestRestoreService_SecurityValidation_CrossUserAccess: relocation target github.com/wk8/go-ordered-map/v2.New[go.shape.string,go.shape.*github.com/denisvmedia/inventario/models.User] not defined github.com/denisvmedia/inventario/backup/restore_test.TestRestoreService_SecurityValidation_CrossTenantAccess: relocation target github.com/wk8/go-ordered-map/v2.New[go.shape.string,go.shape.*github.com/denisvmedia/inventario/models.User] not defined [... multiple similar errors for different test functions ...] Compilation finished with exit code 1 

Error2: Linker Panic with github.com/elliotchance/orderedmap/v3

# github.com/denisvmedia/inventario/backup/restore.test panic: inlined function github.com/elliotchance/orderedmap/v3.NewOrderedMap[go.shape.string,go.shape.*github.com/denisvmedia/inventario/models.User] missing func info goroutine 1 [running]: cmd/link/internal/ld.genInlTreeSym(0xc00013e000, 0x88a6d?, {0xc00012a388, 0xc000100700, {0xc000cb7860, 0x340, 0x340}, {0x10, 0x14, 0x1f, ...}}, ...)	cmd/link/internal/ld/pcln.go:212 +0x4b9 cmd/link/internal/ld.makeInlSyms(0xc00013e000, {0xc012fdc000, 0x49b9, 0x49b9?}, 0xc0125cde30)	cmd/link/internal/ld/pcln.go:235 +0x21e cmd/link/internal/ld.(*Link).pclntab(0xc00013e000, {0xc012f26000?, 0xc0000123a8?, 0x12?})	cmd/link/internal/ld/pcln.go:839 +0x1ce cmd/link/internal/ld.Main(_, {0x20, 0x20, 0x1, 0x7, 0x10, 0x0, {0xc00000a691, 0x1, 0x1}, ...})	cmd/link/internal/ld/main.go:430 +0x185c main.main()	cmd/link/main.go:72 +0xddb 

Analysis

This appears to be a systematic linker issue when handling complex generic type parameters across package boundaries. The issue manifests in two different ways with different third-party libraries, but both involve:

  1. Complex generic constraints: P registry.PIDable[T] where PIDable itself has type parameters
  2. Cross-package inlining/linking of generic functions from third-party libraries
  3. The same problematic type signature: [go.shape.string,go.shape.*github.com/denisvmedia/inventario/models.User]

Pattern observed:

  • With orderedmap/v3: Linker panic during inlining metadata generation
  • With go-ordered-map/v2: Linker relocation target not defined error
  • Both involve the same complex generic type instantiation
  • Both occur when building/testing, not during normal compilation

Workaround

The same fix works for both errors: Adding //go:noinline to the problematic function prevents both the panic and relocation errors:

//go:noinline func NewRegistry[T any, P registry.PIDable[T]]() *Registry[T, P] { return &Registry[T, P]{ items: orderedmap.NewOrderedMap[string, P](), // or go-ordered-map/v2.New[string, P]() lock: &sync.RWMutex{}, } }

This strongly suggests the root cause is the same: linker issues with inlining complex generic functions.

Reproduction Conditions

The issue appears to require specific conditions that make minimal reproduction difficult:

  • Complex generic constraint hierarchies (T any, P SomeInterface[T])
  • Cross-package boundaries
  • Multiple instantiation sites
  • Specific build/test contexts (in this case only go test triggers it)

What did you expect to see?

Successful test execution.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions