Repository: go
Issue: runtime/traceback: segmentation violation failures from unwinding crash
Labels: NeedsInvestigation,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.21.3 linux/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/rest/.cache/go-build'
GOENV='/home/rest/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='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 -ffile-prefix-map=/tmp/go-build2287139495=/tmp/go-build -gno-record-gcc-switches'	
</pre></details>

### What did you do?
We build a Go application which also include some CGO requests and very frequently we see `SIGSEGV: segmentation violation` errors produced by an unwinding crash. Unfortunately, we are not able to reproduce the crash but the crashes occurred often without executing any specific request to produce this error. The crashes are happening frequently (more than 100 on a single day). We have checked the core dumps produced, but nothing there to indicate what causes the issue. Also, from core dumps, we see that there are no CGO requests during the time of the crash.

We see the following stacktrace
```
SIGSEGV: segmentation violation  
PC=0x46df85 m=22 sigcode=1	

goroutine 0 [idle]:	
runtime.(*unwinder).next(0x7fa986bfc060)	
	runtime/traceback.go:463 +0x105 fp=0x7fa986bfbeb0 sp=0x7fa986bfbe38 pc=0x46df85	
runtime.scanstack(0xc0013341a0, 0x100000081?)	
	runtime/mgcmark.go:802 +0x272 fp=0x7fa986bfc1e8 sp=0x7fa986bfbeb0 pc=0x42e392	
runtime.markroot.func1()	
	runtime/mgcmark.go:240 +0xb5 fp=0x7fa986bfc238 sp=0x7fa986bfc1e8 pc=0x42d215
runtime.markroot(0xc00007a140, 0x3fe, 0x1)		
	runtime/mgcmark.go:214 +0x1a8 fp=0x7fa986bfc2e0 sp=0x7fa986bfc238 pc=0x42cea8	
runtime.gcDrain(0xc00007a140, 0x7)	
	runtime/mgcmark.go:1069 +0x37d fp=0x7fa986bfc340 sp=0x7fa986bfc2e0 pc=0x42edfd	
runtime.gcBgMarkWorker.func2()	
	runtime/mgc.go:1385 +0x6f fp=0x7fa986bfc390 sp=0x7fa986bfc340 pc=0x42b52f		
traceback: unexpected SPWRITE function runtime.systemstack		
runtime.systemstack()	
	runtime/asm_amd64.s:509 +0x4a fp=0x7fa986bfc3a0 sp=0x7fa986bfc390 pc=0x47bc4a	
```
 
We also downgrade golang version to `go1.21.0 linux/amd64`, but we see the same behaviour (same crashes), with a bit different stacktrace now.

```
SIGSEGV: segmentation violation
PC=0x46dea5 m=23 sigcode=1	

goroutine 0 [idle]:	
runtime.(*unwinder).next(0x7f89011f3060)	
	runtime/traceback.go:453 +0x105 fp=0x7f89011f2eb0 sp=0x7f89011f2e38 pc=0x46dea5	
runtime.scanstack(0xc0031d44e0, 0x2a?)	
	runtime/mgcmark.go:802 +0x272 fp=0x7f89011f31e8 sp=0x7f89011f2eb0 pc=0x42e272		
runtime.markroot.func1()	
	runtime/mgcmark.go:240 +0xb5 fp=0x7f89011f3238 sp=0x7f89011f31e8 pc=0x42d0f5	
runtime.markroot(0xc00006e640, 0x1bb, 0x1)	
	runtime/mgcmark.go:214 +0x1a8 fp=0x7f89011f32e0 sp=0x7f89011f3238 pc=0x42cd88	
runtime.gcDrain(0xc00006e640, 0x3)	
	runtime/mgcmark.go:1069 +0x37d fp=0x7f89011f3340 sp=0x7f89011f32e0 pc=0x42ecdd	
runtime.gcBgMarkWorker.func2()	
	runtime/mgc.go:1366 +0xa5 fp=0x7f89011f3390 sp=0x7f89011f3340 pc=0x42b445	
```

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on go.dev/play is best.
-->



### What did you expect to see?
No crashes


### What did you see instead?
segmentation violation errors