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

Calling panic() is corrupting system stack #59519

Closed
MariappanBalraj opened this issue Apr 10, 2023 · 2 comments
Closed

Calling panic() is corrupting system stack #59519

MariappanBalraj opened this issue Apr 10, 2023 · 2 comments

Comments

@MariappanBalraj
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.20.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ 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.3/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/soomohan/mbalraj/GO/go1.20.3/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.3"
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-build2259421427=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Test case can be found in the following github.
https://github.com/MariappanBalraj/test_cgo_panic

Command used to build: CGO_CFLAGS="-g" go build -gcflags=all="-N -l"
ulimit -c unlimited
echo "core" > /proc/sys/kernel/core_pattern
export GOTRACEBACK=crash

When the complied go program is run, core file is getting generated because of calling panic(). The following code is line is causing the system stack corruption. Because of this, I am not seeing the complete 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)))

What did you expect to see?

0 0x0000000000460ea1 in runtime.raise
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/sys_linux_amd64.s:154
1 0x0000000000449845 in runtime.dieFromSignal
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:879
2 0x0000000000449e25 in runtime.sigfwdgo
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:1092
3 0x00000000004487a7 in runtime.sigtrampgo
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:432
4 0x0000000000461186 in runtime.sigtramp
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/sys_linux_amd64.s:354
5 0x00007f686b787520 in ???
at ?:-1
6 0x0000000000449a58 in runtime.crash
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/signal_unix.go:971
7 0x0000000000434d85 in runtime.fatalpanic
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/panic.go:1168
8 0x00000000004344cc in runtime.gopanic
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/panic.go:987
9 0x00000000004642a7 in main.Test4
at ./export.go:8
10 0x000000000046431c in _cgoexp_209e16473f08_Test4
at _cgo_gotypes.go:61
11 0x000000000040535b in runtime.cgocallbackg1
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:315
12 0x0000000000405079 in runtime.cgocallbackg
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:234
13 0x0000000000461b0f in runtime.cgocallbackg
at :1
14 0x000000000045f3d4 in runtime.cgocallback
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:998
15 0x00000000004641bd in crosscall2
15 0x00000000004641bd in crosscall2
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgo/asm_amd64.s:30
16 0x0000000000464386 in C.Test4
at /tmp/go-build/_cgo_export.c:33
17 0x0000000000464432 in C.test1
at ./hello.go:10
18 0x000000000046444d in C.test2
at ./hello.go:15
19 0x0000000000464468 in C.test3
at ./hello.go:20
20 0x00000000004644a7 in C._cgo_209e16473f08_Cfunc_test3
at /tmp/go-build/cgo-gcc-prolog:49
21 0x000000000045f2c4 in runtime.asmcgocall
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:848
22 0x000000000046448a in C._cgo_209e16473f08_Cfunc_test3
at /tmp/go-build/cgo-gcc-prolog:44
23 0x0000000000404f0a in runtime.cgocall
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/cgocall.go:167
24 0x0000000000464245 in main._Cfunc_test3
at _cgo_gotypes.go:39
25 0x00000000004642d7 in main.main
at ./hello.go:34
26 0x0000000000437053 in runtime.main
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/proc.go:250
27 0x000000000045f5c1 in runtime.goexit
at /home/soomohan/mbalraj/GO/go1202/go/src/runtime/asm_amd64.s:1598

What did you see instead?

0 0x0000000000460ec1 in runtime.raise
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/sys_linux_amd64.s:154
1 0x0000000000449865 in runtime.dieFromSignal
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/signal_unix.go:879
2 0x0000000000449e45 in runtime.sigfwdgo
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/signal_unix.go:1092
3 0x00000000004487c7 in runtime.sigtrampgo
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/signal_unix.go:432
4 0x00000000004611a6 in runtime.sigtramp
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/sys_linux_amd64.s:354
5 0x00007ff08b3ae520 in ???
at ?:-1
6 0x0000000000449a78 in runtime.crash
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/signal_unix.go:971
7 0x0000000000434da5 in runtime.fatalpanic
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/panic.go:1168
8 0x00000000004344ec in runtime.gopanic
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/panic.go:987
9 0x00000000004642c7 in main.Test4
at ./export.go:8
10 0x000000000046433c in _cgoexp_209e16473f08_Test4
at _cgo_gotypes.go:61
11 0x000000000040535b in runtime.cgocallbackg1
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/cgocall.go:315
12 0x0000000000405079 in runtime.cgocallbackg
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/cgocall.go:234
13 0x0000000000461b2f in runtime.cgocallbackg
at :1
14 0x000000000045f3f4 in runtime.cgocallback
at /home/soomohan/mbalraj/GO/go1.20.3/go/src/runtime/asm_amd64.s:998
15 0x0000000000000001 in ???
15 0x0000000000000001 in ???
at ?:-1
16 0x000000c00003e000 in ???
at ?:-1
error: error while reading spliced memory at 0x8: EOF
(truncated)

@cherrymui
Copy link
Member

As you already have extensive discussions about stack unwinding with stack switches in #57698, and as you see that it is a difficult task, I don't think it is necessary to have a separate issue. Although there is a difference in detail in this case, it is probably still better to have the discussion in one place. Thanks.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2023
@MariappanBalraj
Copy link
Author

MariappanBalraj commented Apr 11, 2023 via email

@golang golang locked and limited conversation to collaborators Apr 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants