golang/go

runtime: ARM uClinux crash with -buildmode=c-archive

Open

#31,378 opened on Apr 10, 2019

View on GitHub
 (5 comments) (1 reaction) (0 assignees)Go (19,008 forks)batch import
NeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Please answer these questions before submitting your issue. Thanks!

What did you do?

main.go package main /* #include <stdio.h> #include <stdlib.h> #include <stdint.h> */ import "C"

//export TestAdd func TestAdd(a C.int32_t, b C.int32_t) C.int32_t { return a + b }

func main() {}

build: CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=5 CC=arm-hisiv500-linux-uclibcgnueabi-gcc CXX=arm-hisiv500-linux-uclibcgnueabi-g++ go build -buildmode=c-archive

output dlltest.a

test.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdint.h> #include <string.h> #include <errno.h> #include <inttypes.h>

extern "C" { int32_t TestAdd(int32_t a, int32_t b); }

int main(int argc, char* argv[]) { int ret = TestAdd(10, 11); printf("TestAdd, ret=%d", ret); }

build: export CC=arm-hisiv500-linux-uclibcgnueabi-gcc export CXX=arm-hisiv500-linux-uclibcgnueabi-g++ $CXX -g test.c -o test dlltest.a -lpthread

output test exe file. file test test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped

copy test to ARM board, run it.

What did you expect to see?

output TestAdd, ret=21

What did you see instead?

Segmentation fault

System details

gdb debug output Program received signal SIGSEGV, Segmentation fault. [Switching to LWP 427] runtime.sysargs (argc=0, argv=0x0) at /usr/local/go-linux-arm-bootstrap/src/runtime/os_linux.go:206

go version go1.12.3 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/csw/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/csw/work/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="/home/work/dlltest/go.mod"
GOROOT/bin/go version: go version go1.12.3 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.12.3
uname -sr: Linux 4.19.0-041900-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27.
gdb --version: GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git

Contributor guide