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/cgo: package that fails to link during test with gccgo #3027

Closed
alberts opened this issue Feb 15, 2012 · 19 comments

Comments

@alberts
Copy link
Contributor

commented Feb 15, 2012

What steps will reproduce the problem?

go test
PASS
ok ib 0.005s

GC=gccgo go test
# cd $WORK/ib/_test
gccgo -o ./ib.test ./main.o -Wl,-( ./libib.a -lpthread -Wl,-)
/tmp/go-build033561263/ib/_test/libib.a(ib.o):qp_test.go:function
fake_ib.ib.PostSendImm.pN20_fake_ib.ib.queuePair: error: undefined reference to
'ibv_post_send'
collect2: error: ld returned 1 exit status
FAIL ib [build failed]

What is the expected output?

test should link and run

What do you see instead?

link fails

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g, gccgo

Which operating system are you using?

linux

Which revision are you using?  (hg identify)

tip

gccgo (GCC) 4.7.0 20120212 (experimental)
commit 97a9e84db7393685db4d56f134fc73ee94c0995e
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184138
138bc75d-0d04-0410-961f-82ee72b054a4

Please provide any additional information below.

CC=gcc
CFLAGS='-O2 -g -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4
-mtune=generic'
CXXFLAGS='-O2 -g -fexceptions -fstack-protector --param=ssp-buffer-size=4 -mtune=generic'

configure --prefix=$prefix --mandir=$prefix/share/man --infodir=$prefix/share/info
--disable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release
--disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=go,lto
--with-ld=/usr/bin/ld.gold --enable-plugin --enable-initfini-array --disable-dssi
--enable-libgcj-multifile --with-ppl --with-cloog --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux

Compiling on Fedora 16 x86_64 with most updates applied.

binutils-2.21.53.0.1-6.fc16.x86_64

libibverbs-devel-1.1.6-1.fc16.x86_64

http://pkgs.fedoraproject.org/gitweb/?p=libibverbs.git

http://git.kernel.org/?p=libs/infiniband/libibverbs.git
@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2012

Comment 1:

Maybe related to issue #1397.
@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2012

Comment 2:

Forgot to attach the source...

Attachments:

  1. qp.go (204 bytes)
  2. qp_test.go (66 bytes)
@rsc

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2012

Comment 3:

Labels changed: added priority-go1, removed priority-triage.

Owner changed to builder@golang.org.

Status changed to Accepted.

@remyoudompheng

This comment has been minimized.

Copy link
Contributor

commented Mar 1, 2012

Comment 4:

Your source does not mention anywhere you're linking with libibverbs. I think you are
just lucky that 6l dropped the unused symbol (why?). By the way, I notice the go tool
does not honor CGO_LDFLAGS for gccgo.
@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2012

Comment 5:

Sorry, it's been a while since I reported this bug. Are you saying I'm doing something
wrong? Are you also saying there are other bugs not mentioned here?
@remyoudompheng

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2012

Comment 6:

Your source file uses a function from libibverbs but nowhere in your source you specify
you want to link with it.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2012

Comment 7:

Labels changed: added gccgo.

@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Mar 2, 2012

Comment 8:

Hello. I'll retest tomorrow and submit a new test case. Maybe the problem is that "the
go tool does not honor CGO_LDFLAGS for gccgo", as you said.
@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Mar 4, 2012

Comment 9:

Okay, here are slightly tweaked input files. I added
//#cgo linux LDFLAGS: -libverbs
to qp.go.
$ go test -v -x -c ./...
WORK=/dev/shm/go-build351850605
mkdir -p $WORK/ib/_test/
$GOROOT/pkg/tool/linux_amd64/cgo -objdir $WORK/ib/_test/ -- -I $WORK/ib/_test/ qp.go
$GOROOT/pkg/tool/linux_amd64/6c -FVw -I $WORK/ib/_test/ -I $GOROOT/pkg/linux_amd64 -o
$WORK/ib/_test/_cgo_defun.6 -DGOOS_linux -DGOARCH_amd64 $WORK/ib/_test/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/_cgo_main.o -c
$WORK/ib/_test/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/_cgo_export.o
-c $WORK/ib/_test/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/qp.cgo2.o -c
$WORK/ib/_test/qp.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/ib/_test/_cgo_.o $WORK/ib/_test/_cgo_main.o
$WORK/ib/_test/_cgo_export.o $WORK/ib/_test/qp.cgo2.o -libverbs
$GOROOT/pkg/tool/linux_amd64/cgo -objdir $WORK/ib/_test/ -dynimport
$WORK/ib/_test/_cgo_.o -dynout $WORK/ib/_test/_cgo_import.c
$GOROOT/pkg/tool/linux_amd64/6c -FVw -I $WORK/ib/_test/ -I $GOROOT/pkg/linux_amd64 -o
$WORK/ib/_test/_cgo_import.6 -DGOOS_linux -DGOARCH_amd64 $WORK/ib/_test/_cgo_import.c
$GOROOT/pkg/tool/linux_amd64/6g -o $WORK/ib/_test/_go_.6 -p ib -D ib -I $WORK
./qp_test.go $WORK/ib/_test/_cgo_gotypes.go $WORK/ib/_test/qp.cgo1.go
$GOROOT/pkg/tool/linux_amd64/pack grc $WORK/ib/_test/ib.a $WORK/ib/_test/_go_.6
$WORK/ib/_test/_cgo_import.6 $WORK/ib/_test/_cgo_defun.6 $WORK/ib/_test/_cgo_export.o
$WORK/ib/_test/qp.cgo2.o
cd $WORK/ib/_test
$GOROOT/pkg/tool/linux_amd64/6g -o ./_go_.6 -p testmain -D  -I . -I $WORK ./_testmain.go
$GOROOT/pkg/tool/linux_amd64/pack grc ./main.a ./_go_.6
$GOROOT/pkg/tool/linux_amd64/6l -o ./ib.test -L . -L $WORK ./main.a
cp $WORK/ib/_test/ib.test ib.test
$ ldd ib.test
linux-vdso.so.1 =>  (0x00007fff743ff000)
libibverbs.so.1 => /usr/lib64/libibverbs.so.1 (0x00007ff54cf3c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff54cd1f000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff54c967000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff54c763000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff54d157000)
$ GC=gccgo go test -v -x -c ./...
WORK=/dev/shm/go-build196429072
cd /home/alberts/ib/src/ib
$GOROOT/pkg/tool/linux_amd64/cgo -objdir $WORK/ib/_test/ -gccgo -- -I $WORK/ib/_test/
qp.go
gcc -Wall -g -I $WORK/ib/_test/ -I $GOROOT/pkg/linux_amd64 -o
$WORK/ib/_test/_cgo_defun.6 -DGOOS_linux -DGOARCH_amd64 -c $WORK/ib/_test/_cgo_defun.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/_cgo_main.o -c
$WORK/ib/_test/_cgo_main.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/_cgo_export.o
-c $WORK/ib/_test/_cgo_export.c
gcc -I . -g -O2 -fPIC -m64 -pthread -I $WORK/ib/_test/ -o $WORK/ib/_test/qp.cgo2.o -c
$WORK/ib/_test/qp.cgo2.c
gcc -I . -g -O2 -fPIC -m64 -pthread -o $WORK/ib/_test/_cgo_.o $WORK/ib/_test/_cgo_main.o
$WORK/ib/_test/_cgo_export.o $WORK/ib/_test/qp.cgo2.o -libverbs
gccgo -I $WORK -c -g -fgo-prefix=fake_ib -o $WORK/ib/_test/ib.o ./qp_test.go
$WORK/ib/_test/_cgo_gotypes.go $WORK/ib/_test/qp.cgo1.go
ar cru $WORK/ib/_test/libib.a $WORK/ib/_test/ib.o $WORK/ib/_test/_cgo_defun.6
$WORK/ib/_test/_cgo_export.o $WORK/ib/_test/qp.cgo2.o
cd $WORK/ib/_test
gccgo -I . -I $WORK -c -g -o ./main.o ./_testmain.go
ar cru ./main.a ./main.o
gccgo -o ./ib.test ./main.o -Wl,-( ./libib.a -lpthread -libverbs -Wl,-)
# testmain
qp.go:15: error: undefined reference to 'ibv_post_send'
collect2: error: ld returned 1 exit status
ibverbs shows up in the link line, but it doesn't work.
I configured with --with-ld=/usr/bin/ld.gold.

Attachments:

  1. qp.go (236 bytes)
  2. qp_test.go (103 bytes)
@remyoudompheng

This comment has been minimized.

Copy link
Contributor

commented Mar 4, 2012

Comment 10:

Oh, it's an inline function. It needs cgo to generate a wrapper to be linkable, I guess.
@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Mar 4, 2012

Comment 11:

Makes sense. I guess it works with 6g because cgo wraps all functions there?
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 20, 2012

Comment 12:

Let's tackle this after Go 1.
The fix is going to be to always generate a wrapper function.  I recently exported
syscall.Entersyscall and syscall.Exitsyscall, so in fact we always want to generate a
wrapper function anyhow, so that we can call those around the call to C code.

Labels changed: added priority-later, removed priority-go1.

Owner changed to @ianlancetaylor.

@alberts

This comment has been minimized.

Copy link
Contributor Author

commented Mar 21, 2012

Comment 13:

I managed to work around this for now by putting the following #defines in one of the
files of my cgo package. Might work for someone else's headers too.
//#define static
//#define inline
//#include <foo.h>
import "C"
@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2012

Comment 14:

Labels changed: added go1.1maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2013

Comment 15:

[The time for maybe has passed.]

Labels changed: removed go1.1maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 16:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 17:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 18:

Labels changed: added repo-gccgo.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2014

Comment 19:

This works on tip now.

Status changed to Fixed.

@alberts alberts added fixed labels Mar 26, 2014

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.