Skip to content

Go 1.26 + CGO_ENABLED=1 on linux/amd64: "relocation target dlopen not defined" for dlopenABI0/dlsymABI0/dlcloseABI0/dlerrorABI0 #450

@aminmokhtari94

Description

@aminmokhtari94

Environment

  • purego: v0.8.4 (transitive — via github.com/ClickHouse/clickhouse-go/v2github.com/shirou/gopsutil/v4)
  • Go: 1.26
  • GOOS/GOARCH: linux/amd64
  • CGO_ENABLED: 1
  • Build tool: ko, base image frolvlad/alpine-glibc:latest

Error

# amin
github.com/ebitengine/purego.dlopenABI0:  relocation target dlopen not defined
github.com/ebitengine/purego.dlsymABI0:   relocation target dlsym not defined
github.com/ebitengine/purego.dlcloseABI0: relocation target dlclose not defined
github.com/ebitengine/purego.dlerrorABI0: relocation target dlerror not defined

Full build log:

Error running ko build, exit status 1 , output: 2026/05/13 10:22:02 Using base frolvlad/alpine-glibc:latest@sha256:248933011db7eae9c848f90800edb8aad79cf3ab8b617e45ea1c256a83f2a43b for amin
2026/05/13 10:22:02 current folder is not a git repository. Git info will not be available
2026/05/13 10:22:02 Building amin for linux/amd64
Error: failed to publish images: error building "ko://amin": build: go build: exit status 1: # amin
github.com/ebitengine/purego.dlopenABI0: relocation target dlopen not defined
github.com/ebitengine/purego.dlsymABI0: relocation target dlsym not defined
github.com/ebitengine/purego.dlcloseABI0: relocation target dlclose not defined
github.com/ebitengine/purego.dlerrorABI0: relocation target dlerror not defined

The build surfaced after upgrading the Go toolchain to 1.26; I have not seen this error on earlier toolchains for the same project, though I have not yet rebuilt against 1.25 to confirm it's a clean regression.

Analysis

The error is hit through the nocgo path in dlfcn_nocgo_linux.go (build constraint !cgo && !faketime), which declares the libdl symbols via:

//go:cgo_import_dynamic purego_dlopen  dlopen  "libdl.so.2"
//go:cgo_import_dynamic purego_dlsym   dlsym   "libdl.so.2"
//go:cgo_import_dynamic purego_dlerror dlerror "libdl.so.2"
//go:cgo_import_dynamic purego_dlclose dlclose "libdl.so.2"

Under Go 1.26 the linker does not appear to wire those dynamic imports to the ABI0 stubs in dlfcn_stubs.s, so each assembly stub fails with relocation target <sym> not defined.

Go 1.26 release notes call out several linker structural changes (relocations moved out of .gopclntab, section reordering, ELF sections sorted by address under internal linking, etc.). The notes say "these changes do not affect running Go programs" — but the build-time behavior here suggests something around //go:cgo_import_dynamic resolution may have shifted.

#189 looked superficially similar but on a different (R_CALL) path; this may be a distinct case specific to 1.26.

Reproduction

  1. Project that transitively imports github.com/ebitengine/purego (e.g. anything pulling github.com/ClickHouse/clickhouse-go/v2 latest → gopsutil/v4).
  2. CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./... with Go 1.26.

Asks

  • Confirm whether Go 1.26 + CGO_ENABLED=1 on linux/amd64 is intended to be supported for the nocgo dlfcn path.
  • If reproducible on your end, a fix to dlfcn_nocgo_linux.go / dlfcn_stubs.s so the assembly relocations resolve under the new linker behavior.

Happy to test patches and to provide a minimal repro / a 1.25-vs-1.26 comparison build if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions