Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the primary differences between 'gc' and 'gccgo'?

Tags:

go

gccgo

What are the primary differences between the two popular Go compilers, 'gc' and 'gccgo'? Build performance? Run-time performance? Command line options? Licensing?

I'm not looking for opinions on which is best, just a basic overview of their differences, so I can decide which is best for my needs.

like image 244
Flimzy Avatar asked Sep 12 '14 15:09

Flimzy


People also ask

What is Gccgo Go?

GCC supports several different frontends for different languages; gccgo is a Go frontend connected to the GCC backend. The Go frontend is separate from the GCC project and is designed to be able to connect to other compiler backends, but currently only supports GCC.

Can you compile Go with GCC?

The gccgo compiler supports all GCC options that are language independent, notably the -O and -g options. The -fgo-pkgpath=PKGPATH option may be used to set a unique prefix for the package being compiled. This option is automatically used by the go command, but you may want to use it if you invoke gccgo directly.

What compiler does Golang use?

There are three Go compiler implementations supported by the Go team. These are gc , the default compiler, gccgo , which uses the GCC back end, and a somewhat less mature gollvm , which uses the LLVM infrastructure.


1 Answers

You can see more in "Setting up and using gccgo":

gccgo, a compiler for the Go language. The gccgo compiler is a new frontend for GCC.
Note that gccgo is not the gc compiler

As explained in "Gccgo in GCC 4.7.1" (July 2012)

The Go language has always been defined by a spec, not an implementation. The Go team has written two different compilers that implement that spec: gc and gccgo.

  • Gc is the original compiler, and the go tool uses it by default.
  • Gccgo is a different implementation with a different focus

Compared to gc, gccgo is slower to compile code but supports more powerful optimizations, so a CPU-bound program built by gccgo will usually run faster.

Also:

  • The gc compiler supports only the most popular processors: x86 (32-bit and 64-bit) and ARM.
  • Gccgo, however, supports all the processors that GCC supports.
    Not all those processors have been thoroughly tested for gccgo, but many have, including x86 (32-bit and 64-bit), SPARC, MIPS, PowerPC and even Alpha.
    Gccgo has also been tested on operating systems that the gc compiler does not support, notably Solaris.

if you install the go command from a standard Go release, it already supports gccgo via the -compiler option: go build -compiler gccgo myprog.


In short: gccgo: more optimization, more processors.


However, as commented by OneOfOne (source), there is often a desynchronization between go supported by gccgo, and the latest go release:

gccgo only supports up to version go v1.2, so if you need anything new in 1.3 / 1.4 (tip) gccgo cant be used. –

GCC release 4.9 will contain the Go 1.2 (not 1.3) version of gccgo.
The release schedules for the GCC and Go projects do not coincide, which means that 1.3 will be available in the development branch but that the next GCC release, 4.10, will likely have the Go 1.4 version of gccgo.


twotwotwo mentions in the comments the slide of Brad Fitzpatrick's presentation

gccgo generates very good code
... but lacks escape analysis: kills performance with many small allocs + garbage
... GC isn't precise. Bad for 32-bit.

twotwotwo adds:

Another slide mentions that non-gccgo ARM code generation is wonky.
Assuming it's an interesting option for your project, probably compare binaries for your use case on your target architecture.


As peterSO comments, Go 1.5 now (Q3/Q4 2015) means:

The compiler and runtime are now written entirely in Go (with a little assembler).
C is no longer involved in the implementation, and so the C compiler that was once necessary for building the distribution is gone.

The "Go in Go" slide do mention:

C is gone.
Side note: gccgo is still going strong.


Berkant asks in the comments if gccgo is what gc was bootstrapped from.

Jörg W Mittag answers:

No, gccgo appeared after gc.

gc was originally written in C. It is based on Ken Thompson's C compiler from the Plan9 operating system, the successor to Unix, designed by the same people. gc was iteratively refactored to have more and more of itself written in Go.

gccgo was started by Ian Lance Taylor, a GCC hacker not affiliated with the Go project.

Note that the first fully self-hosted Go compiler was actually a proprietary commercial closed-source implementation for Windows whose name seems to have vanished from my brain the same way it did from the Internet. They claimed to have a self-hosted compiler written in Go, targeting Windows at a time where gccgo did not yet exist and gc was extremely painful to set up on Windows. (You basically had to set up a full Cygwin environment, patch the source code and compile from source.) The company seems to have folded, however, before they ever managed to market the product.

Hector Chu did release a Windows port of Go in Nov. 2009.
And the go-lang.cat-v.org/os-ports page mentions Joe/Joseph Poirier initial work as well. In this page:

Any chance that someone in the know could request that one of the guys (Alex Brainman - Hector Chu - Joseph Poirier) involved in producing the Windows port could make a wiki entry detailing their build environment?

Add to that (in Writing Web Apps in Go) !光京 (Wei Guangjing).

like image 101
VonC Avatar answered Oct 03 '22 03:10

VonC