Here are some things that the Go program includes that the C program does not include:
-
Container types, such as hash maps and arrays, and their associated functions
-
Memory allocator, with optimizations for multithreaded programs
-
Concurrent garbage collector
-
Types and functions for threading, such as mutexes, condition variables, channels, and threads
-
Debugging tools like stack trace dumping and the SIGQUIT handler
-
Reflection code
(If you are curious exactly what is included, you can look at the symbols in your binary with debugging tools. On macOS and Linux you can use nm
to dump the symbols in your program.)
The thing is—most Go programs use all of these features! It’s hard to imagine a Go program that doesn’t use the garbage collector. So the creators of Go have not created a special way to remove this code from programs—since nobody needs this feature. After all, do you really care how big "Hello, world!"
is? No, you don’t.
From the FAQ Why is my trivial program such a large binary?
The linker in the gc toolchain creates statically-linked binaries by default. All Go binaries therefore include the Go runtime, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces.
Also keep in mind that if you are compiling on Windows with MSVC, you may be using a DLL runtime, such as MSVCR120.DLL… which is about 1 MB.
6
solved Attempting to reduce executable size of Go program [duplicate]