FAQ
Hello everyone!

Today I encountered what seems to be a bug in gccgo.

What I'm trying to do is to link and use a C-library in my application
written in Go. I have narrowed the C-library down to having a method
printing "hi" on stdio.

The directory structure is:

$ tree cfuncer ccombo
cfuncer
├── inc
│ └── cfuncer.h
├── libcfunker.a
└── src
     └── cfuncer.c
ccombo
└── ccombo.go

The main Go-program looks like:

http://play.golang.org/p/h9cXKM6WzG

the C-library consists of the following code:

http://play.golang.org/p/BIVXB0wZjg

and is compiled in the following way:

$ cd cfunker
$ gcc -I inc -Wall -c cfuncer.c
$ ar cruv libcfuncer.a cfuncer.o

Compiling the main program as:

$ cd ../ccombo
$ go build main.go

works, but when using gccgo like:

$ go build -compiler=gccgo main.go

it fails with the error:

# command-line-arguments
/tmp/go-build937064904/command-line-arguments/_obj/ccombo.cgo2.o: In
function `_cgo_53b96737dc38_Cfunc_cfunction':
ccombo.cgo2.c:(.text+0x3): undefined reference to `cfunction'
collect2: error: ld returned 1 exit status

My compilers has the following versions:

$ go version
go version go1.2 linux/amd64

$ gccgo -v
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/opt/gccgo-stable/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.2/configure --prefix=/opt/gccgo-stable
--enable-languages=c,c++,go
Thread model: posix
gcc version 4.8.2 (GCC)

I have also tried to do the same compilation with gcc 4.9.0 but it produces
the same error.

$ gccgo -v
Using built-in specs.
COLLECT_GCC=/opt/gccgo/bin/gccgo
COLLECT_LTO_WRAPPER=/opt/gccgo/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/opt/gccgo --with-arch-32=i586
--enable-languages=c,c++,go
Thread model: posix
gcc version 4.9.0 20131127 (experimental) (GCC)

--
Fredrik Pettersson

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Mar 14, 2014 at 1:42 pm

    On Fri, Mar 14, 2014 at 3:53 AM, wrote:
    Today I encountered what seems to be a bug in gccgo.

    Is this http://golang.org/issue/7303 ?

    Ian

    What I'm trying to do is to link and use a C-library in my application
    written in Go. I have narrowed the C-library down to having a method
    printing "hi" on stdio.

    The directory structure is:

    $ tree cfuncer ccombo
    cfuncer
    ├── inc
    │ └── cfuncer.h
    ├── libcfunker.a
    └── src
    └── cfuncer.c
    ccombo
    └── ccombo.go

    The main Go-program looks like:

    http://play.golang.org/p/h9cXKM6WzG

    the C-library consists of the following code:

    http://play.golang.org/p/BIVXB0wZjg

    and is compiled in the following way:

    $ cd cfunker
    $ gcc -I inc -Wall -c cfuncer.c
    $ ar cruv libcfuncer.a cfuncer.o

    Compiling the main program as:

    $ cd ../ccombo
    $ go build main.go

    works, but when using gccgo like:

    $ go build -compiler=gccgo main.go

    it fails with the error:

    # command-line-arguments
    /tmp/go-build937064904/command-line-arguments/_obj/ccombo.cgo2.o: In
    function `_cgo_53b96737dc38_Cfunc_cfunction':
    ccombo.cgo2.c:(.text+0x3): undefined reference to `cfunction'
    collect2: error: ld returned 1 exit status

    My compilers has the following versions:

    $ go version
    go version go1.2 linux/amd64

    $ gccgo -v
    Using built-in specs.
    COLLECT_GCC=gccgo
    COLLECT_LTO_WRAPPER=/opt/gccgo-stable/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
    Target: x86_64-unknown-linux-gnu
    Configured with: ../gcc-4.8.2/configure --prefix=/opt/gccgo-stable
    --enable-languages=c,c++,go
    Thread model: posix
    gcc version 4.8.2 (GCC)

    I have also tried to do the same compilation with gcc 4.9.0 but it produces
    the same error.

    $ gccgo -v
    Using built-in specs.
    COLLECT_GCC=/opt/gccgo/bin/gccgo
    COLLECT_LTO_WRAPPER=/opt/gccgo/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
    Target: x86_64-unknown-linux-gnu
    Configured with: ../gcc/configure --prefix=/opt/gccgo --with-arch-32=i586
    --enable-languages=c,c++,go
    Thread model: posix
    gcc version 4.9.0 20131127 (experimental) (GCC)

    --
    Fredrik Pettersson

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Fredrik Pettersson 89 at Mar 17, 2014 at 10:22 am

    On Friday, March 14, 2014 2:42:43 PM UTC+1, Ian Lance Taylor wrote:
    On Fri, Mar 14, 2014 at 3:53 AM, <[email protected] <javascript:>>
    wrote:
    Today I encountered what seems to be a bug in gccgo.

    Is this http://golang.org/issue/7303 ?
    I recompiled my gcc today and gccgo now has version 4.9.0 20140307.

    Since the issue was solved March 12 it is not possible for me to try the
    fix with my compiler (since the gofrontend is not manually merged to gcc
    including that commit). I Also looked through the issue and it does not
    seem like it is the same problem as mine.

    If it helps my command-line arguments are:

    $ go build -x -compiler=gccgo ccombo.go
    WORK=/tmp/go-build842442322
    mkdir -p $WORK/command-line-arguments/_obj/
    cd /home/fredpe/src/goprogs/src/ccombo
    /home/fredpe/src/go/pkg/tool/linux_amd64/cgo -objdir
    $WORK/command-line-arguments/_obj/ -gccgo -- -I
    $WORK/command-line-arguments/_obj/ -I ../cfunker/inc/ ccombo.go
    gcc -Wall -g -I $WORK/command-line-arguments/_obj/ -I
    /home/fredpe/src/go/pkg/linux_amd64 -o
    $WORK/command-line-arguments/_obj/_cgo_defun.o -D GOOS_linux -D
    GOARCH_amd64 -m64 -c $WORK/command-line-arguments/_obj/_cgo_defun.c
    gcc -I . -g -O2 -fPIC -m64 -pthread -print-libgcc-file-name
    gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/command-line-arguments/_obj/
    -I ../cfunker/inc/ -o $WORK/command-line-arguments/_obj/_cgo_main.o -c
    $WORK/command-line-arguments/_obj/_cgo_main.c
    gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/command-line-arguments/_obj/
    -I ../cfunker/inc/ -o $WORK/command-line-arguments/_obj/_cgo_export.o -c
    $WORK/command-line-arguments/_obj/_cgo_export.c
    gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/command-line-arguments/_obj/
    -I ../cfunker/inc/ -o $WORK/command-line-arguments/_obj/ccombo.cgo2.o -c
    $WORK/command-line-arguments/_obj/ccombo.cgo2.c
    gcc -I . -g -O2 -fPIC -m64 -pthread -o
    $WORK/command-line-arguments/_obj/_cgo_.o
    $WORK/command-line-arguments/_obj/_cgo_main.o
    $WORK/command-line-arguments/_obj/_cgo_export.o
    $WORK/command-line-arguments/_obj/ccombo.cgo2.o -L ../cfunker/ -lcfunker
    gccgo -I $WORK -c -g -m64
    -fgo-relative-import-path=_/home/fredpe/src/goprogs/src/ccombo -o
    $WORK/command-line-arguments/_obj/main.o
    $WORK/command-line-arguments/_obj/_cgo_gotypes.go
    $WORK/command-line-arguments/_obj/ccombo.cgo1.go
    ar cru $WORK/libcommand-line-arguments.a
    $WORK/command-line-arguments/_obj/main.o
    $WORK/command-line-arguments/_obj/_cgo_defun.o
    $WORK/command-line-arguments/_obj/_cgo_export.o
    $WORK/command-line-arguments/_obj/ccombo.cgo2.o
    cd .
    gccgo -o ccombo $WORK/command-line-arguments/_obj/main.o
    $WORK/command-line-arguments/_obj/_cgo_defun.o
    $WORK/command-line-arguments/_obj/_cgo_export.o
    $WORK/command-line-arguments/_obj/ccombo.cgo2.o -Wl,-( -m64 -lpthread
    -Wl,-E -Wl,-)
    # command-line-arguments
    /tmp/go-build842442322/command-line-arguments/_obj/ccombo.cgo2.o: In
    function `_cgo_ec8ce97ff4d4_Cfunc_cfunction':
    ccombo.cgo2.c:(.text+0x3): undefined reference to `cfunction'
    collect2: error: ld returned 1 exit status

    --
    Fredrik Pettersson

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Mar 17, 2014 at 7:20 pm

    On Mon, Mar 17, 2014 at 3:22 AM, wrote:
    Since the issue was solved March 12 it is not possible for me to try the fix
    with my compiler (since the gofrontend is not manually merged to gcc
    including that commit).
    That is a change to the go tool, which is not included with gccgo
    anyhow.

    I Also looked through the issue and it does not seem
    like it is the same problem as mine.
    That is of course possible.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Ian Lance Taylor at Mar 17, 2014 at 7:20 pm

    On Mon, Mar 17, 2014 at 12:20 PM, Ian Lance Taylor wrote:
    On Mon, Mar 17, 2014 at 3:22 AM, wrote:

    Since the issue was solved March 12 it is not possible for me to try the fix
    with my compiler (since the gofrontend is not manually merged to gcc
    including that commit).
    That is a change to the go tool, which is not included with gccgo
    anyhow.

    I Also looked through the issue and it does not seem
    like it is the same problem as mine.
    That is of course possible.
    Could you open an issue for this at http://golang.org/issue/new with a
    complete standalone test case? Thanks.

    Ian

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Fredrik Pettersson 89 at Mar 18, 2014 at 10:03 am

    On Monday, March 17, 2014 8:20:49 PM UTC+1, Ian Lance Taylor wrote:
    Could you open an issue for this at http://golang.org/issue/new with a
    complete standalone test case? Thanks.
    The issue is posted here: https://code.google.com/p/go/issues/detail?id=7573

    Thanks for your time and help!

    --
    Fredrik Pettersson

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 14, '14 at 12:25p
activeMar 18, '14 at 10:03a
posts6
users2
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase