golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.9k stars 17.65k forks source link

runtime: crash when cross compiled for raspberry pi #30078

Closed nandra closed 5 years ago

nandra commented 5 years ago

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

$ go version
1.11.2

Does this issue reproduce with the latest release?

Yes

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

x86_64 cross compiled for arm

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build099564701=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cross compile mender client for raspberrypi by using:

env CGO_ENABLED=1 \
    CC=arm-linux-gnueabihf-gcc \
    GOOS=linux \
    GOARM=6 \
    GOARCH=arm make build

when run image on rpi0w we get this (in gdb):

Program received signal SIGSEGV, Segmentation fault.
0x00062540 in runtime.typesEqual (
   seen=map[runtime._typePair]struct {}<error reading variable: Cannot access memory at address 0x3ed>, t=0x3e8, v=0xd, ~r3=<optimized out>)
   at /usr/local/go/src/runtime/type.go:623
623                     for i := 0; i < len(tout); i++ {

What did you expect to see?

mender to run raspberrypi

What did you see instead?

Segmentation fault

ianlancetaylor commented 5 years ago

There is no Go version 1.12.1 yet, I assume you mean 1.11.1.

Is this crash reproducible? How often does it happen?

Can you share a program that reproduces the problem?

The error looks like memory corruption. The description of your build suggests that your program includes C code. How sure are you that that is not introducing memory corruption somewhere?

nandra commented 5 years ago

Sorry go version is 1.11.2 (updated original comment). Issue happens every time I run binary.

Program source is mender client: https://github.com/mendersoftware/mender

Mender build for x86 or other arm board like orangepi works perfectly fine.

nandra commented 5 years ago

Turns out that wrong toolchain was used. Linaro tpplchains support armv7+ but raspberrypi0w is armv6 architecture. When used toochain from raspberrypi everything works. Sorry for noise. Closing.

ianlancetaylor commented 5 years ago

Thanks for following up.