Skip to content

runtime: init function run unexpectedly when plugin.Open fails #75102

@WangLeonard

Description

@WangLeonard

Go version

master

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=''
GOCACHE='/home/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2883029808=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'

What did you do?

plugin.go

package main

func init() {
	panic("unexpected call to init")
}

func main() {}

go build -gcflags=all=-N -l -buildmode=plugin

main.go

package main

import (
	"fmt"
	"plugin"
)

func init() {
	_, err := plugin.Open("issue75102.so")
	if err == nil {
		panic("unexpected success to open a different version plugin")
	}
}

func main() {
	fmt.Println("done")
}

go build

What did you see happen?

panic("unexpected call to init")

What did you expect to see?

print "done"

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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions