Fatal error when running a cgo program

This program is willing to bind a c library with go

fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x7fbb8490334c]

runtime stack:
runtime.throw(0x591320, 0x2a)
	/usr/lib/go/src/runtime/panic.go:530 +0x90
	/usr/lib/go/src/runtime/sigpanic_unix.go:12 +0x5a

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4eed60, 0xc820041b88, 0x0)
	/usr/lib/go/src/runtime/cgocall.go:123 +0x11b fp=0xc820041b20 sp=0xc820041af0
github.com/songtianyi/go-mxnet-predictor._C2func_MXPredCreate(0xc820484000, 0xc8204e0000, 0x10f32ece2, 0x100000000, 0x7fbb640008c0, 0xc82000a230, 0xc82000a3d0, 0x0, 0x0, 0x0, ...)
	github.com/songtianyi/go-mxnet-predictor/_obj/_cgo_gotypes.go:67 +0x55 fp=0xc820041b88 sp=0xc820041b20
github.com/songtianyi/go-mxnet-predictor.CreatePredictor(0xc820484000, 0x5b1ad, 0x5b3ad, 0xc8204e0000, 0xf32ece2, 0xf32eee2, 0x1, 0x0, 0xc820041f20, 0x1, ...)
	/root/golang/own/src/github.com/songtianyi/go-mxnet-predictor/predict.go:58 +0x7ac fp=0xc820041d70 sp=0xc820041b88
	/root/golang/own/src/github.com/songtianyi/go-mxnet-predictor/examples/predict.go:49 +0x657 fp=0xc820041f50 sp=0xc820041d70
	/usr/lib/go/src/runtime/proc.go:188 +0x2b0 fp=0xc820041fa0 sp=0xc820041f50
	/usr/lib/go/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc820041fa8 sp=0xc820041fa0

goroutine 17 [syscall, locked to thread]:
	/usr/lib/go/src/runtime/asm_amd64.s:1998 +0x1

Either you passed a nil pointer to your c code or it hit one during execution.

Shouldn’t report a nil pointer dereference error for the case you said?

It looks like the code is crashing in cgo, so you get what C gives you, a SIGSEGV

It looks like you’re using a version of Go provided by your operating system, they are almost always out of date. If you haven’t already, upgraded to Go 1.7.4 or 1.8beta2 and try again.

The most right way to solve this problem.

  • Add following env to ~/.bashrc
export GOTRACEBACK=crash
  • make it work
source ~/.bashrc
  • build your c share library with debug option
  • build your go program
  • run your go program to produce a core dump file
  • run following command
gdb $go-program $corefile
  • run bt in gdb, you will see the line of code that caused the panic

Excellent advice.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.