Why does Go use its own code generator?

The current official Go compiler (http://code.google.com/p/go/) currently uses a hand-crafted, possibly secret code generator that includes inputting custom sections to the ELF binary.

In this approach, there were a lot of errors related to utilities that directly read and / or write ELF information, for example ldd , objdump or strip .

I believe that this could be prevented by using a well-designed cross-platform code generator such as LLVM, and then just use the bundling tools provided with the OS, for example ld on Unix / Linux (or ld.exe on w / MinGW windows) or link.exe on Windows with Visual Studio.

So why does Go use its own code generator? Is it really just reinventing the wheel? Or are there more important reasons for this?

+6
source share
2 answers

For information on how to use gccgo, a more traditional compiler using the GCC end, see Configuring and using gccgo .

Go Language Specification is an agnostic compiler. You can choose from the available compilers, write one yourself or contribute to the LLVM Go frontend project.

For a historical perspective on Go compiler technology, read the answer to this question: What compiler technology is used to build compilers?

+7
source

The control compiler (5g, 6g and 8g, hereinafter referred to as gc) was written by Ken Thompson based on the C compiler, which he wrote for the Plan 9 operating system. There are several reasons why he did this:

  • He already knew how his C compiler worked, so it was easier for him to adapt his existing work, rather than learn a completely new structure.
  • One of Go's goals is to compile quickly. The gc compiler is probably faster than the LLVM compiler, maybe because it just doesn't do that much work. Again, this also does not optimize.

As Peter mentioned, there is also gccgo that uses gcc as a backend. I suspect that there will eventually be other options for Go compilers, especially considering that Go libraries include a full Go parser and a (partially completed) type of validation.

+4
source

Source: https://habr.com/ru/post/891761/


All Articles