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.gogo build -o hello_go_build_gccgo --compiler gccgo hello.gogccgo -o hello_gccgo_shared hello.gogccgo -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)?
I would find it odd if they would be the same size. One is statically linked, the other uses shared libraries, so why they should be expected to be the same size?
I would find it odd if they would be the same size. One is compiled by
gc, the other bygccgo– two completely different compilers. Why they should be expected to produce a binary of the same size?There’s no such thing as “statically link a package as a whole” with
gc. Unused functions (and perhaps not only functions) are not present in the binary. And, IIRC, that was the case since day 1 (counting from the public release). Not sure if the preceding applies togccgoas well, but I would expect it to do the same good job in this.