On Thu, Jun 09, 2022 at 02:14:07PM +0100, Daniel P. Berrangé wrote:
Setting GODEBUG=cgocheck=1 or GODEBUG=cgocheck=2 can sometimes
get more info.
Took me a while to work out that we are actually setting that already
(in ./run) which explains a couple of things: why I couldn't reproduce
the error using go build directly, and why things like
"GODEBUG=cgocheck=1 ../run go build" make no difference.
If you can get the test to core dump, then plain old GDB core
dump could also be useful - might identify which specific API
is being called, which can help restrict the size of the haystack
for code review.
Eventually careful reading of this page revealed how to do this:
https://pkg.go.dev/runtime
The results unfortunately don't seem very useful. The stack trace
appears to point to where the error was detected rather than where it
was caused, but I've copied it below anyway.
Also attached is the failure in the test suite if you turn *off*
cgocheck, maybe that is useful.
Rich.
$ GODEBUG=cgocheck=2,invalidptr=1 GOTRACEBACK=crash go test -count=1 -v
write of Go pointer 0x3f94026000 to non-Go memory 0x3fbfd6fb20
fatal error: Go pointer stored into non-Go memory
runtime stack:
runtime.dopanic_m
../../../libgo/go/runtime/panic.go:1211
runtime.fatalthrow
../../../libgo/go/runtime/panic.go:1071
runtime.throw
../../../libgo/go/runtime/panic.go:1042
runtime.cgoCheckWriteBarrier..func1
../../../libgo/go/runtime/cgocheck.go:55
runtime.systemstack..func1
../../../libgo/go/runtime/stubs.go:63
runtime_mstart
../../../libgo/runtime/proc.c:593
goroutine 1 [running, locked to thread]:
runtime.mcall
../../../libgo/runtime/proc.c:343
runtime.systemstack
../../../libgo/go/runtime/stubs.go:66
runtime.cgoCheckWriteBarrier
../../../libgo/go/runtime/cgocheck.go:53
runtime.wbBufFlush
../../../libgo/go/runtime/mwbbuf.go:196
runtime.gcWriteBarrier
../../../libgo/go/runtime/mgc_gccgo.go:168
runtime.main
../../../libgo/go/runtime/proc.go:209
Aborted (core dumped)
$ coredumpctl gdb
PID: 191012 (go)
UID: 1001 (rjones)
GID: 1001 (rjones)
Signal: 6 (ABRT)
Timestamp: Thu 2022-06-09 10:04:10 EDT (1min 24s ago)
Command Line: go test -count=1 -v
Executable: /usr/bin/go.gcc
Control Group: /user.slice/user-1001.slice/session-11.scope
Unit: session-11.scope
Slice: user-1001.slice
Session: 11
Owner UID: 1001 (rjones)
Boot ID: c2a10a42ad324704a32e04b47621d3a9
Machine ID: 1640aa86edd8444fb3261e75d4390014
Hostname:
nufive.home.annexia.org
Storage:
/var/lib/systemd/coredump/core.go.1001.c2a10a42ad324704a32e04b47621d3a9.191012.1654783450000000.zst
Message: Process 191012 (go) of user 1001 dumped core.
Stack trace of thread 191012:
#0 0x0000003fbe65b084 raise (libc.so.6 + 0x33084)
#1 0x0000003fbf524cca runtime.dieFromSignal (libgo.so.16 + 0xd49cca)
#2 0x0000003fbf542bdc runtime.sigfwdgo (libgo.so.16 + 0xd67bdc)
#3 0x0000003fbfdbb800 n/a (linux-vdso.so.1 + 0x800)
GNU gdb (GDB) Fedora 10.2-4.0.riscv64.fc33
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "riscv64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<
https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<
http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/go.gcc...
[New LWP 191012]
[New LWP 191028]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/lp64d/libthread_db.so.1".
Core was generated by `go test -count=1 -v'.
Program terminated with signal SIGABRT, Aborted.
#0 0x0000003fbe65b084 in raise () from /lib64/lp64d/libc.so.6
Missing separate debuginfos, use: dnf debuginfo-install gcc-go-10.3.1-1.fc33.riscv64
--Type <RET> for more, q to quit, c to continue without paging--
[Current thread is 1 (Thread 0x3fbe5f5630 (LWP 191012))]
(gdb) t a a bt
Thread 2 (Thread 0x3f99563150 (LWP 191028)):
#0 0x0000003fbe6cda60 in syscall () from /lib64/lp64d/libc.so.6
#1 0x0000003fbf246f88 in __go_syscall6 (flag=<optimized out>, a1=<optimized
out>, a2=<optimized out>, a3=<optimized out>, a4=<optimized out>,
a5=<optimized out>, a6=<optimized out>) at
../../../libgo/runtime/go-varargs.c:109
#2 0x0000003fbf51f05c in runtime.futex (val3=<optimized out>, addr2=<optimized
out>, ts=<optimized out>, val=<optimized out>, op=<optimized out>,
addr=<optimized out>) at ../../../libgo/go/runtime/os_linux.go:17
#3 runtime.futexsleep (addr=0x3fbfd6e878 <runtime.sched+240>, val=<optimized
out>, ns=<optimized out>) at ../../../libgo/go/runtime/os_linux.go:59
#4 0x0000003fbf52d70c in runtime.notetsleep_internal (n=n@entry=0x3fbfd6e878
<runtime.sched+240>, ns=ns@entry=60000000000) at
../../../libgo/go/runtime/lock_futex.go:204
#5 0x0000003fbf52d8ce in runtime.notetsleep (n=n@entry=0x3fbfd6e878
<runtime.sched+240>, ns=60000000000) at ../../../libgo/go/runtime/lock_futex.go:227
#6 0x0000003fbf54de9c in runtime.sysmon () at ../../../libgo/go/runtime/proc.go:4210
#7 0x0000003fbf5501a6 in runtime.mstart1 () at ../../../libgo/go/runtime/proc.go:1074
#8 0x0000003fbf24779e in runtime_mstart (arg=<optimized out>) at
../../../libgo/runtime/proc.c:611
#9 0x0000003fbe613606 in start_thread () from /lib64/lp64d/libpthread.so.0
#10 0x0000003fbe6d028e in __thread_start () from /lib64/lp64d/libc.so.6
Thread 1 (Thread 0x3fbe5f5630 (LWP 191012)):
#0 0x0000003fbe65b084 in raise () from /lib64/lp64d/libc.so.6
#1 0x0000003fbf524cca in runtime.dieFromSignal (sig=sig@entry=6) at
../../../libgo/go/runtime/signal_unix.go:668
#2 0x0000003fbf542bdc in runtime.sigfwdgo (ctx=0x3f99973c40, info=0x3f99973bc0,
sig=<optimized out>) at ../../../libgo/go/runtime/signal_unix.go:883
#3 runtime.sigtrampgo (sig=<optimized out>, info=0x3f99973bc0, ctx=0x3f99973c40) at
../../../libgo/go/runtime/signal_unix.go:392
#4 <signal handler called>
#5 0x0000003fbe65b084 in raise () from /lib64/lp64d/libc.so.6
#6 0x0000003fbf524cca in runtime.dieFromSignal (sig=sig@entry=6) at
../../../libgo/go/runtime/signal_unix.go:668
#7 0x0000003fbf524d42 in runtime.crash () at
../../../libgo/go/runtime/signal_unix.go:763
#8 0x0000003fbf529132 in runtime.fatalthrow () at
../../../libgo/go/runtime/panic.go:1072
#9 runtime.throw (s=...) at ../../../libgo/go/runtime/panic.go:1042
#10 0x0000003fbf5291c4 in runtime.cgoCheckWriteBarrier..func1 () at
../../../libgo/go/runtime/cgocheck.go:55
#11 0x0000003fbf51ff3e in runtime.systemstack..func1 (origg=0x3f94000a80) at
../../../libgo/go/runtime/stubs.go:63
#12 0x0000003fbf24776e in runtime_mstart (arg=<optimized out>) at
../../../libgo/runtime/proc.c:593
#13 0x0000000000035abe in main (argc=<optimized out>, argv=<optimized out>) at
../../../libgo/runtime/go-main.c:58
#14 0x0000003fbe64b956 in __libc_start_main () from /lib64/lp64d/libc.so.6
#15 0x0000000000035afc in _start ()
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins
https://gitlab.com/nbdkit/nbdkit