Recently I read Go lang . I began to understand its structure.
How to build
You can build the go compiler and tools as documented in the official documentation .
It is quite easy. But it was confusing for me that I must run ./all.bash instead of usual make (1). I wonder why they don't simply use make . Anyway the bash script internally calls make as usual.
After building, I got the following executables in bin directory.
- 6a: assembler
- 6c: C compiler
- 6g: Go compiler
- 6l: linker
- 6nm: same as nm(1)?
- cgo
- ebnflint
- godefs
- godoc
- gofmt
- goinstall
- gomake
- gopack
- gopprof
- gotest
- gotry
- govet
- goyacc
- hgpatch
- quietgcc: gcc wrapper which is little slienter than native gcc
The oddish *1 prefix "6" is because I built the tools on amd64 architecture. The prefix varies according to architecture.
There are only three architectures which is implemented in the source:
This convention came from Plan 9 . I found the definitions for other architectures in include/mach.h :
2c(1) in Plan 9 describes one more architecture:
- 1: Motorola 68000
Directory structure
bin
where executables will be generated into.
doc
documentation
include
C header files.
lib
where some libraries will be generated into.
misc
misc
pkg
where Go standard packages (libraries) will be compiled into.
src
source codes
test
test cases
Let's dive into src :
cmd
source codes for the Go tool chain
lib9
Plan 9 C library?
libbio
buffered IO library
libcgo
?
libmach
library which contains architecture dependent codes
pkg
source codes of Go standard packages
commands
Let's dive into cmd directory.
- 5a/
- 5c/
- 5g/
- 5l/
- 6a/
- 6c/
- 6g/
- 6l/
- 8a/
- 8c/
- 8g/
- 8l/
- cc/
- cgo/
- cov/
- ebnflint/
- gc/
- godefs/
- godoc/
- gofmt/
- goinstall/
- gomake/
- gopack/
- gotest/
- govet/
- goyacc/
- hgpatch/
- ld/
- nm/
- prof/
[568][acgl] directories contain architecture dependent part of the sources. Architecture independent parts of the Go compiler are in gc directory.
I will read the detail of gc in the next post.