Is Google's Golang an interpreter or compiler?

Raheel picture Raheel · Sep 3, 2012 · Viewed 21.3k times · Source

I have been researching Golang and I see that it has a compiler. But is it compiling Go into assembly level code or just converting it into BYTECODES and then calling that compilation? I mean, even in PHP we are able to convert it into BYTECODES and have faster performance. Is Golang a REPLACEMENT for system level programming and compiling ?

Answer

Denys Séguret picture Denys Séguret · Sep 3, 2012

This is really a compiler (in fact it embbeds 2 compilers) and it makes totally self sufficient executables. You don't need any supplementary library or any kind of runtime to execute it on your server. You just have to have it compiled for your target computer architecture.

From the documentation :

There are two official Go compiler tool chains. This document focuses on the gc Go compiler and tools (6g, 8g etc.). For information on how to work on gccgo, a more traditional compiler using the GCC back end, see Setting up and using gccgo.

The Go compilers support three instruction sets. There are important differences in the quality of the compilers for the different architectures.

amd64 (a.k.a. x86-64); 6g,6l,6c,6a A mature implementation. The compiler has an effective optimizer (registerizer) and generates good code (although gccgo can do noticeably better sometimes).

386 (a.k.a. x86 or x86-32); 8g,8l,8c,8a Comparable to the amd64 port.

arm (a.k.a. ARM); 5g,5l,5c,5a Supports only Linux binaries. Less widely used than the other ports and therefore not as thoroughly tested.

Except for things like low-level operating system interface code, the run-time support is the same in all ports and includes a mark-and-sweep garbage collector, efficient array and string slicing, and support for efficient goroutines, such as stacks that grow and shrink on demand.

The compilers can target the FreeBSD, Linux, NetBSD, OpenBSD, OS X (Darwin), and Windows operating systems. The full set of supported combinations is listed in the discussion of environment variables below.

On a server you'll usually target the amd64 platform.

Note that Go is well known for the speed of compilation. When deploying my server programs, I don't build for the different platforms on the development computer : I deploy the sources and I compile directly on the production servers. Since Go1 I never had a code compiling on one platform and not compiling on the other ones.

On Windows I had no problem in making an exe on my development computer and simply sending this exe to people never having installed anything Go related.