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 · 3 comments
Open

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

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

Comments

@d1vyank
Copy link

@d1vyank 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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 9, 2017

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 9, 2017

@crawshaw

This comment has been minimized.

Copy link
Contributor

@crawshaw crawshaw commented Sep 10, 2017

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.