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: plugin.Open() segfault with statically linked binaries #21822

Open
d1vyank opened this issue Sep 9, 2017 · 4 comments
Open

plugin: plugin.Open() segfault with statically linked binaries #21822

d1vyank opened this issue Sep 9, 2017 · 4 comments
Milestone

Comments

@d1vyank
Copy link

d1vyank commented Sep 9, 2017

What version of Go are you using (go version)?
go version go1.9 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="/opt/gopath"
GORACE=""
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build683959130=/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?
Compiled the simple plugin example described in the plugin docs with the -static flag
go run -ldflags '-extldflags "-static"' main.go

What did you expect to see?
The same output as building without the -static flag:
go run main.go
Hello, number 7

What did you see instead?
Segfault in cgo runtime:

go run -ldflags '-extldflags "-static"' main.go
# command-line-arguments
/tmp/go-link-658275617/000000.o: In function `pluginOpen':
/tmp/workdir/go/src/plugin/plugin_dlopen.go:19: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw(0x52c324, 0x2a)
/opt/go/src/runtime/panic.go:605 +0x95
runtime.sigpanic()
/opt/go/src/runtime/signal_unix.go:351 +0x2b8

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x459260, 0xc420053c18, 0xc42000e010)
/opt/go/src/runtime/cgocall.go:132 +0xe4 fp=0xc420053be8 sp=0xc420053ba8 pc=0x401f84
plugin._Cfunc_pluginOpen(0x25cdfe0, 0xc42000e010, 0x0)
plugin/_obj/_cgo_gotypes.go:98 +0x4e fp=0xc420053c18 sp=0xc420053be8 pc=0x45758e
plugin.open.func3(0x25cdfe0, 0xc42000e010, 0xc42001c0a0)
/tmp/workdir/go/src/plugin/plugin_dlopen.go:102 +0xae fp=0xc420053c58 sp=0xc420053c18 pc=0x4589ae
plugin.open(0x52ce1a, 0x4c, 0x0, 0x0, 0x0)
/tmp/workdir/go/src/plugin/plugin_dlopen.go:102 +0x1d1 fp=0xc420053e88 sp=0xc420053c58 pc=0x457c31
plugin.Open(0x52ce1a, 0x4c, 0xc42007a000, 0xe, 0xc420012000)
/opt/go/src/plugin/plugin.go:31 +0x35 fp=0xc420053ec0 sp=0xc420053e88 pc=0x4570c5
main.loadPlugins()

@ianlancetaylor
Copy link
Contributor

I would not count on this ever working. If someone wants to figure out how to fix it, great, but otherwise it seems both difficult and low priority.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Sep 9, 2017
@ianlancetaylor
Copy link
Contributor

CC @crawshaw

@crawshaw
Copy link
Member

As Ian says, difficult and low priority. Unless an intrepid sort with the need and tenacity shows up to implement this, it won't happen.

I suppose we could produce a link-time error easily enough if both the -static flag and the plugin.Open symbol are present. The current run time error seems quite clear though.

ghost pushed a commit to hyperledger/fabric that referenced this issue Sep 29, 2017
Building binaries dynamically fixes:
- PKCS11 integration issues - FAB-6161
- It also enables the use of Go plugins in FAB-6159
  This is required because Go plugins are not
  compatible with statically linked binaries
  (see golang/go#21822 )

NOTE: Using the dynamic build flag requires a custom image.
Currently, hyperledger/fabric-baseos image does not
include the C libraries required by the peer and orderer
for dynamic linking

Change-Id: Ifddcc563e3bca9e473e6e81f4c10c84da1a6cf6f
Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
@wgerlach
Copy link

wgerlach commented Sep 9, 2020

It would be nice if the documentation https://golang.org/pkg/plugin/ were more clear about the limitations. Also see issues raised in this thread: https://www.reddit.com/r/golang/comments/b6h8qq/is_anyone_actually_using_go_plugins/ejkxd2k/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants