here is a Hello world in go:
package main
import (
"fmt"
)
func main() {
fmt.Println("Go is great!")
}
Put it in hello.go
and compile it with:
go build -o hello_go_build hello.go
go build -o hello_go_build_gccgo --compiler gccgo hello.go
gccgo -o hello_gccgo_shared hello.go
gccgo -static -o hello_gccgo_static hello.go
First, I noticed hello_go_build_gccgo
and hello_gccgo_shared
are not of the same size. I looked for information on the Internet without success. Does anyone know why is that? Or even better, would anyone tell me how I can try to figure that out? I tried to keep temp files with the -work
flag, but I couldn't spot the relevant information.
Then, as you might notice, the two statically linked binaries does not have the same size either. Actually, the one compiled with the go build
(hello_go_build
) command works not only on my system but also on other systems with other Linux distribution while hello_go_build_gccgo
fails on my system as well as on others with the error:
panic: runtime error: invalid memory address or nil pointer dereference
This is a bug about to be solved: https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/y2RIy0XLJ24
Finally, even if nowadays, size does not matter anymore, I am curious: is there any option with anyone of the go compilers to do function level linking (instead of statically link a package as a whole, only link the functions needed and their dependencies)?