运行时错误:"致命:从意外的goroutine中调用systemstack"(在armv6架构上)

7fhtutme  于 4个月前  发布在  Go
关注(0)|答案(6)|浏览(41)

注意:我正在使用karalabe的xgo为ARM6进行编译

你使用的Go版本是什么( go version )?

$ go version
go version go1.12.17 linux/amd64

这个问题在最新版本中是否重现?

是的,1.12.17和1.14.0似乎都受影响。

你做了什么?

使用github.com/mattn/go-sqlite3进行交叉编译应用程序,仅将其导入armv6,并启用CGO_ENABLED=1
代码:

package main

import _ "github.com/mattn/go-sqlite3"

func main() {
	println("Hello")
}

更长的故事是,我的主机操作系统是macOS,因此我默认使用karalabe/go-1.12.12作为目标。然而,我也在go-1.12.17( cd docker/go-1.12.17 && docker build -t karalabe/xgo-1.12.17 )和最新版本的1.14.0( cd docker/go-1.14.0 && docker build -t karalabe/xgo-1.14.0 )上进行了测试,但没有区别。
我能在三次情况下遇到段错误:

  1. 不使用gomod的代码,构建可执行文件的输出将是Segmentation fault
  2. 使用gomod(仅go get github.com/mattn/go-sqlite3作为包)的代码,可执行文件的输出将是Segmentation fault
  3. 使用gomod(仅go get github.com/mattn/go-sqlite3@v1.11.0作为包)的代码,可执行文件的输出将是fatal: systemstack called from unexpected goroutineSegmentation fault

构建

测试环境

树莓派Zero(非W型)。由于没有互联网,通过交叉编译进行构建。

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 997.08
Features	: half thumb fastmult vfp edsp java tls
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2835
Revision	: 900093
Serial		: 0000000088a33a5e

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.98+ #1200 Tue Feb 12 20:11:02 GMT 2019 armv6l GNU/Linux

不使用gomod

构建代码:

$ mkdir diamondo25 && cd diamondo25
# write the main.go file from the code above
$ nano main.go
$ docker run -it -v $PWD:/code/ -w /code/ --entrypoint bash karalabe/xgo-1.12.17  
root@91db62d6dde7:/code# export CC=arm-linux-gnueabihf-gcc-5 GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=1

root@91db62d6dde7:/code# CGO_CFLAGS='-march=armv6' CGO_CXXFLAGS='-march=armv6' go install std

root@91db62d6dde7:/code# go get github.com/mattn/go-sqlite3

root@91db62d6dde7:/code# go build -o hello .

root@91db62d6dde7:/code# exit

现在在'diamondo25'文件夹中有一个新的hello可执行文件。
将二进制文件复制到一个armv6l盒子上。运行可执行文件立即报告SEGFAULT:

pi@raspberrypi:~ $ ./hello
Segmentation fault

pi@raspberrypi:~ $ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=c60aae380bfbd3f2292bfa0a5718ecaece5cb328, not stripped

GDB帮助不大:

pi@raspberrypi:~ $ gdb hello
GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello...done.
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/pi/hello.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) r
Starting program: /home/pi/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
runtime.tracebackHexdump (stk=..., frame=0xbefffeb8, bad=3204447949) at /usr/local/go/src/runtime/traceback.go:992
992	/usr/local/go/src/runtime/traceback.go: No such file or directory.
(gdb) bt
#0  runtime.tracebackHexdump (stk=..., frame=0xbefffeb8, bad=3204447949) at /usr/local/go/src/runtime/traceback.go:992
#1  0x00000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

使用gomod

$ mkdir diamondo25_gomod && cd diamondo25_gomod
# write the main.go file from the code above
$ nano main.go
$ docker run -it -v $PWD:/code/ -w /code/ --entrypoint bash karalabe/xgo-1.12.17
root@e35c28fde210:/code# go mod init hello
go: creating new go.mod: module hello

root@e35c28fde210:/code# go get github.com/mattn/go-sqlite3 
go: finding github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: downloading github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: extracting github.com/mattn/go-sqlite3 v2.0.3+incompatible

root@e35c28fde210:/code# export CC=arm-linux-gnueabihf-gcc-5 GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=1

root@e35c28fde210:/code# CGO_CFLAGS='-march=armv6' CGO_CXXFLAGS='-march=armv6' go install std

root@e35c28fde210:/code# go build -o hello .
# Keep open for next variant

现在在'diamondo25_gomod'文件夹中有一个新的hello可执行文件。与之前的无gomod变体相比,此可执行文件的构建时间更长。
运行此代码也报告Segmentation fault

使用gomod with go-sqlite3@v1.11.0

使用Docker容器shell,将go-sqlite3模块更改为v1.11.0

root@e35c28fde210:/code# go get github.com/mattn/go-sqlite3@v1.11.0
go: finding github.com/mattn/go-sqlite3 v1.11.0
go: downloading github.com/mattn/go-sqlite3 v1.11.0
go: extracting github.com/mattn/go-sqlite3 v1.11.0

root@c1619b650cc7:/code# go build -o hello .

现在,复制并运行此可执行文件将抛出fatal: systemstack called from unexpected goroutineSegmentation fault错误:

pi@raspberrypi:~ $ ./hello
fatal: systemstack called from unexpected goroutineSegmentation fault

GDB这次报告了不同的信息:

pi@raspberrypi:~ $ gdb hello
GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello...
done.
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/pi/hello.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) r
Starting program: /home/pi/hello
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
fatal: systemstack called from unexpected goroutine
Program received signal SIGSEGV, Segmentation fault.
runtime.abort () at /usr/local/go/src/runtime/asm_arm.s:801
801	/usr/local/go/src/runtime/asm_arm.s: No such file or directory.
(gdb) bt
#0  runtime.abort () at /usr/local/go/src/runtime/asm_arm.s:801
#1  0x00063a48 in runtime.badsystemstack () at /usr/local/go/src/runtime/stubs.go:62
#2  0x00049748 in runtime.throw (s=...) at /usr/local/go/src/runtime/panic.go:610
#3  0x00000012 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

它不清楚实际崩溃的位置,因为它从未报告堆栈。我认为这导致了致命异常。

yyyllmsg

yyyllmsg1#

构建日志(v1.11库)

root@c1619b650cc7:/code# go clean -cache -modcache  -r
root@c1619b650cc7:/code# go get github.com/mattn/go-sqlite3@v1.11.0
go: finding github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: finding github.com/mattn/go-sqlite3 v1.11.0
go: downloading github.com/mattn/go-sqlite3 v1.11.0
go: extracting github.com/mattn/go-sqlite3 v1.11.0
root@c1619b650cc7:/code# go clean -cache -modcache  -r
root@c1619b650cc7:/code# go build -v -x -o hello . &> buildlog_v1.11.txt

buildlog_v1.11.txt

ruoxqz4g

ruoxqz4g2#

Buildlog with latest (v2.0.3+incompatible) library

root@c1619b650cc7:/code# go clean -cache -modcache  -r
root@c1619b650cc7:/code# go get github.com/mattn/go-sqlite3        
go: finding github.com/mattn/go-sqlite3 v1.11.0
go: finding github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: downloading github.com/mattn/go-sqlite3 v2.0.3+incompatible
go: extracting github.com/mattn/go-sqlite3 v2.0.3+incompatible
root@c1619b650cc7:/code# go clean -cache -modcache  -r
root@c1619b650cc7:/code# go build -v -x -o hello . &> buildlog_v2.0.3.txt

buildlog_v2.0.3.txt

erhoui1w

erhoui1w4#

我已经准备好了电缆来下载软件包等。现在正在安装sqlite软件包,所以明年再见啦。(这真的需要时间,因为它是在一个单核上编译的)

eyh26e7m

eyh26e7m5#

当我直接在树莓派上构建时,它可以正常工作。

[buildlog_v2.0.3.txt](https://github.com/golang/go/files/4509955/buildlog_v2.0.3.txt)

total 9400
4 drwxr-xr-x 2 pi pi 4096 Apr 21 13:33 .
4 drwxr-xr-x 8 pi pi 4096 Apr 21 12:56 ..
4 -rw-r--r-- 1 pi pi 28 Apr 21 13:34 buildlog_v2.0.3.txt
4692 -rwxr-xr-x 1 pi pi 4800652 Apr 21 13:34 hello
4 -rw-r--r-- 1 pi pi 89 Apr 21 12:45 main.go
pi@raspberrypi:~/diamondo25 $ go env
GO111MODULE=""
GOARCH="arm"
GOBIN=""
GOCACHE="/home/pi/.cache/go-build"
GOENV="/home/pi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm"
GCCGO="gccgo"
GOARM="6"
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 -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build150874878=/tmp/go-build -gno-record-gcc-switches"

pi@raspberrypi:~/diamondo25 $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 6.3.0-18+rpi1+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)

628mspwn

628mspwn6#

xgo docker镜像运行以下版本的gcc:

root@4b1de367ed35:/code# arm-linux-gnueabihf-gcc-5 -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc-5
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-armhf-cross --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-armhf-cross --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libgcj --enable-objc-gc --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4)

相关问题