FS#26884 - golang. CGO is broken.

Attached to Project: Community Packages
Opened by Viacheslav Chimishuk (vocie) - Monday, 14 November 2011, 13:00 GMT
Last edited by Vesa Kaihlavirta (vegai) - Monday, 21 November 2011, 18:36 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Vesa Kaihlavirta (vegai)
Architecture All
Severity Critical
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
cgo command is broken in latest community/go package.

Additional info:
go-1:r60.3-1-i686.pkg.tar.xz (this version is broken)
go-1:r60-1-i686.pkg.tar.xz (this is ok)

Steps to reproduce:
I've attached test project. Try to build it with go-1:r60.3-1 go version.

$ make
CGOPKGPATH= cgo -- cgotest.go
touch _obj/_cgo_run
8g -o _go_.8 _obj/cgotest.cgo1.go _obj/_cgo_gotypes.go
8c -FVw -I/usr/lib/go/pkg/linux_386 -I . -o "_cgo_defun.8" _obj/_cgo_defun.c
gcc -m32 -I . -g -fPIC -O2 -o _cgo_main.o -c _obj/_cgo_main.c
gcc -m32 -I . -g -fPIC -O2 -o cgotest.cgo2.o -c _obj/cgotest.cgo2.c
gcc -m32 -I . -g -fPIC -O2 -o _cgo_export.o -c _obj/_cgo_export.c
gcc -m32 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o cgotest.cgo2.o _cgo_export.o
cgo -dynimport _cgo1_.o >_obj/_cgo_import.c_ && mv -f _obj/_cgo_import.c_ _obj/_cgo_import.c
8c -FVw -I . -o "_cgo_import.8" _obj/_cgo_import.c
rm -f _obj/cgotest.a
gopack grc _obj/cgotest.a _go_.8 _cgo_defun.8 _cgo_import.8 cgotest.cgo2.o _cgo_export.o

It builds well, but when you try to run build code it fails with next error:

$ make test
gotest
rm -f _test/cgotest.a
8g -o _gotest_.8 _obj/cgotest.cgo1.go _obj/_cgo_gotypes.go cgotest_test.go
rm -f _test/cgotest.a
gopack grc _test/cgotest.a _gotest_.8 _cgo_defun.8 _cgo_import.8 cgotest.cgo2.o _cgo_export.o
throw: cgocall unavailable

runtime.throw+0x43 /build/src/release-build/src/pkg/runtime/runtime.c:111
runtime.throw(0x8127518, 0x8)
runtime.cgocall+0x33 /build/src/release-build/src/pkg/runtime/cgocall.c:98
runtime.cgocall(0x805bf7e, 0x875c9f80, 0x0)
cgotest._Cfunc_time+0x32 /home/viacheslav/projects/cgotest/_obj/_cgo_defun.c:42
cgotest._Cfunc_time(0x976284d8, 0x976284d8)
--- skipped ---

P. S.
I've selected "Packages: Extra" category for this ticket, but package in the Community repo. Which category should be selected for community packages?
This task depends upon

Closed by  Vesa Kaihlavirta (vegai)
Monday, 21 November 2011, 18:36 GMT
Reason for closing:  Fixed
Comment by Csaba Henk (csheemea) - Monday, 14 November 2011, 18:41 GMT
subscribe
Comment by Neal van Veen (Nvveen) - Friday, 18 November 2011, 03:17 GMT
This is easily fixable by rebuilding the package with the CGO-disable flag removed from the PKGBUILD.
Comment by Vesa Kaihlavirta (vegai) - Friday, 18 November 2011, 14:34 GMT
Ah, this is most unfortunate.

That CGO disabling flag was added to fix a bug where the net package is built against glibc, which is not really required on Linux.

I'll try to find out if we can have it both ways, but it doesn't look good...
Comment by Csaba Henk (csheemea) - Monday, 21 November 2011, 13:58 GMT
@vegai: Why do you think building against glibc is not required on Linux? Well, definitely not required in the sense that you can complete the build without that. However, doing so implies loss of functionality (instead of having a pure go implementation of all features) -- in the net pkg's Makefile [http://code.google.com/p/go/source/browse/src/pkg/net/Makefile#99]:

ifeq ($(CGO_ENABLED),1)
CGOFILES_linux=\
cgo_linux.go\
cgo_unix.go
else
GOFILES_linux+=cgo_stub.go
endif

Checking the cgo_stub.go file [http://code.google.com/p/go/source/browse/src/pkg/net/cgo_stub.go]:

...
func cgoLookupHost(name string) (addrs []string, err error, completed bool) {
return nil, nil, false
}
...

ie. you get just stubs for the DNS lookup related functions.

Therefore forcing out cgo seems to be counterproductive also with respect to the use case you had in mind when doing it.

Btw, can I ask why did you add inetutils to makedeps in the same commit?
Comment by Vesa Kaihlavirta (vegai) - Monday, 21 November 2011, 17:49 GMT
"Why do you think building against glibc is not required on Linux?"

It became obvious after chatting with the developers in go's irc channel, plus testing it out myself. Although seeing the code you mentioned makes me be a bit surprised that it could have worked.

inetutils was added because one of the tests of golang failed without one of its programs. Could've been /usr/bin/hostname



Comment by Vesa Kaihlavirta (vegai) - Monday, 21 November 2011, 18:36 GMT
==> Updating [community]...
-> go-1:r60.3-2-i686.pkg.tar.xz (i686)
-> go-1:r60.3-2-x86_64.pkg.tar.xz (x86_64)

reverted CGO_ENABLED=0 and ran the test program in this ticket. Seems to work again.

Loading...