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

gccgo: arm64: programs built with the -static option crashed during runtime initialization #38742

Open
erifan opened this issue Apr 29, 2020 · 6 comments

Comments

@erifan
Copy link
Contributor

@erifan erifan commented Apr 29, 2020

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

$ 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.

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="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"

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

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 #37257. It may be related to precise stack scan, but I haven't figured out why it happened?
/cc @ianlancetaylor /cc @cherrymui /cc @thanm

@gopherbot gopherbot added this to the Gccgo milestone Apr 29, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 30, 2020

This doesn't look like a gccgo bug. Almost all the code involved here is in C. You might try writing a C function that calls _Unwind_Backtrace and see what happens if you link with -static.

Using -static does seem to work on amd64.

@ianlancetaylor ianlancetaylor changed the title gccgo: programs built with the -static option crashed during runtime initialization gccgo: arm64: programs built with the -static option crashed during runtime initialization Apr 30, 2020
@erifan
Copy link
Contributor Author

@erifan erifan commented Apr 30, 2020

I wrote a c program using _Unwind_Backtrace, and this error will also appear when compiling and running with the latest version of gcc built by myself. But using the installed version of gcc (apt-get install gcc-9) didn't crash. And yes the same operation will not go wrong on amd64. I think there may be two problems here:

  1. The latest gcc on arm64 may have a bug related to _Unwind_Backtrace.
  2. Gollvm may have some problems when dealing with gcc. Because even I compile gollvm with the installed version of gcc, it still crashes.
@erifan
Copy link
Contributor Author

@erifan erifan commented Apr 30, 2020

In addition, I'm using gold linker.

$ gold --version
GNU gold (GNU Binutils for Ubuntu 2.30) 1.15
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 30, 2020

I'm not seeing a lot of reason to think that this is a gccgo/GoLLVM problem at all. It sounds like the problem is elsewhere.

@erifan
Copy link
Contributor Author

@erifan erifan commented Apr 30, 2020

Yes, it should not be a problem of Gollvm/Gccgo, it may be a problem with the ld.gold linker, because no matter what compiler I use, as long as the ld.gold linker is used, the program will crash. And it won't crash with ld or lld linker. I don't know if there is any difference between gold and other linkers in handling of unwind_backtrace.

Gollvm's search for the gcc path is not completely correct, because it will not find the path according to the currently used gcc version, and gccgo will. I will send a patch to fix this issue.

@erifan
Copy link
Contributor Author

@erifan erifan commented Apr 30, 2020

This may related to this gold issue https://bugs.chromium.org/p/chromium/issues/detail?id=437106, with -Wl,--eh-frame-hdr, the issue disappears. I'll consider if we need to add this option for arm64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.