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

cmd/go: buildmode=c-shared broken /w libmusl #19016

Closed
nicolai86 opened this issue Feb 9, 2017 · 3 comments
Closed

cmd/go: buildmode=c-shared broken /w libmusl #19016

nicolai86 opened this issue Feb 9, 2017 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@nicolai86
Copy link

nicolai86 commented Feb 9, 2017

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

1.8rc3, 1.7.5

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build694367367=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I tried to use a go shared library from a C program on alpine-linux (libmusl).

To reproduce:

$ docker run --rm -it golang:1.8-alpine sh
# apk add -U build-base
# cat > sum.go
// sum.go
package main

import "C"

//export sum
func sum(x, y int) int {
    return x + y
}

func main() {}
^C
# cat > sum.c
#include <stdio.h>
#include "sum.h"

int main(void) {

    int z = sum(1, 2);
    printf("1+2=%d\n", z);

    return 0;
}
^C
# go build -buildmode=c-shared -o sum.so
# gcc sum.c ./sum.so -o sum && ./sum
Segmentation fault

the same happens with the golang:1.7.5-alpine image. I did not test with older versions.

Using gdb I get the following core dump:

# apk add -U gdb
# ulimit -c unlimited
# gcc sum.c ./sum.so -o sum && ./sum
# gdb ./sum core
(gdb) bt
#0  runtime.raise () at /usr/local/go/src/runtime/sys_linux_amd64.s:110
#1  0x00007fadef86cddb in runtime.dieFromSignal (sig=11) at /usr/local/go/src/runtime/signal_unix.go:323
#2  0x00007fadef86d2a1 in runtime.sigfwdgo (sig=11, info=0x7fadefd88130, ctx=0x7fadefd88000, ~r3=false) at /usr/local/go/src/runtime/signal_unix.go:501
#3  0x00007fadef86c70b in runtime.sigtrampgo (sig=11, info=0x7fadefd88130, ctx=0x7fadefd88000) at /usr/local/go/src/runtime/signal_unix.go:200
#4  0x00007fadef883133 in runtime.sigtramp () at /usr/local/go/src/runtime/sys_linux_amd64.s:262
#5  <signal handler called>
#6  0x00007fadef85a02c in runtime.sysargs (argc=-273804016, argv=0x0) at /usr/local/go/src/runtime/os_linux.go:199
#7  0x00007fadef86962c in runtime.args (c=-273804016, v=0x0) at /usr/local/go/src/runtime/runtime1.go:64
#8  0x00007fadef87f60b in runtime.rt0_go () at /usr/local/go/src/runtime/asm_amd64.s:156
#9  0x00000000efae1510 in ?? ()
#10 0x0000000000000000 in ?? ()

What did you expect to see?

I expect the binary to work and print 1+2=3

What did you see instead?

Segmentation fault

@bradfitz
Copy link
Contributor

bradfitz commented Feb 9, 2017

We don't really have CI coverage for either build-shared or musl/alpine by themselves, much less together.

/cc @crawshaw @jessfraz (for #17891)

@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 9, 2017
@bradfitz bradfitz added this to the Go1.9 milestone Feb 9, 2017
@bradfitz
Copy link
Contributor

Update to my Feb 9th comment: we do have an Alpine builder as of recently which we're trying to get green. So this is at least easily debuggable by people now.

@ALTree
Copy link
Member

ALTree commented Jun 2, 2017

Closing this as an exact dup of #13492 (which has more discussion and people in it).

@ALTree ALTree closed this as completed Jun 2, 2017
@golang golang locked and limited conversation to collaborators Jun 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants