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

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

Open
ooepay opened this issue Apr 10, 2019 · 5 comments
Open

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

ooepay opened this issue Apr 10, 2019 · 5 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ooepay
Copy link

ooepay commented Apr 10, 2019

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
@ianlancetaylor ianlancetaylor changed the title Program received signal SIGSEGV, Segmentation fault. cmd/link: ARM uClinux crash with -buildmode=c-archive Apr 10, 2019
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 10, 2019
@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Apr 10, 2019
@ianlancetaylor ianlancetaylor changed the title cmd/link: ARM uClinux crash with -buildmode=c-archive runtime: ARM uClinux crash with -buildmode=c-archive Apr 10, 2019
@ianlancetaylor
Copy link
Contributor

The Go runtime on GNU/Linux systems currently expects that entries in the DT_INIT_ARRAY section are invoked with the C argc and argv values. The glibc library does this, but perhaps the uClinux library does not.

This could likely be fixed by changing the runtime package to read /proc/self/cmdline when the arguments are not passed in when running in c-archive mode.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Apr 10, 2019
@ianlancetaylor ianlancetaylor modified the milestones: Go1.13, Unplanned Apr 10, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 10, 2019
@ooepay
Copy link
Author

ooepay commented Apr 11, 2019

Thanks, the same problem in when running in c-shared mode.

@ooepay
Copy link
Author

ooepay commented Apr 11, 2019

how to fix this problem, have patch?
i do not how to change argv, it is **byte

func args(c int32, v **byte) {
argc = c
argv = v
sysargs(c, v)
}

@gopherbot
Copy link

Change https://golang.org/cl/334991 mentions this issue: runtime: add check before using arguments with -buildmode=c-archive and -buildmode=c-shared on non glibc systems such as musl/uclinux

@imkos
Copy link

imkos commented May 12, 2023

This issue has always existed in the alpine environment. Can the go teams plan to fix this issue? @ianlancetaylor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants