‘gc’和’gccgo’之间的主要区别是什么?

huangapple go评论80阅读模式
英文:

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

问题

两个流行的Go编译器"gc"和"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.

答案1

得分: 137

你可以在“设置和使用gccgo”中了解更多信息:

gccgo是Go语言的编译器。gccgo编译器是GCC的一个新的前端。
请注意,gccgo不是gc编译器。

正如在“GCC 4.7.1中的Gccgo”(2012年7月)中所解释的那样:

Go语言一直是由规范而不是实现定义的。Go团队编写了两个不同的编译器来实现该规范:gc和gccgo。

  • Gc是原始的编译器,go工具默认使用它。
  • Gccgo是一个不同的实现,具有不同的重点。

与gc相比,gccgo编译代码的速度较慢,但支持更强大的优化,因此由gccgo构建的CPU密集型程序通常运行更快。

此外:

  • gc编译器仅支持最流行的处理器:x86(32位和64位)和ARM。
  • 然而,gccgo支持GCC支持的所有处理器。
    并非所有这些处理器都经过gccgo的彻底测试,但其中许多处理器已经经过测试,包括x86(32位和64位)、SPARC、MIPS、PowerPC甚至Alpha。
    gccgo还在gc编译器不支持的操作系统上进行了测试,尤其是Solaris。

如果你从标准的Go发行版安装go命令,它已经通过-compiler选项支持gccgo:go build -compiler gccgo myprog

简而言之:gccgo:更多优化,更多处理器

然而,正如OneOfOne来源)在评论中所指出的,gccgo支持的Go版本与最新的Go发行版之间经常存在不同步:

gccgo仅支持到Go v1.2版本,因此如果你需要1.3 / 1.4(tip)中的任何新功能,则无法使用gccgo。

GCC 4.9发布版将包含Go 1.2(而不是1.3)版本的gccgo
GCC和Go项目的发布计划不一致,这意味着1.3版本将在开发分支中可用,但下一个GCC发布版4.10可能会包含Go 1.4版本的gccgo。

twotwotwo评论中提到了Brad Fitzpatrick的演讲幻灯片

gccgo生成非常好的代码
...但缺乏逃逸分析:对于许多小的分配和垃圾回收来说性能较差
...GC不是精确的。对于32位来说不好。

twotwotwo补充道:

另一张幻灯片提到非gccgo的ARM代码生成有问题。
如果对你的项目来说这是一个有趣的选项,可能要在目标架构上比较你的用例的二进制文件。

正如peterSO评论中所提到的,Go 1.5(2015年第三季度/第四季度)意味着:

编译器和运行时现在完全由Go编写(带有一点汇编语言)。
C不再参与实现,因此构建分发所需的C编译器已经消失

“Go in Go”幻灯片中提到:

C已经消失。
附注:gccgo仍然强大。

Berkant评论中问gccgo是否是从gc引导的。

Jörg W Mittag回答道:

不,gccgo出现在gc之后。

gc最初是用C编写的。它基于Ken Thompson在Plan9操作系统中的C编译器,该操作系统是Unix的继任者,由同一批人设计。gc经过迭代重构,越来越多地使用Go编写。

gccgo是由与Go项目无关的GCC黑客Ian Lance Taylor发起的。

请注意,第一个完全自托管的Go编译器实际上是一个专有的商业闭源实现,用于Windows,其名称似乎已经从我的脑海中消失,就像它从互联网上消失一样。他们声称拥有一个用Go编写的自托管编译器,针对的是在gccgo尚未存在且在Windows上设置gc非常痛苦的时候。 (你基本上必须设置一个完整的Cygwin环境,修补源代码并从源代码编译。)然而,该公司似乎在推出该产品之前就已经倒闭了。

Hector Chu在2009年11月发布了Go的Windows移植版。
go-lang.cat-v.org/os-ports页面还提到了Joe/Joseph Poirier的初步工作。在这个页面中:

是否有可能有了解情况的人请求参与制作Windows移植版的人之一(Alex Brainman - Hector Chu - Joseph Poirier)详细说明他们的构建环境?

此外,在《使用Go编写Web应用程序》中还提到了**!光京(Wei Guangjing)**。

英文:

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

huangapple
  • 本文由 发表于 2014年9月12日 23:11:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/25811445.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定