Skip to content

cmd/link: coro_var.go reports a DWARF error or panics instead of rejecting the linkname #81567

Open

Description

@zhouguangyuan0718

Go version

go version devel go1.27-5c06c57d21 linux/amd64

Commit: 5c06c57d21281817ab62fa3083f92a8cedf76806.

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='<redacted>'
GOCACHE='<redacted>'
GOCACHEPROG=''
GODEBUG=''
GOENV=''
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=<redacted>=<redacted> -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='<redacted>'
GOMODCACHE='<redacted>'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPACKAGESDRIVER=''
GOPATH='<redacted>'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='<redacted>'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='<redacted>'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='<redacted>'
GOVCS=''
GOVERSION='devel go1.27-5c06c57d21'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Build the existing cmd/link/testdata/linkname/coro_var.go negative test, with and without DWARF generation:

go build coro_var.go
go build -ldflags=-w coro_var.go

The program is:

package main

import "unsafe"

func main() {
    call(&newcoro)
}

//go:linkname newcoro runtime.newcoro
var newcoro unsafe.Pointer

//go:noinline
func call(*unsafe.Pointer) {
    // not implemented
}

What did you see happen?

The default build fails with an internal linker error:

link: error: non-function sym 27596/runtime.newcoro t=SBSS passed to GetFuncDwarfAuxSyms

With -ldflags=-w, it instead panics with an index-out-of-range error in cmd/link/internal/ld.(*Link).findfunctab.func1.

panic: runtime error: index out of range [1967] with length 1967

goroutine 97 [running]:
cmd/link/internal/ld.(*Link).findfunctab.func1(0xd2e80a8ded8?, 0xfdb8?)
	/tmp/pr291-upstream-draft/go/src/cmd/link/internal/ld/pcln.go:1056 +0x59f
cmd/link/internal/ld.writeBlock(0xd2e7fc7a600, 0xd2e80b1c000, 0xd2e7fc92a88, {0xd2e80684800, 0x1035, 0xd2e80b00000?}, 0x617?, 0x617?, {0xd73180, 0x200, ...})
	/tmp/pr291-upstream-draft/go/src/cmd/link/internal/ld/data.go:1146 +0x4c2
cmd/link/internal/ld.writeBlocks.func1(0xd2e8091a000?, 0x617?, {0xd2e80684800?, 0x900000000000000?, 0x1b?}, 0xd2e808f6a10?, 0xd2e801fe608?, {0xd73180, 0x200, 0x200})
	/tmp/pr291-upstream-draft/go/src/cmd/link/internal/ld/data.go:1097 +0x70
created by cmd/link/internal/ld.writeBlocks in goroutine 82
	/tmp/pr291-upstream-draft/go/src/cmd/link/internal/ld/data.go:1096 +0x6b9

The existing TestCheckLinkname/coro_var.go subtest still passes because it only checks for an unsuccessful build, not the reason for the failure.

What did you expect to see?

Both builds should reject the forbidden linkname with:

link: main: invalid reference to runtime.newcoro

Disabling DWARF generation should not change this into a linker panic.

Go 1.26.5 correctly rejects the same program with an invalid-reference diagnostic.

loader.addSym applies Dupok precedence before resolving TEXT/BSS pairs. The non-Dupok BSS declaration can therefore replace runtime.newcoro's Dupok ABI wrapper, losing its function metadata and linkname permissions. The linkname check is missed, and the linker fails later in DWARF generation or findfunctab. Preserving the TEXT definition before applying Dupok precedence restores the expected invalid-reference diagnostic.

Activity

  1. gopherbot commented on Sep 16, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/833605 mentions this issue: cmd/link: preserve TEXT definitions when merging BSS aliases

  2. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Sep 18, 2026
  3. added this to the Backlog milestone on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions