BuildToolchain
BuildToolchain is initialized as noToolchain{} by default, then it’s set dynamically to gccgo or gc.
Both implementations are wrappers around the binary toolchains installed on the machine. For gc, the delegations are as follows:
BuildToolchain.gc-base.Tool("compile")BuildToolchain.cc-base.Tool("cgo"). Actuallycgohas been executed before the compile andcfileshas been cleared, soBuildToolchain.ccshould never be called and it always returns an error.BuildToolchain.asm-base.Tool("asm")BuildToolchain.pack-base.Tool("pack")BuildToolchain.ld-base.Tool("link")
cmd/compile aka base.Tool(“compile”)
- Entry point:
internal/gc.Main
It’s a standalone binary which means all packages path assumes a relative path to go/src/cmd/compile.
gc.Main will get an archInit function as the parameter, this function populates the ssagen.ArchInfo which contains necessary architecture information.
- Initialize a new
obj.Linkas context. - Parse compiler flags -
internal/base.CmdFlags. - Initialize
types.Pkginformation. - Save DWARF info from compiler flags.
- Initialize
ssagenby OS environments and initialize the table, also initialize other architecture-specifictypesinformation. - Initialize
typecheck noder.LoadPackage- This is the main step for compiling and type checking, after this step,typecheck.Target(type ofir.Package) will be ready to use.- Initialize
ssagenconfiguration. - Build the
initfunction for the package. - Eliminate dead codes.
- Compute Addrtaken for names. <- What’s this?
- Wrapping the types, the imported types are assumed to be wrapped already.
devirtualize.FuncallDeclswithOp == ir.ODCLFUNC- Build init task.
- Generate ABI wrappers.
- Do escape analysis.
- Compile functions in parallel.
- Dump everything to the object file.
What’s Next
ssaarchitecture.- ABI architecture.
typessystem.irstructure.- escape analysis.
- Object file structure.