golang/go

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

开放

#31,378 创建于 2019年4月10日

 (5 条评论) (1 个反应) (0 位负责人)Go (19,008 个派生)batch import
NeedsFixhelp wanted

仓库指标

星标
 (133,883 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南