
Smaller Go 1.7 Binaries - chrisbroadfoot
https://blog.golang.org/go1.7-binary-size
======
crawshaw
Hi all. Something I left out of the post that I should have mentioned: if you
are wondering why a Hello World program is hundreds of kilobytes instead of
tens like a C program, it is because Go programs are statically linked.

You can dynamically link Go on linux to see similar numbers:

    
    
        $ go install -buildmode=shared std
        $ go build -linkshared hello.go 
        $ ./hello 
        Hello, World!
        $ ls -l hello
        -rwxr-x--- 1 crawshaw eng 15713 Aug 18 19:26 hello
    

(Dynamic linking in Go was funded by Canonical, which is pretty cool!)

------
jjnoakes
Does Go do any LTO? It's good that they throw away unexported unused routines
from my code, but it'd be better if they also didn't link in unused routines
from the standard library (assuming no reflection is being used).

~~~
mseepgood
I thought that's exactly what this article describes: "Similarly the linker
can discard other exported methods, those that are only accessible through
reflection, if the corresponding reflection features are not used anywhere in
the program. That change shrinks binaries by 5–20%."

~~~
jjnoakes
Could be. I read that as discarding user-defined methods, not library-provided
methods. Hopefully it is both.

~~~
crawshaw
The technique described in the blog post doesn't differentiate between user
code and library code. It's all code. Any method the linker or the compiler
can get rid of it does.

