Is my gccgo broken ?

341 views
Skip to first unread message

Guillaume Lescure

unread,
Jan 13, 2013, 2:16:32 PM1/13/13
to golan...@googlegroups.com
Hi,

I tried to compile my own mini-kernel in Go (here : https://groups.google.com/forum/?fromgroups=#!searchin/golang-nuts/easy$20kernel/golang-nuts/P7uct7eTOIQ/iw1PNkbHmUkJ) but I had some strange errors. Because I don't use gccgo as often as go-compiler, I ran some tests and I found some strange behaviours. For example, when I compile a simple HelloWorld program with gccgo, no problems but if I had the "-static" flag, I had those errors when I run it :

$ gccgo -static helloworld.go
$./a.out
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0]
goroutine 2 [syscall]:
goroutine 1 [runnable]:
$

Is it normal or is there really a problem here ?

$gccgo -v             
Utilisation des specs internes.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configuré avec: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Modèle de thread: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1)
$

minux

unread,
Jan 13, 2013, 2:30:44 PM1/13/13
to Guillaume Lescure, golan...@googlegroups.com
I can reproduce it with latest version of gccgo (gcc version 4.8.0 20130113 (experimental) (GCC)),
so I think it is a bug.

for now, maybe you can get away with 'gccgo -static-libgo helloworld.go'. 

Ian Lance Taylor

unread,
Jan 13, 2013, 2:58:59 PM1/13/13
to Guillaume Lescure, golan...@googlegroups.com
On Sun, Jan 13, 2013 at 11:16 AM, Guillaume Lescure
<guil.l...@gmail.com> wrote:
>
> I tried to compile my own mini-kernel in Go (here :
> https://groups.google.com/forum/?fromgroups=#!searchin/golang-nuts/easy$20kernel/golang-nuts/P7uct7eTOIQ/iw1PNkbHmUkJ)
> but I had some strange errors. Because I don't use gccgo as often as
> go-compiler, I ran some tests and I found some strange behaviours. For
> example, when I compile a simple HelloWorld program with gccgo, no problems
> but if I had the "-static" flag, I had those errors when I run it :
>
>> $ gccgo -static helloworld.go
>>
>> $./a.out
>>
>> panic: runtime error: invalid memory address or nil pointer dereference
>>
>> [signal 0xb code=0x1 addr=0x0]
>> goroutine 2 [syscall]:
>> goroutine 1 [runnable]:
>> $

I haven't sorted out precisely why this happens, but to fix it add
-Wl,-u,pthread_create to your link line.

Ian

minux

unread,
Jan 13, 2013, 3:04:47 PM1/13/13
to Ian Lance Taylor, Guillaume Lescure, golan...@googlegroups.com
On Mon, Jan 14, 2013 at 3:58 AM, Ian Lance Taylor <ia...@google.com> wrote:
I haven't sorted out precisely why this happens, but to fix it add
-Wl,-u,pthread_create to your link line.
wow, indeed. this is quite weird.

btw, why gccgo wraps pthread_create in generated binaries?
could this be related to this strange bug?

Guillaume Lescure

unread,
Jan 13, 2013, 3:35:51 PM1/13/13
to golan...@googlegroups.com, Guillaume Lescure
I don't know if it's linked to that problem or not but if I do an empty program :

package main
 
func main() {
}

And if I use "-nostdlib" or/and "-nodefaultlibs", even with "-Wl,-u,pthread_create", I found back my old problem of "morestack" :

$LC_ALL=C gccgo -Wl,-u,pthread_create -nostdlib empty.go
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400144
/tmp/cc1el2AA.o: In function `main.main':
toto.go:(.text+0x18): undefined reference to `__morestack'
/tmp/cc1el2AA.o: In function `__go_init_main':
toto.go:(.text+0x3b): undefined reference to `__morestack'
collect2: error: ld returned 1 exit status
$

Maybe I'm wrong but "-nodefaultlibs" and "-nostdlib" shouldn't be a problem for an empty program ...

minux

unread,
Jan 13, 2013, 3:40:19 PM1/13/13
to Guillaume Lescure, golan...@googlegroups.com
an empty Go program still does a lot of things behind the scene as the Go runtime
still needs to started.
and the go runtime uses libc and libgcc, so -nodefaultlibs and -nostdlib won't work.

however, you can try:
gccgo -fno-split-stack -nodefaultlibs -nostdlib
to workaround the __morestack problem.

Guillaume Lescure

unread,
Jan 13, 2013, 5:37:17 PM1/13/13
to golan...@googlegroups.com, Guillaume Lescure
Thanks a lot minux,

The "-fno-split-stack" solve a big problem that I had ;)

minux

unread,
Jan 16, 2013, 1:48:17 PM1/16/13
to Guillaume Lescure, golan...@googlegroups.com
On Mon, Jan 14, 2013 at 3:16 AM, Guillaume Lescure <guil.l...@gmail.com> wrote:
I tried to compile my own mini-kernel in Go (here : https://groups.google.com/forum/?fromgroups=#!searchin/golang-nuts/easy$20kernel/golang-nuts/P7uct7eTOIQ/iw1PNkbHmUkJ) but I had some strange errors. Because I don't use gccgo as often as go-compiler, I ran some tests and I found some strange behaviours. For example, when I compile a simple HelloWorld program with gccgo, no problems but if I had the "-static" flag, I had those errors when I run it :

$ gccgo -static helloworld.go
$./a.out
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0]
goroutine 2 [syscall]:
goroutine 1 [runnable]:
$
This problem is just fixed in gcc trunk, and should appear in gcc 4.8.1.

minux

unread,
Jan 16, 2013, 1:50:27 PM1/16/13
to Guillaume Lescure, golan...@googlegroups.com
sorry, I mean, the fix should appear in gcc 4.8.1 (gcc 4.8.0 is in a stage where only serious regression fixes
and docs fixes are acceptable now)

Ian Lance Taylor

unread,
Jan 16, 2013, 3:25:33 PM1/16/13
to minux, Guillaume Lescure, golan...@googlegroups.com
Actually since -static did work at one time I treated it as a
regression fix, and it should be in 4.8.0.

Ian

Guillaume Lescure

unread,
Jan 16, 2013, 4:40:38 PM1/16/13
to golan...@googlegroups.com, minux, Guillaume Lescure
 Ok great, thanks for sharing the good news :)

Reply all
Reply to author
Forward
0 new messages