Re: [go-nuts] Need help: Calling panic() is corrupting system stack

172 views
Skip to first unread message

Ian Lance Taylor

unread,
Apr 4, 2023, 6:06:10 PM4/4/23
to mariappan balraj, Kurtis Rader, golang-nuts
On Mon, Apr 3, 2023 at 9:26 PM mariappan balraj
<mariappa...@gmail.com> wrote:
>
> Hi Kurtis Rader,
>
> Thanks for your response. I am working on it. I will quickly share it. Before that one more update. I have commented the below two lines. Now from the core, I am able to see the correct stack trace.
>
> 326 func unwindm(restore *bool) {
> 327 if *restore {
> 328 // Restore sp saved by cgocallback during
> 329 // unwind of g's stack (see comment at top of file).
> 330 mp := acquirem()
> 331 //sched := &mp.g0.sched
> 332 //sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + alignUp(sys.MinFrameSize, sys.StackAlign)))
> 333
> 334 // Do the accounting that cgocall will not have a chance to do
> 335 // during an unwind.
> 336 //
> 337 // In the case where a Go call originates from C, ncgo is 0
> 338 // and there is no matching cgocall to end.
> 339 if mp.ncgo > 0 {
> 340 mp.incgo = false
> 341 mp.ncgo--
> 342 osPreemptExtExit(mp)
> 343 }
> 344
> 345 releasem(mp)
> 346 }
> 347 }



Just a note that in general we can't make that change, as it will
break the case where a Go function calls a C function calls a Go
function and that Go function calls panic.

Ian

robert engels

unread,
Apr 4, 2023, 6:30:44 PM4/4/23
to mariappan balraj, golang-nuts, Ian Lance Taylor
Unfortunately, I am on OSX - and Go doesn’t appear to generate a core dump on panic despite the GOTRACEBACK setting.

That being said, the stack-traces look ok to me. See attached.

test.out.txt

Kurtis Rader

unread,
Apr 4, 2023, 11:19:51 PM4/4/23
to robert engels, mariappan balraj, golang-nuts, Ian Lance Taylor
On Tue, Apr 4, 2023 at 3:30 PM robert engels <ren...@ix.netcom.com> wrote:
Unfortunately, I am on OSX - and Go doesn’t appear to generate a core dump on panic despite the GOTRACEBACK setting.

That being said, the stack-traces look ok to me. See attached.

Since I also use macOS (aka "OS X") I investigated why core dumps are not generated. The answer can be found in https://github.com/golang/go/issues/59446 that I just opened. The short answer is that on macOS on amd64 core dumps from Go programs are explicitly disallowed. On macOS on arm64 they should occur but generating them requires a code-signed Go binary. Something I don't have enough interest to verify. Also, presumably the same issue that affects Go core dumps on macOS amd64 also applies to macOS arm64. So even if you go to the trouble of code-signing a Go binary generating a core dump would not be practical on Apple Silicon.
 
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

mariappan balraj

unread,
Apr 4, 2023, 11:47:44 PM4/4/23
to Kurtis Rader, robert engels, golang-nuts, Ian Lance Taylor
Sorry. Forgot to share go environment.

root@soomohan:/home/soomohan/mbalraj/test_hb2# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/soomohan/mbalraj/GO/go1.20.2/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/soomohan/mbalraj/GO/go1.20.2/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3821222181=/tmp/go-build -gno-record-gcc"


mariappan balraj

unread,
Apr 5, 2023, 12:20:54 AM4/5/23
to Ian Lance Taylor, Kurtis Rader, golang-nuts
Hi Ian,

In my test case, I have tried, Go-->C-->Go->panic() only. 

Ian Lance Taylor

unread,
Apr 5, 2023, 4:53:08 PM4/5/23
to mariappan balraj, Kurtis Rader, golang-nuts
On Tue, Apr 4, 2023 at 9:20 PM mariappan balraj
<mariappa...@gmail.com> wrote:
>
> In my test case, I have tried, Go-->C-->Go->panic() only.

You can run a bunch of cgo tests by running "go test" in the directory
$GOROOT/misc/cgo/test.

Ian

mariappan balraj

unread,
Apr 6, 2023, 1:56:04 AM4/6/23
to Ian Lance Taylor, Kurtis Rader, golang-nuts
Hi Ian,

You are correct. The following test case is failing. I commented out the code to make sure whether my analysis is correct or not. Definitely, you people are experts. What could be the best fix for this issue? If you can help then that is really helpful.

=== RUN   TestCallbackPanicLoop
signal: segmentation fault
FAIL    misc/cgo/test   0.671s

Best Regards
Mariappan
Reply all
Reply to author
Forward
0 new messages