Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: crash when calling functions from plugins that have dots inside their names #22295

Closed
AndreyNevolin opened this issue Oct 16, 2017 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@AndreyNevolin
Copy link

AndreyNevolin commented Oct 16, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.1 linux/amd64

Does this issue reproduce with the latest release?

Yes, I'm using the latest release

What operating system and processor architecture are you using (go env)?

GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

I use a plugin whose name has dots inside. The program that uses this plugin crashes when a function from the plugin is called. The problem disappears if I rename the plugin (e.g. remove dots) and recompile everything.

To reproduce, one needs to do the following:

  1. create "plugin_error/plugin_error.go" with the following contents:
package main

import (
	"plugin"
)

func main() {
	plugin_handler, err := plugin.Open("plugin/p.l.u.g.i.n.so")

	if err != nil {
		panic("Cannot open plugin: " + err.Error())
	}

	plugin_entry_symb, err := plugin_handler.Lookup("Plugin_entry")

	if err != nil {
		panic("Cannot find symbol: " + err.Error())
	}

	plugin_entry := plugin_entry_symb.(func())

	plugin_entry()
}

  1. create "plugin_error/vendor/another_package/another_package.go" with the following contents:
package another_package

import "fmt"

func init() {
	fmt.Println("CAN YOU SEE THIS MESSAGE?")
}

func FormalFunction() {
	fmt.Println("Formal message")
}
  1. create "plugin_error/p.l.u.g.i.n/p.l.u.g.i.n.go" with the following contents:
package main

import (
	"another_package"
)

func Plugin_entry() {
	another_package.FormalFunction()
}
  1. go to "plugin_error/p.l.u.g.i.n/p.l.u.g.i.n.go" and run "go build -buildmode=plugin"
  2. create a directory called "plugin_error/plugin"
  3. copy the compiled plugin to this directory
  4. build "plugin_error" package
  5. ./plugin_error

What did you expect to see?

For the code above, I expect to see:

CAN YOU SEE THIS MESSAGE?
Formal message

What did you see instead?

A program crash

@AndreyNevolin
Copy link
Author

I forgot to mention one more issue with plugins of that kind.
When they are loaded, init() functions from imported packages (i.e. imported by the plugin) are not called. The provided reproducer demonstrates this issue also. The text "CAN YOU SEE THIS MESSAGE?" is not shown, while plugin.Open() successfully returns

@gbbr gbbr changed the title Go programs crash when call functions from plugins that have dots inside their names plugin: crash when calling functions that have dots inside their names Oct 16, 2017
@AndreyNevolin
Copy link
Author

@gbbr , new bug name is a little bit incorrect. It's not functions who have dots inside their names, but plugins. The problem is with plugin names.
Sorry for confusion.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 16, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 16, 2017
@gbbr gbbr changed the title plugin: crash when calling functions that have dots inside their names plugin: crash when calling functions from plugins that have dots inside their names Oct 16, 2017
@edaniels
Copy link
Contributor

edaniels commented Oct 17, 2017

Random finding: importing os in plugin_error/plugin_error.go eliminates the crash. Seems related to @gbbr mentioning that init does not called considering os/file.go initializes Stdout, Stderr, and Stdin in the package scope. Seems like the plugin is effectively linked to the runtime binary (an explanation of this would be nice).

EDIT: The init functions from the plugin are nowhere to be seen in the shared object upon running readelf -Ws p.l.u.g.i.n.so | grep init

@gopherbot
Copy link

Change https://golang.org/cl/72390 mentions this issue: cmd/link, plugin: always encode path

@AndreyNevolin
Copy link
Author

Awesome! Thank you for the quick response and timely fix!

@golang golang locked and limited conversation to collaborators Oct 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants