Repository: go
Issue: gccgo: arm64: programs built with the -static option crashed during runtime initialization
Labels: NeedsInvestigation,arch-arm64

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.14.2 gccgo (GCC) 10.0.1 20200421 (experimental) linux/arm64

$ gcc --version
gcc (GCC) 10.0.1 20200421 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++ (GCC) 10.0.1 20200421 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

</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="arm64"
GOBIN=""
GOCACHE="/home/hostname/.cache/go-build"
GOENV="/home/hostname/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/hostname/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/hostname/gccbuild/install"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/hostname/gccbuild/install/libexec/gcc/aarch64-unknown-linux-gnu/10.0.1"
GCCGO="/home/hostname/gccbuild/install/bin/gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build614590846=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

</pre></details>

### What did you do?
$ cat hello.go
```
package main

import (
        "fmt"
)

func main() {
        fmt.Println("hello")
}
```

go build -gccgoflags="-static -g -v" -x -a hello.go

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->



### What did you expect to see?
The program outputs "hello"


### What did you see instead?

```
Aborted (core dumped)

GDB debugging information:
(gdb) r
Starting program: /home/erifan01/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Program received signal SIGABRT, Aborted.
raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x000000000050c4d4 in abort ()
#2  0x00000000005048ec in uw_init_context_1 (context=context@entry=0xfffffffe8f70,
    outer_cfa=outer_cfa@entry=0xfffffffe99b0, outer_ra=0x4df204 <runtime.probestackmaps+36>)
    at ../../../../gcc/libgcc/unwind-dw2.c:1600
#3  0x0000000000505270 in _Unwind_Backtrace (trace=trace@entry=0x4de780 <probestackmaps_callback>,
    trace_argument=trace_argument@entry=0x0) at ../../../../gcc/libgcc/unwind.inc:295
#4  0x00000000004df204 in runtime.probestackmaps () at ../../../../gcc/libgo/runtime/go-unwind.c:868
#5  0x0000000000486708 in runtime.schedinit () at ../../../../gcc/libgo/go/runtime/proc.go:548
#6  0x0000000000400520 in main (argc=<optimized out>, argv=<optimized out>)
    at ../../../../gcc/libgo/runtime/go-main.c:56
#7  0x0000000000507574 in __libc_start_main ()
#8  0x00000000004005a0 in _start ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
```

The crash happened here https://github.com/gcc-mirror/gcc/blob/df30ab70690d6088f367e74757f0b5dd6a2587e5/libgcc/unwind-dw2.c#L1593
I found this issue while looking at the issue https://github.com/golang/go/issues/37257. It may be related to precise stack scan, but I haven't figured out why it happened?
/cc @ianlancetaylor  /cc @cherrymui /cc @thanm