Skip to content

plugin: loading a copy of an already loaded plugin panics #19004

Closed
@campoy

Description

@campoy

Please answer these questions before submitting your issue. Thanks!

What did you do?

Given a simple plugin hello.go:

package main

import "fmt"

func Run() { fmt.Println("Hello") }

I build it into a .so file and create a copy of the resulting file.

$ go build -buildmode=plugin hello.go
$ cp hello.so bye.so

Then running this program panics:

_, err := plugin.Open("hello.so")
if err != nil {
	log.Fatal(err)
}
_, err = plugin.Open("bye.so")
if err != nil {
	log.Fatal(err)
}

The result of the execution is:

plugin: plugin plugin/unnamed-5e323bb7e1479d9f71342c85ad29e7552ca5f746 already loaded
fatal error: plugin: plugin already loaded

goroutine 1 [running]:
runtime.throw(0x534999, 0x1d)
	/usr/local/go/src/runtime/panic.go:596 +0x95 fp=0xc420045b80 sp=0xc420045b60
plugin.lastmoduleinit(0x1e5a400, 0xc42000fb18, 0x1e5ba70, 0xc, 0x7b52a0)
	/usr/local/go/src/runtime/plugin.go:25 +0xc1a fp=0xc420045cb0 sp=0xc420045b80
plugin.open(0x530dda, 0x6, 0x0, 0x0, 0x0)
	/usr/local/go/src/plugin/plugin_dlopen.go:72 +0x25d fp=0xc420045ef0 sp=0xc420045cb0
plugin.Open(0x530dda, 0x6, 0xc42000c160, 0x0, 0x0)
	/usr/local/go/src/plugin/plugin.go:30 +0x35 fp=0xc420045f28 sp=0xc420045ef0
main.main()
	/data/main.go:39 +0xae fp=0xc420045f88 sp=0xc420045f28
runtime.main()
	/usr/local/go/src/runtime/proc.go:185 +0x20a fp=0xc420045fe0 sp=0xc420045f88
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420045fe8 sp=0xc420045fe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2197 +0x1
exit status 2

What did you expect to see?

Either the second call to Open is silently ignored and no code is loaded (as it happens if I call twice Open with the same path) or Open returns an error.

What did you see instead?

A panic.

Does this issue reproduce with the latest release (go1.7.5)?

Only on Go 1.8 (plugin is required)

System details

go version devel +9799622f09 Thu Feb 9 01:45:17 2017 +0000 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/campoy"
GORACE=""
GOROOT="/Users/campoy/src/golang.org/x/go"
GOTOOLDIR="/Users/campoy/src/golang.org/x/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/yt/3jw3ts594kd9w6t6dw7rp6y40043p6/T/go-build097698135=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version devel +9799622f09 Thu Feb 9 01:45:17 2017 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +9799622f09 Thu Feb 9 01:45:17 2017 +0000 X:framepointer
uname -v: Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.3
BuildVersion:	16D32
lldb --version: lldb-360.1.70

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions