113

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

137

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).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 4
    https://golang.org/doc/go1.3#gccgo And more importantly 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. – OneOfOne Sep 12 '14 at 15:40
  • 1
    @OneOfOne good point, I have included your comment in the answer for more visibility. – VonC Sep 12 '14 at 17:11
  • bradfitz's [slide on it](http://talks.golang.org/2014/gocon-tokyo.slide#54) mentions that it lacks escape analysis, where the compiler figures out some things can be allocated on the stack, and that its GC isn't precise. 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. – twotwotwo Sep 12 '14 at 18:25
  • 1
    @twotwotwo good find. I have included it in the answer for more visibility. – VonC Sep 12 '14 at 18:56
  • 3
    I read that gccgo implements goroutines by giving each goroutine a dedicated thread (as opposed to multiplexing many goroutines onto one thread). If this is still true then that can be a major difference to some people. – DragonFax Feb 23 '15 at 21:16
  • The root cause of all pros and cons is of course that gccgo is a GCC front-end: it parses GO into some GCC internal representation (at least GIMPLE I imagine), while `gc` is a completely dedicated compiler end to end (TODO check: was it written from scratch?) – Ciro Santilli OurBigBook.com Jun 28 '15 at 11:45
  • @CiroSantilli六四事件法轮功纳米比亚胡海峰 at least, gc in Go 1.5 will be gone: https://talks.golang.org/2015/gogo.slide#2 – VonC Jun 28 '15 at 11:51
  • 1
    @VonC: "gc in Go 1.5 will be gone" That's not true. [Go 1.5 Release Notes](https://golang.org/doc/go1.5). The slide (https://talks.golang.org/2015/gogo.slide#2) correctly says "C is gone", not "gc is gone". – peterSO Oct 25 '15 at 12:20
  • @peterSO True, I have included your command in the answer for more visibility. – VonC Oct 25 '15 at 12:27
  • 1
    How has this changes over time? Now in 2019 – Leo Gallucci Feb 14 '19 at 10:08
  • 2
    @LeoGallucci The general idea in this answer stands with Go 1.11 ("gccgo: more optimization, more processors."). You can see a more recent illustration in https://stackoverflow.com/a/46970176/6309. – VonC Feb 14 '19 at 10:23
  • Can I say that gccgo is what gc was bootstrapped from, or? I know there was a compiler written in C to compile a Go compiler but was that gccgo? If all gc compiler executables were lost in a second, would they have to recompile it using gccgo? Could you enlighten me? – Berkant İpek Jul 26 '19 at 06:37
  • @Berkant Not sure: gc and gccgo have manifestly their own independent evolution: https://github.com/quasilyte/gccgo_vs_gc, https://meltware.com/2019/01/16/gccgo-benchmarks-2019.html – VonC Jul 26 '19 at 07:18
  • 1
    Also, `gc` is under BSD-style license while `gccgo` is under GPL. – amrezzd Aug 08 '19 at 15:35
  • anyone noticed that gccgo is not supported on macos? https://github.com/gcc-mirror/gcc/blob/3e7b85061947bdc7c7465743ba90734566860821/configure#L3521-L3527 Any solutions? – ackratos Sep 03 '19 at 05:58
  • @ackratos That was noticed before indeed: https://stackoverflow.com/q/41765665/6309 – VonC Sep 03 '19 at 06:08
  • 1
    @Berkant: 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](https://wikipedia.org/wiki/Plan_9_from_Bell_Labs), 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 – Jörg W Mittag Jun 01 '20 at 11:39
  • … 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. – Jörg W Mittag Jun 01 '20 at 11:41
  • @JörgWMittag Thank you. I have included your comment in the answer for more visibility. I did not find that commercial port you mention, only the original Windows port (in 2009) done by Alex Brainman - Hector Chu - Joseph Poirier and !光京 (Wei Guangjing). – VonC Jun 01 '20 at 13:03
  • @VonC: I a sure it was something with "e", and may have been a play on "ego". (Which, of course, someone else also had the idea, and it now seems to be a web framework.) – Jörg W Mittag Jun 01 '20 at 13:05