Join GitHub today
runtime: "fatal: morestack on g0" when messing with the stack #39411
What version of Go are you using (
Thanks for the interest!
The libretro library is loaded using dlopen:
The libretro library may also create its own threads using pthreads, I can see various mentions in the code but i am not sure if those code paths are actually used.
As evidence and to give a bit more details, here is the call stack right before the libretro libray coopts the thread (using gdb):
Thread 6 "worker" hit Breakpoint 1, co_switch (handle=0xa161b800) at libretro-common/libco/armeabi.c:100 100 cothread_t co_previous_handle = co_active(); (gdb) bt #0 co_switch (handle=0xa161b800) at libretro-common/libco/armeabi.c:100 #1 0x934fe064 in retro_run () at libretro/libretro.c:1503 #2 0x006c3778 in bridge_retro_run (f=0x934fdfbc ) at /home/pi/workspace/cloud-game/pkg/emulator/libretro/nanoarch/cfuncs.go:62 #3 0x006c3fc8 in _cgo_e181eea56bf5_Cfunc_bridge_retro_run (v=0x1456dbc) at cgo-gcc-prolog:166 #4 0x000a54e8 in runtime.asmcgocall () at /usr/local/go/src/runtime/asm_arm.s:607 #5 0x000a3898 in runtime.mcall () at /usr/local/go/src/runtime/asm_arm.s:285 #6 0x006c0b80 in crosscall_arm1 () at gcc_arm.S:30 #7 0x00000000 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?)
Here is the call stack right after the cooption happened for the first time:
Thread 6 "worker" hit Breakpoint 2, EmuThreadFunction () at libretro/libretro.c:464 464 log_cb(RETRO_LOG_DEBUG, CORE_NAME ": [EmuThread] M64CMD_EXECUTE\n"); (gdb) bt #0 EmuThreadFunction () at libretro/libretro.c:464 #1 0x93527468 in co_switch (handle=) at libretro-common/libco/armeabi.c:101 Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Here is the segmentation fault that happens intermittently:
fatal: morestack on g0 Thread 6 "worker" received signal SIGSEGV, Segmentation fault. runtime.abort () at /usr/local/go/src/runtime/asm_arm.s:794 794 MOVW (R0), R1 (gdb) bt #0 runtime.abort () at /usr/local/go/src/runtime/asm_arm.s:794 #1 0x00076440 in runtime.write (fd=, p=0x0, n=9654726) at /usr/local/go/src/runtime/time_nofake.go:30 #2 runtime.badmorestackg0 () at /usr/local/go/src/runtime/proc.go:438 #3 0x00077ec0 in runtime.startTheWorldWithSema (emitTraceEvent=false, ~r1=) at :1 Backtrace stopped: Cannot access memory at address 0xe
Also it does not happen immediately after the thread is coopted but, if it happens, it happens a few calls in when I am guessing the stack increases past some limit.
Let me know if you need more details!
I don't think the Go runtime will be happy with a C library coopting one of its OS threads. My guess is that both