go: plugin: linker error when one plugin tries to open another plugin

There is a problem that has been closed, but did not reply after asking. #20312

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

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/workspace/go"
GORACE=""
GOROOT="/home/nzlov/program/go"
GOTOOLDIR="/home/nzlov/program/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build294433604=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

DEMO

make

What did you expect to see?

9

What did you see instead?

runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Are there any known workarounds for this until Go 1.10 is released?

Oops, sorry for missing this @nzlov. I’ll look into it.

It does not appear to be related to the special handling for plugin.Open in the linker. Instead, the fact that plugin.Open calls runtime.plugin_lastmoduleinit brings extra symbols into the plugin that cause the confusion. Stubbing out the implementation of plugin_lastmoduleinit lets the program build.

Sorry for the confusion. This is a bug when a plugin calls plugin.Open. Simple test case:

package main

import "plugin"

func F() {
	plugin.Open("x.so")
}

func main() {}

Compiling this with go build -buildmode=plugin produces

# command-line-arguments
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

Removing the call to plugin.Open permits it to build, even if “plugin” is still imported.